From e1a4c457d457f4a553d83737ad9dd5b3a597d035 Mon Sep 17 00:00:00 2001 From: "Eevee (Alex Munroe)" Date: Tue, 13 Aug 2013 14:08:42 -0700 Subject: Fix unquote() to work on lists. --- scss/functions/core.py | 14 ++++++++++++-- scss/tests/functions/test_core.py | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/scss/functions/core.py b/scss/functions/core.py index 5f36be3..b4a3a19 100644 --- a/scss/functions/core.py +++ b/scss/functions/core.py @@ -396,12 +396,22 @@ def change_color(color, saturation=None, lightness=None, red=None, green=None, b @register('escape', 1) @register('unquote') def unquote(*args): - return StringValue(' '.join([StringValue(s).value for s in args])) + arg = List.from_maybe_starargs(args).maybe() + + if isinstance(arg, StringValue): + return StringValue(arg.value, quotes=None) + else: + return StringValue(arg.render(), quotes=None) @register('quote') def quote(*args): - return QuotedStringValue(' '.join([StringValue(s).value for s in args])) + arg = List.from_maybe_starargs(args).maybe() + + if isinstance(arg, StringValue): + return StringValue(arg.value, quotes='"') + else: + return StringValue(arg.render(), quotes='"') # ------------------------------------------------------------------------------ diff --git a/scss/tests/functions/test_core.py b/scss/tests/functions/test_core.py index d02a479..c36250c 100644 --- a/scss/tests/functions/test_core.py +++ b/scss/tests/functions/test_core.py @@ -8,7 +8,7 @@ from __future__ import division from scss.expression import Calculator from scss.functions.core import CORE_LIBRARY from scss.rule import Namespace -from scss.types import ColorValue, NumberValue +from scss.types import ColorValue, NumberValue, String import pytest xfail = pytest.mark.xfail @@ -200,13 +200,23 @@ def test_ie_hex_str(calc): def test_unquote(calc): # Examples from the Ruby docs - assert calc('unquote("foo")') == calc('foo') - assert calc('unquote(foo)') == calc('foo') + ret = calc('unquote("foo")') + assert ret == String('foo') + assert ret.quotes is None + ret = calc('unquote(foo)') + assert ret == String('foo') + assert ret.quotes is None + + assert calc('unquote((one, two, three))') == String('one, two, three') def test_quote(calc): # Examples from the Ruby docs - assert calc('quote("foo")') == calc('"foo"') - assert calc('quote(foo)') == calc('"foo"') + ret = calc('quote("foo")') + assert ret == String('foo') + assert ret.quotes == '"' + ret = calc('quote(foo)') + assert ret == String('foo') + assert ret.quotes == '"' # ------------------------------------------------------------------------------ -- cgit v1.2.1