1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/parser/tests/test_overload.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +import WebIDL 1.5 + 1.6 +def WebIDLTest(parser, harness): 1.7 + parser.parse(""" 1.8 + interface TestOverloads { 1.9 + void basic(); 1.10 + void basic(long arg1); 1.11 + boolean abitharder(TestOverloads foo); 1.12 + boolean abitharder(boolean foo); 1.13 + void abitharder(ArrayBuffer? foo); 1.14 + void withVariadics(long... numbers); 1.15 + void withVariadics(TestOverloads iface); 1.16 + void withVariadics(long num, TestOverloads iface); 1.17 + void optionalTest(); 1.18 + void optionalTest(optional long num1, long num2); 1.19 + }; 1.20 + """) 1.21 + 1.22 + results = parser.finish() 1.23 + 1.24 + harness.ok(True, "TestOverloads interface parsed without error.") 1.25 + harness.check(len(results), 1, "Should be one production.") 1.26 + iface = results[0] 1.27 + harness.ok(isinstance(iface, WebIDL.IDLInterface), 1.28 + "Should be an IDLInterface") 1.29 + harness.check(iface.identifier.QName(), "::TestOverloads", "Interface has the right QName") 1.30 + harness.check(iface.identifier.name, "TestOverloads", "Interface has the right name") 1.31 + harness.check(len(iface.members), 4, "Expect %s members" % 4) 1.32 + 1.33 + member = iface.members[0] 1.34 + harness.check(member.identifier.QName(), "::TestOverloads::basic", "Method has the right QName") 1.35 + harness.check(member.identifier.name, "basic", "Method has the right name") 1.36 + harness.check(member.hasOverloads(), True, "Method has overloads") 1.37 + 1.38 + signatures = member.signatures() 1.39 + harness.check(len(signatures), 2, "Method should have 2 signatures") 1.40 + 1.41 + (retval, argumentSet) = signatures[0] 1.42 + 1.43 + harness.check(str(retval), "Void", "Expect a void retval") 1.44 + harness.check(len(argumentSet), 0, "Expect an empty argument set") 1.45 + 1.46 + (retval, argumentSet) = signatures[1] 1.47 + harness.check(str(retval), "Void", "Expect a void retval") 1.48 + harness.check(len(argumentSet), 1, "Expect an argument set with one argument") 1.49 + 1.50 + argument = argumentSet[0] 1.51 + harness.ok(isinstance(argument, WebIDL.IDLArgument), 1.52 + "Should be an IDLArgument") 1.53 + harness.check(argument.identifier.QName(), "::TestOverloads::basic::arg1", "Argument has the right QName") 1.54 + harness.check(argument.identifier.name, "arg1", "Argument has the right name") 1.55 + harness.check(str(argument.type), "Long", "Argument has the right type") 1.56 + 1.57 + member = iface.members[3] 1.58 + harness.check(len(member.overloadsForArgCount(0)), 1, 1.59 + "Only one overload for no args") 1.60 + harness.check(len(member.overloadsForArgCount(1)), 0, 1.61 + "No overloads for one arg") 1.62 + harness.check(len(member.overloadsForArgCount(2)), 1, 1.63 + "Only one overload for two args")