1 """testcases for cssutils.css.CSSStyleRuleTestCase"""
2 __author__ = '$LastChangedBy: cthedot $'
3 __date__ = '$LastChangedDate: 2007-08-20 22:09:16 +0200 (Mo, 20 Aug 2007) $'
4 __version__ = '$LastChangedRevision: 258 $'
5
6 import xml.dom
7 import test_cssrule
8 import cssutils
9
11
18
29
33
35 "CSSStyleRule (incomplete)"
36 tests = {
37 u'a {': u'a {}',
38 u'a { font-family: "arial sans':
39 u'a {\n font-family: "arial sans"\n }',
40 }
41 self.do_equal_p(tests)
42
43 - def test_cssText(self):
44 "CSSStyleRule.cssText"
45 tests = {
46 u'''a\n{color: #000}''': 'a {\n color: #000\n }',
47 u'''a\n{color: #000000}''': 'a {\n color: #000000\n }',
48 u'''a\n{color: #abc}''': 'a {\n color: #abc\n }',
49 u'''a\n{color: #abcdef}''': 'a {\n color: #abcdef\n }',
50 u'''a\n{color: #00a}''': 'a {\n color: #00a\n }',
51 u'''a\n{color: #1a1a1a}''': 'a {\n color: #1a1a1a\n }',
52 u'''#id\n{}''': '#id {}',
53 u'''* {}''': None,
54 u'a {}': None,
55 u'b { a: 1; }': u'b {\n a: 1\n }',
56
57 u'c1 {/*1*/a:1;}': u'c1 {\n /*1*/\n a: 1\n }',
58 u'c2 {a:1;/*2*/}': u'c2 {\n a: 1;\n /*2*/\n }',
59 u'd1 {/*0*/}': u'd1 {\n /*0*/\n }',
60 u'd2 {/*0*//*1*/}': u'd2 {\n /*0*/\n /*1*/\n }'
61 }
62 self.do_equal_p(tests)
63 self.do_equal_r(tests)
64
65 tests = {
66 u'''a;''': xml.dom.SyntaxErr,
67 u'''a {{}''': xml.dom.SyntaxErr,
68 u'''a }''': xml.dom.SyntaxErr,
69 }
70 self.do_raise_p(tests)
71 tests.update({
72 u'''a {}x''': xml.dom.SyntaxErr,
73 u'''/*x*/''': xml.dom.SyntaxErr,
74 u'''a {''': xml.dom.SyntaxErr,
75 })
76 self.do_raise_r(tests)
77
93
95 "CSSStyleRule.selectorText"
96 r = cssutils.css.CSSStyleRule()
97
98 r.selectorText = u'a'
99 self.assertEqual(1, r.selectorList.length)
100 self.assertEqual(u'a', r.selectorText)
101
102 r.selectorText = u' b, h1 '
103 self.assertEqual(2, r.selectorList.length)
104 self.assertEqual(u'b, h1', r.selectorText)
105
114
116 "CSSStyleRule.__repr__(), .__str__()"
117 sel=u'a>b+c'
118
119 s = cssutils.css.CSSStyleRule(selectorText=sel)
120
121 self.assert_(sel in str(s))
122
123 s2 = eval(repr(s))
124 self.assert_(isinstance(s2, s.__class__))
125 self.assert_(sel == s2.selectorText)
126
127
128 if __name__ == '__main__':
129 import unittest
130 unittest.main()
131