tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_overload.py (2735B)


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