File: test_expression.py

package info (click to toggle)
python-lesscpy 0.13.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,436 kB
  • sloc: python: 3,572; sh: 20; makefile: 8
file content (58 lines) | stat: -rw-r--r-- 1,847 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
    lesscpy expression tests.
"""
import unittest

from lesscpy.plib.expression import Expression


class TestExpression(unittest.TestCase):
    def test_basic(self):
        for test in [
            ['0', '+', '0', '0'],
            ['2', '+', '2', '4'],
            ['2.0', '+', '2', '4'],
            ['2', '+', '2.0', '4'],
            ['2.0', '+', '2.0', '4'],
            [('2.0',), '+', '2.0', '4'],
            [('2.0',), '+', ('2.0',), '4'],
            ['0px', '+', '0', '0'],
            ['2px', '+', '2', '4px'],
            ['2.0px', '+', '2', '4px'],
            [('2px', ' '), '+', '2.0', '4px'],
            ['2.0px', '+', '2.0', '4px'],
        ]:
            e = Expression(test[:3])
            self.assertEqual(test[3], e.parse(None), str(test))

    def test_neg(self):
        for test in [
            ['-0', '+', '0', '0'],
            ['-2', '+', '-2', '-4'],
            ['-2.0', '+', '-2', '-4'],
            ['-2', '+', '-2.0', '-4'],
            ['-2.0', '+', '-2.0', '-4'],
            ['-0', '-', '0', '0'],
            ['-2', '-', '-2', '0'],
            ['-2.0', '-', '2', '-4'],
            ['-2', '-', '-2.0', '0'],
            ['2.0', '-', '-2.0', '4'],
            ['-0px', '+', '0', '0'],
            ['-2px', '+', '-2', '-4px'],
            ['-2.0', '+', '-2px', '-4px'],
            ['-2em', '+', '-2.0', '-4em'],
            ['-2.0s', '+', '-2.0s', '-4s'],
        ]:
            e = Expression(test[:3])
            self.assertEqual(test[3], e.parse(None), str(test))

    def test_op(self):
        for test in [
            ['0', '=', '0', True],
            ['1', '>', '2', False],
            ['1', '<', '2', True],
            ['1', '>=', '2', False],
            ['1', '=<', '2', True],
        ]:
            e = Expression(test[:3])
            self.assertEqual(test[3], e.parse(None), test)