dom/bindings/parser/tests/test_enum.py

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:3ee6f3c23fe8
1 import WebIDL
2
3 def WebIDLTest(parser, harness):
4 parser.parse("""
5 enum TestEnum {
6 "",
7 "foo",
8 "bar"
9 };
10
11 interface TestEnumInterface {
12 TestEnum doFoo(boolean arg);
13 readonly attribute TestEnum foo;
14 };
15 """)
16
17 results = parser.finish()
18
19 harness.ok(True, "TestEnumInterfaces interface parsed without error.")
20 harness.check(len(results), 2, "Should be one production")
21 harness.ok(isinstance(results[0], WebIDL.IDLEnum),
22 "Should be an IDLEnum")
23 harness.ok(isinstance(results[1], WebIDL.IDLInterface),
24 "Should be an IDLInterface")
25
26 enum = results[0]
27 harness.check(enum.identifier.QName(), "::TestEnum", "Enum has the right QName")
28 harness.check(enum.identifier.name, "TestEnum", "Enum has the right name")
29 harness.check(enum.values(), ["", "foo", "bar"], "Enum has the right values")
30
31 iface = results[1]
32
33 harness.check(iface.identifier.QName(), "::TestEnumInterface", "Interface has the right QName")
34 harness.check(iface.identifier.name, "TestEnumInterface", "Interface has the right name")
35 harness.check(iface.parent, None, "Interface has no parent")
36
37 members = iface.members
38 harness.check(len(members), 2, "Should be one production")
39 harness.ok(isinstance(members[0], WebIDL.IDLMethod),
40 "Should be an IDLMethod")
41 method = members[0]
42 harness.check(method.identifier.QName(), "::TestEnumInterface::doFoo",
43 "Method has correct QName")
44 harness.check(method.identifier.name, "doFoo", "Method has correct name")
45
46 signatures = method.signatures()
47 harness.check(len(signatures), 1, "Expect one signature")
48
49 (returnType, arguments) = signatures[0]
50 harness.check(str(returnType), "TestEnum (Wrapper)", "Method type is the correct name")
51 harness.check(len(arguments), 1, "Method has the right number of arguments")
52 arg = arguments[0]
53 harness.ok(isinstance(arg, WebIDL.IDLArgument), "Should be an IDLArgument")
54 harness.check(str(arg.type), "Boolean", "Argument has the right type")
55
56 attr = members[1]
57 harness.check(attr.identifier.QName(), "::TestEnumInterface::foo",
58 "Attr has correct QName")
59 harness.check(attr.identifier.name, "foo", "Attr has correct name")
60
61 harness.check(str(attr.type), "TestEnum (Wrapper)", "Attr type is the correct name")
62
63 # Now reset our parser
64 parser = parser.reset()
65 threw = False
66 try:
67 parser.parse("""
68 enum Enum {
69 "a",
70 "b",
71 "c"
72 };
73 interface TestInterface {
74 void foo(optional Enum e = "d");
75 };
76 """)
77 results = parser.finish()
78 except:
79 threw = True
80
81 harness.ok(threw, "Should not allow a bogus default value for an enum")
82
83 # Now reset our parser
84 parser = parser.reset()
85 parser.parse("""
86 enum Enum {
87 "a",
88 "b",
89 "c",
90 };
91 """)
92 results = parser.finish()
93 harness.check(len(results), 1, "Should allow trailing comma in enum")

mercurial