michael@0: import WebIDL michael@0: michael@0: def WebIDLTest(parser, harness): michael@0: parser.parse(""" michael@0: enum TestEnum { michael@0: "", michael@0: "foo", michael@0: "bar" michael@0: }; michael@0: michael@0: interface TestEnumInterface { michael@0: TestEnum doFoo(boolean arg); michael@0: readonly attribute TestEnum foo; michael@0: }; michael@0: """) michael@0: michael@0: results = parser.finish() michael@0: michael@0: harness.ok(True, "TestEnumInterfaces interface parsed without error.") michael@0: harness.check(len(results), 2, "Should be one production") michael@0: harness.ok(isinstance(results[0], WebIDL.IDLEnum), michael@0: "Should be an IDLEnum") michael@0: harness.ok(isinstance(results[1], WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: michael@0: enum = results[0] michael@0: harness.check(enum.identifier.QName(), "::TestEnum", "Enum has the right QName") michael@0: harness.check(enum.identifier.name, "TestEnum", "Enum has the right name") michael@0: harness.check(enum.values(), ["", "foo", "bar"], "Enum has the right values") michael@0: michael@0: iface = results[1] michael@0: michael@0: harness.check(iface.identifier.QName(), "::TestEnumInterface", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestEnumInterface", "Interface has the right name") michael@0: harness.check(iface.parent, None, "Interface has no parent") michael@0: michael@0: members = iface.members michael@0: harness.check(len(members), 2, "Should be one production") michael@0: harness.ok(isinstance(members[0], WebIDL.IDLMethod), michael@0: "Should be an IDLMethod") michael@0: method = members[0] michael@0: harness.check(method.identifier.QName(), "::TestEnumInterface::doFoo", michael@0: "Method has correct QName") michael@0: harness.check(method.identifier.name, "doFoo", "Method has correct name") michael@0: michael@0: signatures = method.signatures() michael@0: harness.check(len(signatures), 1, "Expect one signature") michael@0: michael@0: (returnType, arguments) = signatures[0] michael@0: harness.check(str(returnType), "TestEnum (Wrapper)", "Method type is the correct name") michael@0: harness.check(len(arguments), 1, "Method has the right number of arguments") michael@0: arg = arguments[0] michael@0: harness.ok(isinstance(arg, WebIDL.IDLArgument), "Should be an IDLArgument") michael@0: harness.check(str(arg.type), "Boolean", "Argument has the right type") michael@0: michael@0: attr = members[1] michael@0: harness.check(attr.identifier.QName(), "::TestEnumInterface::foo", michael@0: "Attr has correct QName") michael@0: harness.check(attr.identifier.name, "foo", "Attr has correct name") michael@0: michael@0: harness.check(str(attr.type), "TestEnum (Wrapper)", "Attr type is the correct name") michael@0: michael@0: # Now reset our parser michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: enum Enum { michael@0: "a", michael@0: "b", michael@0: "c" michael@0: }; michael@0: interface TestInterface { michael@0: void foo(optional Enum e = "d"); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should not allow a bogus default value for an enum") michael@0: michael@0: # Now reset our parser michael@0: parser = parser.reset() michael@0: parser.parse(""" michael@0: enum Enum { michael@0: "a", michael@0: "b", michael@0: "c", michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: harness.check(len(results), 1, "Should allow trailing comma in enum")