dom/bindings/parser/tests/test_constructor.py

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 import WebIDL
michael@0 2
michael@0 3 def WebIDLTest(parser, harness):
michael@0 4 def checkArgument(argument, QName, name, type, optional, variadic):
michael@0 5 harness.ok(isinstance(argument, WebIDL.IDLArgument),
michael@0 6 "Should be an IDLArgument")
michael@0 7 harness.check(argument.identifier.QName(), QName, "Argument has the right QName")
michael@0 8 harness.check(argument.identifier.name, name, "Argument has the right name")
michael@0 9 harness.check(str(argument.type), type, "Argument has the right return type")
michael@0 10 harness.check(argument.optional, optional, "Argument has the right optional value")
michael@0 11 harness.check(argument.variadic, variadic, "Argument has the right variadic value")
michael@0 12
michael@0 13 def checkMethod(method, QName, name, signatures,
michael@0 14 static=True, getter=False, setter=False, creator=False,
michael@0 15 deleter=False, legacycaller=False, stringifier=False,
michael@0 16 chromeOnly=False):
michael@0 17 harness.ok(isinstance(method, WebIDL.IDLMethod),
michael@0 18 "Should be an IDLMethod")
michael@0 19 harness.ok(method.isMethod(), "Method is a method")
michael@0 20 harness.ok(not method.isAttr(), "Method is not an attr")
michael@0 21 harness.ok(not method.isConst(), "Method is not a const")
michael@0 22 harness.check(method.identifier.QName(), QName, "Method has the right QName")
michael@0 23 harness.check(method.identifier.name, name, "Method has the right name")
michael@0 24 harness.check(method.isStatic(), static, "Method has the correct static value")
michael@0 25 harness.check(method.isGetter(), getter, "Method has the correct getter value")
michael@0 26 harness.check(method.isSetter(), setter, "Method has the correct setter value")
michael@0 27 harness.check(method.isCreator(), creator, "Method has the correct creator value")
michael@0 28 harness.check(method.isDeleter(), deleter, "Method has the correct deleter value")
michael@0 29 harness.check(method.isLegacycaller(), legacycaller, "Method has the correct legacycaller value")
michael@0 30 harness.check(method.isStringifier(), stringifier, "Method has the correct stringifier value")
michael@0 31 harness.check(method.getExtendedAttribute("ChromeOnly") is not None, chromeOnly, "Method has the correct value for ChromeOnly")
michael@0 32 harness.check(len(method.signatures()), len(signatures), "Method has the correct number of signatures")
michael@0 33
michael@0 34 sigpairs = zip(method.signatures(), signatures)
michael@0 35 for (gotSignature, expectedSignature) in sigpairs:
michael@0 36 (gotRetType, gotArgs) = gotSignature
michael@0 37 (expectedRetType, expectedArgs) = expectedSignature
michael@0 38
michael@0 39 harness.check(str(gotRetType), expectedRetType,
michael@0 40 "Method has the expected return type.")
michael@0 41
michael@0 42 for i in range(0, len(gotArgs)):
michael@0 43 (QName, name, type, optional, variadic) = expectedArgs[i]
michael@0 44 checkArgument(gotArgs[i], QName, name, type, optional, variadic)
michael@0 45
michael@0 46 parser.parse("""
michael@0 47 [Constructor]
michael@0 48 interface TestConstructorNoArgs {
michael@0 49 };
michael@0 50
michael@0 51 [Constructor(DOMString name)]
michael@0 52 interface TestConstructorWithArgs {
michael@0 53 };
michael@0 54
michael@0 55 [Constructor(object foo), Constructor(boolean bar)]
michael@0 56 interface TestConstructorOverloads {
michael@0 57 };
michael@0 58 """)
michael@0 59 results = parser.finish()
michael@0 60 harness.check(len(results), 3, "Should be three productions")
michael@0 61 harness.ok(isinstance(results[0], WebIDL.IDLInterface),
michael@0 62 "Should be an IDLInterface")
michael@0 63 harness.ok(isinstance(results[1], WebIDL.IDLInterface),
michael@0 64 "Should be an IDLInterface")
michael@0 65 harness.ok(isinstance(results[2], WebIDL.IDLInterface),
michael@0 66 "Should be an IDLInterface")
michael@0 67
michael@0 68 checkMethod(results[0].ctor(), "::TestConstructorNoArgs::constructor",
michael@0 69 "constructor", [("TestConstructorNoArgs (Wrapper)", [])])
michael@0 70 checkMethod(results[1].ctor(), "::TestConstructorWithArgs::constructor",
michael@0 71 "constructor",
michael@0 72 [("TestConstructorWithArgs (Wrapper)",
michael@0 73 [("::TestConstructorWithArgs::constructor::name", "name", "String", False, False)])])
michael@0 74 checkMethod(results[2].ctor(), "::TestConstructorOverloads::constructor",
michael@0 75 "constructor",
michael@0 76 [("TestConstructorOverloads (Wrapper)",
michael@0 77 [("::TestConstructorOverloads::constructor::foo", "foo", "Object", False, False)]),
michael@0 78 ("TestConstructorOverloads (Wrapper)",
michael@0 79 [("::TestConstructorOverloads::constructor::bar", "bar", "Boolean", False, False)])])
michael@0 80
michael@0 81 parser = parser.reset()
michael@0 82 parser.parse("""
michael@0 83 [ChromeConstructor()]
michael@0 84 interface TestChromeConstructor {
michael@0 85 };
michael@0 86 """)
michael@0 87 results = parser.finish()
michael@0 88 harness.check(len(results), 1, "Should be one production")
michael@0 89 harness.ok(isinstance(results[0], WebIDL.IDLInterface),
michael@0 90 "Should be an IDLInterface")
michael@0 91
michael@0 92 checkMethod(results[0].ctor(), "::TestChromeConstructor::constructor",
michael@0 93 "constructor", [("TestChromeConstructor (Wrapper)", [])],
michael@0 94 chromeOnly=True)
michael@0 95
michael@0 96 parser = parser.reset()
michael@0 97 threw = False
michael@0 98 try:
michael@0 99 parser.parse("""
michael@0 100 [Constructor(),
michael@0 101 ChromeConstructor(DOMString a)]
michael@0 102 interface TestChromeConstructor {
michael@0 103 };
michael@0 104 """)
michael@0 105 results = parser.finish()
michael@0 106 except:
michael@0 107 threw = True
michael@0 108
michael@0 109 harness.ok(threw, "Can't have both a Constructor and a ChromeConstructor")

mercurial