1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/parser/tests/test_enum.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +import WebIDL 1.5 + 1.6 +def WebIDLTest(parser, harness): 1.7 + parser.parse(""" 1.8 + enum TestEnum { 1.9 + "", 1.10 + "foo", 1.11 + "bar" 1.12 + }; 1.13 + 1.14 + interface TestEnumInterface { 1.15 + TestEnum doFoo(boolean arg); 1.16 + readonly attribute TestEnum foo; 1.17 + }; 1.18 + """) 1.19 + 1.20 + results = parser.finish() 1.21 + 1.22 + harness.ok(True, "TestEnumInterfaces interface parsed without error.") 1.23 + harness.check(len(results), 2, "Should be one production") 1.24 + harness.ok(isinstance(results[0], WebIDL.IDLEnum), 1.25 + "Should be an IDLEnum") 1.26 + harness.ok(isinstance(results[1], WebIDL.IDLInterface), 1.27 + "Should be an IDLInterface") 1.28 + 1.29 + enum = results[0] 1.30 + harness.check(enum.identifier.QName(), "::TestEnum", "Enum has the right QName") 1.31 + harness.check(enum.identifier.name, "TestEnum", "Enum has the right name") 1.32 + harness.check(enum.values(), ["", "foo", "bar"], "Enum has the right values") 1.33 + 1.34 + iface = results[1] 1.35 + 1.36 + harness.check(iface.identifier.QName(), "::TestEnumInterface", "Interface has the right QName") 1.37 + harness.check(iface.identifier.name, "TestEnumInterface", "Interface has the right name") 1.38 + harness.check(iface.parent, None, "Interface has no parent") 1.39 + 1.40 + members = iface.members 1.41 + harness.check(len(members), 2, "Should be one production") 1.42 + harness.ok(isinstance(members[0], WebIDL.IDLMethod), 1.43 + "Should be an IDLMethod") 1.44 + method = members[0] 1.45 + harness.check(method.identifier.QName(), "::TestEnumInterface::doFoo", 1.46 + "Method has correct QName") 1.47 + harness.check(method.identifier.name, "doFoo", "Method has correct name") 1.48 + 1.49 + signatures = method.signatures() 1.50 + harness.check(len(signatures), 1, "Expect one signature") 1.51 + 1.52 + (returnType, arguments) = signatures[0] 1.53 + harness.check(str(returnType), "TestEnum (Wrapper)", "Method type is the correct name") 1.54 + harness.check(len(arguments), 1, "Method has the right number of arguments") 1.55 + arg = arguments[0] 1.56 + harness.ok(isinstance(arg, WebIDL.IDLArgument), "Should be an IDLArgument") 1.57 + harness.check(str(arg.type), "Boolean", "Argument has the right type") 1.58 + 1.59 + attr = members[1] 1.60 + harness.check(attr.identifier.QName(), "::TestEnumInterface::foo", 1.61 + "Attr has correct QName") 1.62 + harness.check(attr.identifier.name, "foo", "Attr has correct name") 1.63 + 1.64 + harness.check(str(attr.type), "TestEnum (Wrapper)", "Attr type is the correct name") 1.65 + 1.66 + # Now reset our parser 1.67 + parser = parser.reset() 1.68 + threw = False 1.69 + try: 1.70 + parser.parse(""" 1.71 + enum Enum { 1.72 + "a", 1.73 + "b", 1.74 + "c" 1.75 + }; 1.76 + interface TestInterface { 1.77 + void foo(optional Enum e = "d"); 1.78 + }; 1.79 + """) 1.80 + results = parser.finish() 1.81 + except: 1.82 + threw = True 1.83 + 1.84 + harness.ok(threw, "Should not allow a bogus default value for an enum") 1.85 + 1.86 + # Now reset our parser 1.87 + parser = parser.reset() 1.88 + parser.parse(""" 1.89 + enum Enum { 1.90 + "a", 1.91 + "b", 1.92 + "c", 1.93 + }; 1.94 + """) 1.95 + results = parser.finish() 1.96 + harness.check(len(results), 1, "Should allow trailing comma in enum")