1 """Testcases for cssutils.css.selector.Selector.
2
3 what should happen here?
4 - star 7 hack::
5 x*
6 does not validate but works in IE>5 and FF...
7
8 """
9 __author__ = '$LastChangedBy: cthedot $'
10 __date__ = '$LastChangedDate: 2007-11-03 22:40:26 +0100 (Sa, 03 Nov 2007) $'
11 __version__ = '$LastChangedRevision: 628 $'
12
13 import xml.dom
14 import basetest
15 import cssutils
16
18
21
25
27 "Selector.selectorText"
28 tests = {
29 u'''*''': None,
30 u'''*/*x*/''': None,
31 u'''* /*x*/''': None,
32 u'''*:hover''': None,
33 u'''* :hover''': None,
34 u'''*:lang(fr)''': None,
35 u'''* :lang(fr)''': None,
36 u'''*::first-line''': None,
37 u'''* ::first-line''': None,
38 u'''*[lang=fr]''': None,
39 u'''[lang=fr]''': None,
40
41 u'''a''': None,
42 u'''h1''': None,
43 u'''.a a''': None,
44
45 u'''a1''': None,
46 u'''a1-1''': None,
47 u'''.a1-1''': None,
48 u'''.a1._1''': None,
49
50 u'''[x]''': None,
51 u'''*[x]''': None,
52 u'''a[x]''': None,
53 u'''a[ x]''': 'a[x]',
54 u'''a[x ]''': 'a[x]',
55 u'''a [x]''': 'a [x]',
56 u'''* [x]''': None,
57
58 u'''a[x="1"]''': None,
59 u'''a[x ="1"]''': 'a[x="1"]',
60 u'''a[x= "1"]''': 'a[x="1"]',
61 u'''a[x = "1"]''': 'a[x="1"]',
62 u'''a[ x = "1"]''': 'a[x="1"]',
63 u'''a[x = "1" ]''': 'a[x="1"]',
64 u'''a[ x = "1" ]''': 'a[x="1"]',
65 u'''a [ x = "1" ]''': 'a [x="1"]',
66
67 u'''a[x~=a1]''': None,
68 u'''a[x ~=a1]''': 'a[x~=a1]',
69 u'''a[x~= a1]''': 'a[x~=a1]',
70 u'''a[x ~= a1]''': 'a[x~=a1]',
71 u'''a[ x ~= a1]''': 'a[x~=a1]',
72 u'''a[x ~= a1 ]''': 'a[x~=a1]',
73 u'''a[ x ~= a1 ]''': 'a[x~=a1]',
74 u'''a [ x ~= a1 ]''': 'a [x~=a1]',
75 u'''a *[ x ~= a1 ]''': 'a *[x~=a1]',
76
77 u'''a[x|=en]''': None,
78 u'''a[x|= en]''': 'a[x|=en]',
79 u'''a[x |=en]''': 'a[x|=en]',
80 u'''a[x |= en]''': 'a[x|=en]',
81 u'''a[ x |= en]''': 'a[x|=en]',
82 u'''a[x |= en ]''': 'a[x|=en]',
83 u'''a[ x |= en]''': 'a[x|=en]',
84 u'''a [ x |= en]''': 'a [x|=en]',
85
86 u'''a[x^=en]''': None,
87 u'''a[x$=en]''': None,
88 u'''a[x*=en]''': None,
89
90 u'''a[/*1*/x/*2*/]''': None,
91 u'''a[/*1*/x/*2*/=/*3*/a/*4*/]''': None,
92 u'''a[/*1*/x/*2*/~=/*3*/a/*4*/]''': None,
93 u'''a[/*1*/x/*2*/|=/*3*/a/*4*/]''': None,
94
95 u'''a b''': None,
96 u'''a b''': 'a b',
97 u'''a #b''': 'a #b',
98 u'''a .b''': 'a .b',
99 u'''ab''': 'ab',
100 u'''a.b''': None,
101 u'''a.b.c''': None,
102
103 u'''#a''': None,
104 u'''#a1''': None,
105 u'''#1a''': None,
106 u'''#1''': None,
107 u'''a#b''': None,
108 u'''a #b''': None,
109
110 u'''a>b''': None,
111 u'''a> b''': 'a>b',
112 u'''a >b''': 'a>b',
113 u'''a > b''': 'a>b',
114
115 u'''a+b''': None,
116 u'''a+ b''': 'a+b',
117 u'''a +b''': 'a+b',
118 u'''a + b''': 'a+b',
119
120 u'''a~b''': None,
121 u'''a~ b''': 'a~b',
122 u'''a ~b''': 'a~b',
123 u'''a ~ b''': 'a~b',
124
125 u'''a+ b c''': 'a+b c',
126
127 u'''|e''': None,
128 u'''*|e''': None,
129 u'''n|e''': None,
130 u'''n|*''': None,
131 u'''*|b[x|a]''': None,
132
133 u'''x:lang(de) y''': None,
134 u'''x:nth-child(odd) y''': None,
135
136 u':not(y)': None,
137 u'x:not(y)': None,
138 u'.x:not(y)': None,
139 }
140
141 self.do_equal_r(tests, att='selectorText')
142
143 tests = {
144 u'': xml.dom.SyntaxErr,
145 u'1': xml.dom.SyntaxErr,
146
147 u'#': xml.dom.SyntaxErr,
148 u'|': xml.dom.SyntaxErr,
149
150 u':': xml.dom.SyntaxErr,
151 u'::': xml.dom.SyntaxErr,
152 u': a': xml.dom.SyntaxErr,
153 u':: a': xml.dom.SyntaxErr,
154 u':a()': xml.dom.SyntaxErr,
155 u'::a()': xml.dom.SyntaxErr,
156 u':::a': xml.dom.SyntaxErr,
157 u':1': xml.dom.SyntaxErr,
158
159 u'#.x': xml.dom.SyntaxErr,
160 u'.': xml.dom.SyntaxErr,
161 u'.1': xml.dom.SyntaxErr,
162 u'.a.1': xml.dom.SyntaxErr,
163
164 u'[a': xml.dom.SyntaxErr,
165 u'a]': xml.dom.SyntaxErr,
166 u'[a b]': xml.dom.SyntaxErr,
167 u'[=b]': xml.dom.SyntaxErr,
168 u'[a=]': xml.dom.SyntaxErr,
169 u'[a|=]': xml.dom.SyntaxErr,
170 u'[a~=]': xml.dom.SyntaxErr,
171 u'[a=1]': xml.dom.SyntaxErr,
172
173 u'a +': xml.dom.SyntaxErr,
174 u'a >': xml.dom.SyntaxErr,
175 u'a ++ b': xml.dom.SyntaxErr,
176 u'a + > b': xml.dom.SyntaxErr,
177
178 u'*:lang(': xml.dom.SyntaxErr,
179
180 u'not(x)': xml.dom.SyntaxErr,
181
182
183 u',': xml.dom.InvalidModificationErr,
184 u',a': xml.dom.InvalidModificationErr,
185 u'a,': xml.dom.InvalidModificationErr,
186 }
187
188 self.do_raise_r(tests, att='_setSelectorText')
189
191 "Selector.__repr__(), .__str__()"
192 sel=u'a+b'
193
194 s = cssutils.css.Selector(selectorText=sel)
195
196 self.assert_(sel in str(s))
197
198 s2 = eval(repr(s))
199 self.assert_(isinstance(s2, s.__class__))
200 self.assert_(sel == s2.selectorText)
201
203 "Selector.prefixes"
204 sel=u'a|x1 a|x2 |y *|z [b|x] [a|x="1"]'
205 s = cssutils.css.Selector(selectorText=sel)
206
207 self.assertEqual(set('ab'), s.prefixes)
208
209 if __name__ == '__main__':
210 import unittest
211 unittest.main()
212