File: test_identifier.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 (101 lines) | stat: -rw-r--r-- 3,856 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import unittest

from lesscpy.lessc.scope import Scope
from lesscpy.plib.identifier import Identifier


class TestIdentifier(unittest.TestCase):

    def test_basic(self):
        fl = {'ws': ' ', 'nl': '\n'}
        for i in [
            ([], ''),
            (['.scope', ' ', 'a'], '.scope a'),
            (['a', ' ', '.scope'], 'a .scope'),
            (['a', '.scope'], 'a.scope'),
            (['a', '>', 'p', '>', 'h2'], 'a > p > h2'),
            (['a', '~', 'p', '+', 'h2'], 'a ~ p + h2'),
            (['*', 'html'], '* html'),
        ]:
            t, r = i
            id = Identifier(t, 0)
            self.assertEqual(id.parse(None).fmt(fl), r, i)

    def test_scope(self):
        fl = {'ws': ' ', 'nl': '\n'}
        sc = Scope()
        sc.push()
        sc.current = Identifier(['.current'], 0).parse(sc)
        for i in [
            (['.scope', ' ', 'a'], '.current .scope a'),
            (['a', ' ', '.scope'], '.current a .scope'),
            (['a', '.scope'], '.current a.scope'),
            (['a', '>', 'p', '>', 'h2'], '.current a > p > h2'),
            (['a', '~', 'p', '+', 'h2'], '.current a ~ p + h2'),
            (['>', 'p', '+', 'h2'], '.current > p + h2'),
        ]:
            t, r = i
            id = Identifier(t, 0)
            self.assertEqual(id.parse(sc).fmt(fl), r, i)

    def test_combinators(self):
        fl = {'ws': ' ', 'nl': '\n'}
        sc = Scope()
        sc.push()
        sc.current = Identifier(['.current'], 0).parse(sc)
        for i in [
            (['&', '.scope', ' ', 'a'], '.current.scope a'),
            (['.scope', '&', ' ', 'a'], '.scope.current a'),
            (['.scope', ' ', 'a', '&'], '.scope a.current'),
            (['&', '>', '.scope', ' ', 'a'], '.current > .scope a'),
            (['.span', '&', '.scope', ' ', 'a', '&'],
             '.span.current.scope a.current'),
        ]:
            t, r = i
            id = Identifier(t, 0)
            self.assertEqual(id.parse(sc).fmt(fl), r, i)
        sc.push()
        sc.current = Identifier(['&', '.next'], 0).parse(sc)
        id = Identifier(['&', '.top'], 0)
        self.assertEqual(id.parse(sc).fmt(fl), '.current.next.top')

    def test_groups(self):
        fl = {'ws': ' ', 'nl': '\n'}
        sc = Scope()
        sc.push()
        sc.current = Identifier(['.a', ',', '.b'], 0).parse(sc)
        for i in [
            (['&', '.scope', ' ', 'a'], '.a.scope a,\n.b.scope a'),
            (['.scope', '&', ' ', 'a'], '.scope.a a,\n.scope.b a'),
            (['.scope', ' ', 'a', '&'], '.scope a.a,\n.scope a.b'),
            (['>', '&', '.scope', ' ', 'a'], ' > .a.scope a,\n > .b.scope a'),
        ]:
            t, r = i
            id = Identifier(t, 0)
            self.assertEqual(id.parse(sc).fmt(fl), r, i)
        sc.current = Identifier(['.next'], 0).parse(sc)
        sc.push()
        sc.current = Identifier(['.c', ',', '.d'], 0).parse(sc)
        id = Identifier(['.deep'], 0)
        self.assertEqual(id.parse(sc).fmt(fl), '.a .next .c .deep,\n'
                         '.b .next .c .deep,\n'
                         '.a .next .d .deep,\n'
                         '.b .next .d .deep')
        self.assertEqual(id.raw(), '.a% %.next% %.c% %.deep%'
                                   '.b% %.next% %.c% %.deep%'
                                   '.a% %.next% %.d% %.deep%'
                                   '.b% %.next% %.d% %.deep')

    def test_media(self):
        fl = {'ws': ' ', 'nl': '\n'}
        sc = Scope()
        sc.push()
        sc.current = Identifier(
            ['@media', ' ', 'screen', ',', 'projection'], 0).parse(sc)
        self.assertEqual(sc.current.fmt(fl), '@media screen,projection')
        for i in [
            (['html'], 'html'),
        ]:
            t, r = i
            id = Identifier(t, 0)
            self.assertEqual(id.parse(sc).fmt(fl), r, i)