Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / bindings / parser / tests / test_enum.py
blob4eb26f7eaf9f7f78b99639f62c907200b94dd4ea
1 import WebIDL
4 def WebIDLTest(parser, harness):
5 parser.parse(
6 """
7 enum TestEnum {
8 "",
9 "foo",
10 "bar"
13 interface TestEnumInterface {
14 TestEnum doFoo(boolean arg);
15 readonly attribute TestEnum foo;
17 """
20 results = parser.finish()
22 harness.ok(True, "TestEnumInterfaces interface parsed without error.")
23 harness.check(len(results), 2, "Should be one production")
24 harness.ok(isinstance(results[0], WebIDL.IDLEnum), "Should be an IDLEnum")
25 harness.ok(isinstance(results[1], WebIDL.IDLInterface), "Should be an IDLInterface")
27 enum = results[0]
28 harness.check(enum.identifier.QName(), "::TestEnum", "Enum has the right QName")
29 harness.check(enum.identifier.name, "TestEnum", "Enum has the right name")
30 harness.check(enum.values(), ["", "foo", "bar"], "Enum has the right values")
32 iface = results[1]
34 harness.check(
35 iface.identifier.QName(), "::TestEnumInterface", "Interface has the right QName"
37 harness.check(
38 iface.identifier.name, "TestEnumInterface", "Interface has the right name"
40 harness.check(iface.parent, None, "Interface has no parent")
42 members = iface.members
43 harness.check(len(members), 2, "Should be one production")
44 harness.ok(isinstance(members[0], WebIDL.IDLMethod), "Should be an IDLMethod")
45 method = members[0]
46 harness.check(
47 method.identifier.QName(),
48 "::TestEnumInterface::doFoo",
49 "Method has correct QName",
51 harness.check(method.identifier.name, "doFoo", "Method has correct name")
53 signatures = method.signatures()
54 harness.check(len(signatures), 1, "Expect one signature")
56 (returnType, arguments) = signatures[0]
57 harness.check(
58 str(returnType), "TestEnum (Wrapper)", "Method type is the correct name"
60 harness.check(len(arguments), 1, "Method has the right number of arguments")
61 arg = arguments[0]
62 harness.ok(isinstance(arg, WebIDL.IDLArgument), "Should be an IDLArgument")
63 harness.check(str(arg.type), "Boolean", "Argument has the right type")
65 attr = members[1]
66 harness.check(
67 attr.identifier.QName(), "::TestEnumInterface::foo", "Attr has correct QName"
69 harness.check(attr.identifier.name, "foo", "Attr has correct name")
71 harness.check(str(attr.type), "TestEnum (Wrapper)", "Attr type is the correct name")
73 # Now reset our parser
74 parser = parser.reset()
75 threw = False
76 try:
77 parser.parse(
78 """
79 enum Enum {
80 "a",
81 "b",
82 "c"
84 interface TestInterface {
85 undefined foo(optional Enum e = "d");
87 """
89 parser.finish()
90 except WebIDL.WebIDLError:
91 threw = True
93 harness.ok(threw, "Should not allow a bogus default value for an enum")
95 # Now reset our parser
96 parser = parser.reset()
97 parser.parse(
98 """
99 enum Enum {
100 "a",
101 "b",
102 "c",
106 results = parser.finish()
107 harness.check(len(results), 1, "Should allow trailing comma in enum")