diff options
author | Jack Moffitt <jack@metajack.im> | 2014-08-28 09:34:23 -0600 |
---|---|---|
committer | Jack Moffitt <jack@metajack.im> | 2014-09-08 20:21:42 -0600 |
commit | c6ab60dbfc6da7b4f800c9e40893c8b58413960c (patch) | |
tree | d1d74076cf7fa20e4f77ec7cb82cae98b67362cb /components/script/dom/bindings/codegen/parser/tests/test_implements.py | |
parent | db2f642c32fc5bed445bb6f2e45b0f6f0b4342cf (diff) | |
download | servo-c6ab60dbfc6da7b4f800c9e40893c8b58413960c.tar.gz servo-c6ab60dbfc6da7b4f800c9e40893c8b58413960c.zip |
Cargoify servo
Diffstat (limited to 'components/script/dom/bindings/codegen/parser/tests/test_implements.py')
-rw-r--r-- | components/script/dom/bindings/codegen/parser/tests/test_implements.py | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/components/script/dom/bindings/codegen/parser/tests/test_implements.py b/components/script/dom/bindings/codegen/parser/tests/test_implements.py new file mode 100644 index 00000000000..04c47d92abe --- /dev/null +++ b/components/script/dom/bindings/codegen/parser/tests/test_implements.py @@ -0,0 +1,216 @@ +# Import the WebIDL module, so we can do isinstance checks and whatnot +import WebIDL + +def WebIDLTest(parser, harness): + # Basic functionality + threw = False + try: + parser.parse(""" + A implements B; + interface B { + attribute long x; + }; + interface A { + attribute long y; + }; + """) + results = parser.finish() + except: + threw = True + + harness.ok(not threw, "Should not have thrown on implements statement " + "before interfaces") + harness.check(len(results), 3, "We have three statements") + harness.ok(isinstance(results[1], WebIDL.IDLInterface), "B is an interface") + harness.check(len(results[1].members), 1, "B has one member") + A = results[2] + harness.ok(isinstance(A, WebIDL.IDLInterface), "A is an interface") + harness.check(len(A.members), 2, "A has two members") + harness.check(A.members[0].identifier.name, "y", "First member is 'y'") + harness.check(A.members[1].identifier.name, "x", "Second member is 'x'") + + # Duplicated member names not allowed + threw = False + try: + parser.parse(""" + C implements D; + interface D { + attribute long x; + }; + interface C { + attribute long x; + }; + """) + parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown on implemented interface duplicating " + "a name on base interface") + + # Same, but duplicated across implemented interfaces + threw = False + try: + parser.parse(""" + E implements F; + E implements G; + interface F { + attribute long x; + }; + interface G { + attribute long x; + }; + interface E {}; + """) + parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown on implemented interfaces " + "duplicating each other's member names") + + # Same, but duplicated across indirectly implemented interfaces + threw = False + try: + parser.parse(""" + H implements I; + H implements J; + I implements K; + interface K { + attribute long x; + }; + interface L { + attribute long x; + }; + interface I {}; + interface J : L {}; + interface H {}; + """) + parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown on indirectly implemented interfaces " + "duplicating each other's member names") + + # Same, but duplicated across an implemented interface and its parent + threw = False + try: + parser.parse(""" + M implements N; + interface O { + attribute long x; + }; + interface N : O { + attribute long x; + }; + interface M {}; + """) + parser.finish() + except: + threw = True + + harness.ok(threw, "Should have thrown on implemented interface and its " + "ancestor duplicating member names") + + # Reset the parser so we can actually find things where we expect + # them in the list + parser = parser.reset() + + # Diamonds should be allowed + threw = False + try: + parser.parse(""" + P implements Q; + P implements R; + Q implements S; + R implements S; + interface Q {}; + interface R {}; + interface S { + attribute long x; + }; + interface P {}; + """) + results = parser.finish() + except: + threw = True + + harness.ok(not threw, "Diamond inheritance is fine") + harness.check(results[6].identifier.name, "S", "We should be looking at 'S'") + harness.check(len(results[6].members), 1, "S should have one member") + harness.check(results[6].members[0].identifier.name, "x", + "S's member should be 'x'") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface TestInterface { + }; + callback interface TestCallbackInterface { + }; + TestInterface implements TestCallbackInterface; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, + "Should not allow callback interfaces on the right-hand side " + "of 'implements'") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface TestInterface { + }; + callback interface TestCallbackInterface { + }; + TestCallbackInterface implements TestInterface; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, + "Should not allow callback interfaces on the left-hand side of " + "'implements'") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface TestInterface { + }; + dictionary Dict { + }; + Dict implements TestInterface; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, + "Should not allow non-interfaces on the left-hand side " + "of 'implements'") + + parser = parser.reset() + threw = False + try: + parser.parse(""" + interface TestInterface { + }; + dictionary Dict { + }; + TestInterface implements Dict; + """) + results = parser.finish() + except: + threw = True + + harness.ok(threw, + "Should not allow non-interfaces on the right-hand side " + "of 'implements'") + |