dom/bindings/parser/tests/test_overload.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 parser.parse("""
michael@0 5 interface TestOverloads {
michael@0 6 void basic();
michael@0 7 void basic(long arg1);
michael@0 8 boolean abitharder(TestOverloads foo);
michael@0 9 boolean abitharder(boolean foo);
michael@0 10 void abitharder(ArrayBuffer? foo);
michael@0 11 void withVariadics(long... numbers);
michael@0 12 void withVariadics(TestOverloads iface);
michael@0 13 void withVariadics(long num, TestOverloads iface);
michael@0 14 void optionalTest();
michael@0 15 void optionalTest(optional long num1, long num2);
michael@0 16 };
michael@0 17 """)
michael@0 18
michael@0 19 results = parser.finish()
michael@0 20
michael@0 21 harness.ok(True, "TestOverloads interface parsed without error.")
michael@0 22 harness.check(len(results), 1, "Should be one production.")
michael@0 23 iface = results[0]
michael@0 24 harness.ok(isinstance(iface, WebIDL.IDLInterface),
michael@0 25 "Should be an IDLInterface")
michael@0 26 harness.check(iface.identifier.QName(), "::TestOverloads", "Interface has the right QName")
michael@0 27 harness.check(iface.identifier.name, "TestOverloads", "Interface has the right name")
michael@0 28 harness.check(len(iface.members), 4, "Expect %s members" % 4)
michael@0 29
michael@0 30 member = iface.members[0]
michael@0 31 harness.check(member.identifier.QName(), "::TestOverloads::basic", "Method has the right QName")
michael@0 32 harness.check(member.identifier.name, "basic", "Method has the right name")
michael@0 33 harness.check(member.hasOverloads(), True, "Method has overloads")
michael@0 34
michael@0 35 signatures = member.signatures()
michael@0 36 harness.check(len(signatures), 2, "Method should have 2 signatures")
michael@0 37
michael@0 38 (retval, argumentSet) = signatures[0]
michael@0 39
michael@0 40 harness.check(str(retval), "Void", "Expect a void retval")
michael@0 41 harness.check(len(argumentSet), 0, "Expect an empty argument set")
michael@0 42
michael@0 43 (retval, argumentSet) = signatures[1]
michael@0 44 harness.check(str(retval), "Void", "Expect a void retval")
michael@0 45 harness.check(len(argumentSet), 1, "Expect an argument set with one argument")
michael@0 46
michael@0 47 argument = argumentSet[0]
michael@0 48 harness.ok(isinstance(argument, WebIDL.IDLArgument),
michael@0 49 "Should be an IDLArgument")
michael@0 50 harness.check(argument.identifier.QName(), "::TestOverloads::basic::arg1", "Argument has the right QName")
michael@0 51 harness.check(argument.identifier.name, "arg1", "Argument has the right name")
michael@0 52 harness.check(str(argument.type), "Long", "Argument has the right type")
michael@0 53
michael@0 54 member = iface.members[3]
michael@0 55 harness.check(len(member.overloadsForArgCount(0)), 1,
michael@0 56 "Only one overload for no args")
michael@0 57 harness.check(len(member.overloadsForArgCount(1)), 0,
michael@0 58 "No overloads for one arg")
michael@0 59 harness.check(len(member.overloadsForArgCount(2)), 1,
michael@0 60 "Only one overload for two args")

mercurial