michael@0: import WebIDL michael@0: michael@0: def WebIDLTest(parser, harness): michael@0: def checkArgument(argument, QName, name, type, optional, variadic): michael@0: harness.ok(isinstance(argument, WebIDL.IDLArgument), michael@0: "Should be an IDLArgument") michael@0: harness.check(argument.identifier.QName(), QName, "Argument has the right QName") michael@0: harness.check(argument.identifier.name, name, "Argument has the right name") michael@0: harness.check(str(argument.type), type, "Argument has the right return type") michael@0: harness.check(argument.optional, optional, "Argument has the right optional value") michael@0: harness.check(argument.variadic, variadic, "Argument has the right variadic value") michael@0: michael@0: def checkMethod(method, QName, name, signatures, michael@0: static=True, getter=False, setter=False, creator=False, michael@0: deleter=False, legacycaller=False, stringifier=False, michael@0: chromeOnly=False): michael@0: harness.ok(isinstance(method, WebIDL.IDLMethod), michael@0: "Should be an IDLMethod") michael@0: harness.ok(method.isMethod(), "Method is a method") michael@0: harness.ok(not method.isAttr(), "Method is not an attr") michael@0: harness.ok(not method.isConst(), "Method is not a const") michael@0: harness.check(method.identifier.QName(), QName, "Method has the right QName") michael@0: harness.check(method.identifier.name, name, "Method has the right name") michael@0: harness.check(method.isStatic(), static, "Method has the correct static value") michael@0: harness.check(method.isGetter(), getter, "Method has the correct getter value") michael@0: harness.check(method.isSetter(), setter, "Method has the correct setter value") michael@0: harness.check(method.isCreator(), creator, "Method has the correct creator value") michael@0: harness.check(method.isDeleter(), deleter, "Method has the correct deleter value") michael@0: harness.check(method.isLegacycaller(), legacycaller, "Method has the correct legacycaller value") michael@0: harness.check(method.isStringifier(), stringifier, "Method has the correct stringifier value") michael@0: harness.check(method.getExtendedAttribute("ChromeOnly") is not None, chromeOnly, "Method has the correct value for ChromeOnly") michael@0: harness.check(len(method.signatures()), len(signatures), "Method has the correct number of signatures") michael@0: michael@0: sigpairs = zip(method.signatures(), signatures) michael@0: for (gotSignature, expectedSignature) in sigpairs: michael@0: (gotRetType, gotArgs) = gotSignature michael@0: (expectedRetType, expectedArgs) = expectedSignature michael@0: michael@0: harness.check(str(gotRetType), expectedRetType, michael@0: "Method has the expected return type.") michael@0: michael@0: for i in range(0, len(gotArgs)): michael@0: (QName, name, type, optional, variadic) = expectedArgs[i] michael@0: checkArgument(gotArgs[i], QName, name, type, optional, variadic) michael@0: michael@0: parser.parse(""" michael@0: [Constructor] michael@0: interface TestConstructorNoArgs { michael@0: }; michael@0: michael@0: [Constructor(DOMString name)] michael@0: interface TestConstructorWithArgs { michael@0: }; michael@0: michael@0: [Constructor(object foo), Constructor(boolean bar)] michael@0: interface TestConstructorOverloads { michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: harness.check(len(results), 3, "Should be three productions") michael@0: harness.ok(isinstance(results[0], WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.ok(isinstance(results[1], WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.ok(isinstance(results[2], WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: michael@0: checkMethod(results[0].ctor(), "::TestConstructorNoArgs::constructor", michael@0: "constructor", [("TestConstructorNoArgs (Wrapper)", [])]) michael@0: checkMethod(results[1].ctor(), "::TestConstructorWithArgs::constructor", michael@0: "constructor", michael@0: [("TestConstructorWithArgs (Wrapper)", michael@0: [("::TestConstructorWithArgs::constructor::name", "name", "String", False, False)])]) michael@0: checkMethod(results[2].ctor(), "::TestConstructorOverloads::constructor", michael@0: "constructor", michael@0: [("TestConstructorOverloads (Wrapper)", michael@0: [("::TestConstructorOverloads::constructor::foo", "foo", "Object", False, False)]), michael@0: ("TestConstructorOverloads (Wrapper)", michael@0: [("::TestConstructorOverloads::constructor::bar", "bar", "Boolean", False, False)])]) michael@0: michael@0: parser = parser.reset() michael@0: parser.parse(""" michael@0: [ChromeConstructor()] michael@0: interface TestChromeConstructor { michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: harness.check(len(results), 1, "Should be one production") michael@0: harness.ok(isinstance(results[0], WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: michael@0: checkMethod(results[0].ctor(), "::TestChromeConstructor::constructor", michael@0: "constructor", [("TestChromeConstructor (Wrapper)", [])], michael@0: chromeOnly=True) michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: [Constructor(), michael@0: ChromeConstructor(DOMString a)] michael@0: interface TestChromeConstructor { michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Can't have both a Constructor and a ChromeConstructor")