summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <eevee.git@veekun.com>2013-08-19 16:16:08 -0700
committerEevee (Alex Munroe) <eevee.git@veekun.com>2013-08-19 16:16:08 -0700
commit03628c2b0b7841506fb0e0d8e5b5c60f2069e143 (patch)
tree97247c541891415f82a66f344a70b1abe0635ff3
parent5ec6107750b4738faf29ee7561493d691e21e19a (diff)
downloadpyscss-03628c2b0b7841506fb0e0d8e5b5c60f2069e143.tar.gz
Split type-system tests into their own file, and rewrite without the parser.
-rw-r--r--scss/tests/test_expression.py93
-rw-r--r--scss/tests/test_types.py110
2 files changed, 113 insertions, 90 deletions
diff --git a/scss/tests/test_expression.py b/scss/tests/test_expression.py
index a10f21b..a16950e 100644
--- a/scss/tests/test_expression.py
+++ b/scss/tests/test_expression.py
@@ -1,3 +1,6 @@
+"""Tests for expressions. This test module is currently a bit ill-defined and
+contains a variety of expression-related tests.
+"""
from scss.expression import Calculator
from scss.functions.core import CORE_LIBRARY
from scss.rule import Namespace
@@ -65,96 +68,6 @@ def test_reference_operations():
assert_strict_string_eq(calc('"I ate #{$value} pies!"'), String('I ate pies!', quotes='"'))
-# Operators: arithmetic (+ - * / %), unary (+ -), comparison (== != < > <= >=), boolean
-# Types: numbers, colors, strings, booleans, lists
-# Test them all!
-
-def test_addition(calc):
- assert calc('123 + 456') == Number(579)
-
- assert calc('1px + 2px') == Number(3, "px")
-
- assert calc('123 + abc') == String('123abc')
- assert calc('abc + 123') == String('abc123')
-
- assert calc('abc + def') == String('abcdef')
- assert calc('abc + "def"') == String('abcdef')
- ret = calc('"abc" + def')
- assert ret == String('abcdef')
- assert ret.quotes == '"'
- ret = calc('"abc" + "def"')
- assert ret == String('abcdef')
- assert ret.quotes == '"'
-
- assert calc('#010305 + #050301') == Color.from_hex('#060606')
- assert calc('#ffffff + #ffffff') == Color.from_name('white')
-
-
-def test_subtraction(calc):
- assert calc('123 - 456') == Number(-333)
- assert calc('456 - 123') == Number(333)
- # TODO test that subtracting e.g. strings doesn't work
-
- assert calc('#0f0f0f - #050505') == Color.from_hex('#0a0a0a')
-
-
-def test_division(calc):
- assert calc('(5px / 5px)') == Number(1)
- assert calc('(1in / 6pt)') == Number(12)
-
-
-def test_comparison_numeric(calc):
- assert calc('123 < 456')
- assert calc('123 <= 456')
- assert calc('123 <= 123')
- assert calc('456 > 123')
- assert calc('456 >= 123')
- assert calc('456 >= 456')
- assert calc('123 == 123')
- assert calc('123 != 456')
-
- # Same tests, negated
- assert not calc('123 > 456')
- assert not calc('123 >= 456')
- assert not calc('456 < 123')
- assert not calc('456 <= 123')
- assert not calc('123 != 123')
- assert not calc('123 == 456')
-
-
-def test_comparison_stringerific(calc):
- assert calc('"abc" == "abc"')
- assert calc('"abc" != "xyz"')
-
- # Same tests, negated
- assert not calc('"abc" != "abc"')
- assert not calc('"abc" == "xyz"')
-
- # Interaction with other types
- assert calc('123 != "123"')
-
- # Sass strings don't support ordering
- for expression in (
- '"abc" < "xyz"',
- '"abc" <= "xyz"',
- '"abc" <= "abc"',
- '"xyz" > "abc"',
- '"xyz" >= "abc"',
- '"xyz" >= "xyz"',
- '123 < "456"'):
-
- with pytest.raises(TypeError):
- calc(expression)
-
-
-def test_comparison_null(calc):
- assert calc('null == null')
- assert calc('null != 0')
-
- with pytest.raises(TypeError):
- calc('null < null')
-
-
def test_parse(calc):
# Tests for some general parsing.
diff --git a/scss/tests/test_types.py b/scss/tests/test_types.py
new file mode 100644
index 0000000..b55c5f2
--- /dev/null
+++ b/scss/tests/test_types.py
@@ -0,0 +1,110 @@
+"""Tests for the type system."""
+
+from scss.types import Color, Null, Number, String
+
+import pytest
+
+
+# Operators: arithmetic (+ - * / %), unary (+ -), comparison (== != < > <= >=), boolean
+# Types: numbers, colors, strings, booleans, lists
+# Test them all!
+
+def test_addition():
+ assert Number(123) + Number(456) == Number(579)
+
+ assert Number(1, "px") + Number(2, "px") == Number(3, "px")
+
+ assert Number(123) + String('abc') == String('123abc')
+ assert String('abc') + Number(123) == String('abc123')
+
+ ret = String('abc', quotes=None) + String('def', quotes=None)
+ assert ret == String('abcdef')
+ assert ret.quotes is None
+
+ ret = String('abc', quotes='"') + String('def', quotes=None)
+ assert ret == String('abcdef')
+ assert ret.quotes is '"'
+
+ ret = String('abc', quotes=None) + String('def', quotes='"')
+ assert ret == String('abcdef')
+ assert ret.quotes is None
+
+ assert Color.from_hex('#010305') + Color.from_hex('#050301') == Color.from_hex('#060606')
+ assert Color.from_name('white') + Color.from_name('white') == Color.from_name('white')
+
+
+def test_subtraction():
+ assert Number(123) - Number(456) == Number(-333)
+ assert Number(456) - Number(123) == Number(333)
+ # TODO test that subtracting e.g. strings doesn't work
+
+ assert Color.from_hex('#0f0f0f') - Color.from_hex('#050505') == Color.from_hex('#0a0a0a')
+
+
+def test_division():
+ assert Number(5, "px") / Number(5, "px") == Number(1)
+ assert Number(1, "in") / Number(6, "pt") == Number(12)
+
+
+def test_comparison_numeric():
+ lo = Number(123)
+ hi = Number(456)
+ assert lo < hi
+ assert lo <= hi
+ assert lo <= lo
+ assert hi > lo
+ assert hi >= lo
+ assert hi >= hi
+ assert lo == lo
+ assert lo != hi
+
+ # Same tests, negated
+ assert not lo > hi
+ assert not lo >= hi
+ assert not hi < lo
+ assert not hi <= lo
+ assert not lo != lo
+ assert not lo == hi
+
+
+def test_comparison_stringerific():
+ abc = String('abc')
+ xyz = String('xyz')
+
+ assert abc == abc
+ assert abc != xyz
+ assert not abc == xyz
+ assert not abc != abc
+
+ # Interaction with other types
+ assert Number(123) != String('123')
+ assert String('123') != Number(123)
+
+ # Sass strings don't support ordering
+ with pytest.raises(TypeError):
+ abc < xyz
+
+ with pytest.raises(TypeError):
+ abc <= xyz
+
+ with pytest.raises(TypeError):
+ abc > xyz
+
+ with pytest.raises(TypeError):
+ abc >= xyz
+
+ with pytest.raises(TypeError):
+ Number(123) < String('123')
+
+
+def test_comparison_null():
+ null = Null()
+
+ assert null == null
+ assert null != Number(0)
+
+ with pytest.raises(TypeError):
+ null < null
+
+
+# TODO write more! i'm lazy.