1
2 """
3 testcases for cssutils.util
4 """
5 __author__ = '$LastChangedBy: cthedot $'
6 __date__ = '$LastChangedDate: 2007-06-13 20:38:01 +0200 (Mi, 13 Jun 2007) $'
7 __version__ = '$LastChangedRevision: 56 $'
8
9 import sys
10 import xml.dom
11 import basetest
12 from cssutils.util import Base
13
14
16
18 "Base._normalize()"
19 b = Base()
20
21 tests = {u'aöäüß': u'aöäüß',
22 u'AbC-DeÖÄÜß': u'abc-deöäüß',
23 ur'\x': u'x'}
24 for test, exp in tests.items():
25 self.assertEqual(b._normalize(test), exp)
26
27 self.assertEqual(Base._normalize(test), exp)
28
30 "Base._tokensupto2()"
31
32
33 b = Base()
34
35 tests = [
36 ('default', u'a[{1}]({2}) { } NOT', u'a[{1}]({2}) { }', False),
37 ('default', u'a[{1}]({2}) { } NOT', u'a[{1}]func({2}) { }', True),
38 ('blockstartonly', u'a[{1}]({2}) { NOT', u'a[{1}]({2}) {', False),
39 ('blockstartonly', u'a[{1}]({2}) { NOT', u'a[{1}]func({2}) {', True),
40 ('propertynameendonly', u'a[(2)1] { }2 : a;', u'a[(2)1] { }2 :', False),
41 ('propertynameendonly', u'a[(2)1] { }2 : a;', u'a[func(2)1] { }2 :', True),
42 ('propertyvalueendonly', u'a{;{;}[;](;)}[;{;}[;](;)](;{;}[;](;)) 1; NOT',
43 u'a{;{;}[;](;)}[;{;}[;](;)](;{;}[;](;)) 1;', False),
44 ('propertyvalueendonly', u'a{;{;}[;](;)}[;{;}[;](;)](;{;}[;](;)) 1; NOT',
45 u'a{;{;}[;]func(;)}[;{;}[;]func(;)]func(;{;}[;]func(;)) 1;', True),
46 ('funcendonly', u'a{[1]}([3])[{[1]}[2]([3])]) NOT',
47 u'a{[1]}([3])[{[1]}[2]([3])])', False),
48 ('funcendonly', u'a{[1]}([3])[{[1]}[2]([3])]) NOT',
49 u'a{[1]}func([3])[{[1]}[2]func([3])])', True),
50 ('selectorattendonly', u'[a[()]{()}([()]{()}())] NOT',
51 u'[a[()]{()}([()]{()}())]', False),
52 ('selectorattendonly', u'[a[()]{()}([()]{()}())] NOT',
53 u'[a[func()]{func()}func([func()]{func()}func())]', True)
54 ]
55
56 for typ, values, exp, paransasfunc in tests:
57
58 def maketokens(valuelist):
59
60 return [('TYPE', v, 0, 0) for v in valuelist]
61
62 tokens = maketokens(list(values))
63 if paransasfunc:
64 for i, t in enumerate(tokens):
65 if u'(' == t[1]:
66 tokens[i] = ('FUNCTION', u'func(', t[2], t[3])
67
68 if 'default' == typ:
69 restokens = b._tokensupto2(tokens)
70 elif 'blockstartonly' == typ:
71 restokens = b._tokensupto2(
72 tokens, blockstartonly=True)
73 elif 'propertynameendonly' == typ:
74 restokens = b._tokensupto2(
75 tokens, propertynameendonly=True)
76 elif 'propertyvalueendonly' == typ:
77 restokens = b._tokensupto2(
78 tokens, propertyvalueendonly=True)
79 elif 'funcendonly' == typ:
80 restokens = b._tokensupto2(
81 tokens, funcendonly=True)
82 elif 'selectorattendonly' == typ:
83 restokens = b._tokensupto2(
84 tokens, selectorattendonly=True)
85
86 res = u''.join([t[1] for t in restokens])
87 self.assertEqual(exp, res)
88
89
90 if __name__ == '__main__':
91 import unittest
92 unittest.main()
93