Backed out changeset 713114c0331a (bug 1938707) by developer request CLOSED TREE
[gecko.git] / dom / bindings / parser / tests / test_namespace.py
blob5812364dddc9611d96d82629d1f3f8c7ede7aa96
1 import WebIDL
4 def WebIDLTest(parser, harness):
5 parser.parse(
6 """
7 namespace MyNamespace {
8 attribute any foo;
9 any bar();
11 """
14 results = parser.finish()
15 harness.check(len(results), 1, "Should have a thing.")
16 harness.ok(results[0].isNamespace(), "Our thing should be a namespace")
17 harness.check(len(results[0].members), 2, "Should have two things in our namespace")
18 harness.ok(results[0].members[0].isAttr(), "First member is attribute")
19 harness.ok(results[0].members[0].isStatic(), "Attribute should be static")
20 harness.ok(results[0].members[1].isMethod(), "Second member is method")
21 harness.ok(results[0].members[1].isStatic(), "Operation should be static")
23 parser = parser.reset()
24 parser.parse(
25 """
26 namespace MyNamespace {
27 attribute any foo;
29 partial namespace MyNamespace {
30 any bar();
32 """
35 results = parser.finish()
36 harness.check(len(results), 2, "Should have things.")
37 harness.ok(results[0].isNamespace(), "Our thing should be a namespace")
38 harness.check(len(results[0].members), 2, "Should have two things in our namespace")
39 harness.ok(results[0].members[0].isAttr(), "First member is attribute")
40 harness.ok(results[0].members[0].isStatic(), "Attribute should be static")
41 harness.ok(results[0].members[1].isMethod(), "Second member is method")
42 harness.ok(results[0].members[1].isStatic(), "Operation should be static")
44 parser = parser.reset()
45 parser.parse(
46 """
47 partial namespace MyNamespace {
48 any bar();
50 namespace MyNamespace {
51 attribute any foo;
53 """
56 results = parser.finish()
57 harness.check(len(results), 2, "Should have things.")
58 harness.ok(results[1].isNamespace(), "Our thing should be a namespace")
59 harness.check(len(results[1].members), 2, "Should have two things in our namespace")
60 harness.ok(results[1].members[0].isAttr(), "First member is attribute")
61 harness.ok(results[1].members[0].isStatic(), "Attribute should be static")
62 harness.ok(results[1].members[1].isMethod(), "Second member is method")
63 harness.ok(results[1].members[1].isStatic(), "Operation should be static")
65 parser = parser.reset()
66 threw = False
67 try:
68 parser.parse(
69 """
70 namespace MyNamespace {
71 static attribute any foo;
73 """
76 results = parser.finish()
77 except WebIDL.WebIDLError:
78 threw = True
79 harness.ok(threw, "Should have thrown.")
81 parser = parser.reset()
82 threw = False
83 try:
84 parser.parse(
85 """
86 namespace MyNamespace {
87 static any bar();
89 """
92 results = parser.finish()
93 except WebIDL.WebIDLError:
94 threw = True
95 harness.ok(threw, "Should have thrown.")
97 parser = parser.reset()
98 threw = False
99 try:
100 parser.parse(
102 namespace MyNamespace {
103 any bar();
106 interface MyNamespace {
107 any baz();
112 results = parser.finish()
113 except WebIDL.WebIDLError:
114 threw = True
115 harness.ok(threw, "Should have thrown.")
117 parser = parser.reset()
118 threw = False
119 try:
120 parser.parse(
122 interface MyNamespace {
123 any baz();
126 namespace MyNamespace {
127 any bar();
132 results = parser.finish()
133 except WebIDL.WebIDLError:
134 threw = True
135 harness.ok(threw, "Should have thrown.")
137 parser = parser.reset()
138 threw = False
139 try:
140 parser.parse(
142 namespace MyNamespace {
143 any baz();
146 namespace MyNamespace {
147 any bar();
152 results = parser.finish()
153 except WebIDL.WebIDLError:
154 threw = True
155 harness.ok(threw, "Should have thrown.")
157 parser = parser.reset()
158 threw = False
159 try:
160 parser.parse(
162 partial namespace MyNamespace {
163 any baz();
166 interface MyNamespace {
167 any bar();
172 results = parser.finish()
173 except WebIDL.WebIDLError:
174 threw = True
175 harness.ok(threw, "Should have thrown.")
177 parser = parser.reset()
178 threw = False
179 try:
180 parser.parse(
182 namespace MyNamespace {
183 any bar();
186 partial interface MyNamespace {
187 any baz();
192 results = parser.finish()
193 except WebIDL.WebIDLError:
194 threw = True
195 harness.ok(threw, "Should have thrown.")
197 parser = parser.reset()
198 threw = False
199 try:
200 parser.parse(
202 partial interface MyNamespace {
203 any baz();
206 namespace MyNamespace {
207 any bar();
212 results = parser.finish()
213 except WebIDL.WebIDLError:
214 threw = True
215 harness.ok(threw, "Should have thrown.")
217 parser = parser.reset()
218 threw = False
219 try:
220 parser.parse(
222 interface MyNamespace {
223 any bar();
226 partial namespace MyNamespace {
227 any baz();
232 results = parser.finish()
233 except WebIDL.WebIDLError:
234 threw = True
235 harness.ok(threw, "Should have thrown.")