michael@0: # Import the WebIDL module, so we can do isinstance checks and whatnot michael@0: import WebIDL michael@0: michael@0: def WebIDLTest(parser, harness): michael@0: # Basic functionality michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: A implements B; michael@0: interface B { michael@0: attribute long x; michael@0: }; michael@0: interface A { michael@0: attribute long y; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(not threw, "Should not have thrown on implements statement " michael@0: "before interfaces") michael@0: harness.check(len(results), 3, "We have three statements") michael@0: harness.ok(isinstance(results[1], WebIDL.IDLInterface), "B is an interface") michael@0: harness.check(len(results[1].members), 1, "B has one member") michael@0: A = results[2] michael@0: harness.ok(isinstance(A, WebIDL.IDLInterface), "A is an interface") michael@0: harness.check(len(A.members), 2, "A has two members") michael@0: harness.check(A.members[0].identifier.name, "y", "First member is 'y'") michael@0: harness.check(A.members[1].identifier.name, "x", "Second member is 'x'") michael@0: michael@0: # Duplicated member names not allowed michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: C implements D; michael@0: interface D { michael@0: attribute long x; michael@0: }; michael@0: interface C { michael@0: attribute long x; michael@0: }; michael@0: """) michael@0: parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should have thrown on implemented interface duplicating " michael@0: "a name on base interface") michael@0: michael@0: # Same, but duplicated across implemented interfaces michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: E implements F; michael@0: E implements G; michael@0: interface F { michael@0: attribute long x; michael@0: }; michael@0: interface G { michael@0: attribute long x; michael@0: }; michael@0: interface E {}; michael@0: """) michael@0: parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should have thrown on implemented interfaces " michael@0: "duplicating each other's member names") michael@0: michael@0: # Same, but duplicated across indirectly implemented interfaces michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: H implements I; michael@0: H implements J; michael@0: I implements K; michael@0: interface K { michael@0: attribute long x; michael@0: }; michael@0: interface L { michael@0: attribute long x; michael@0: }; michael@0: interface I {}; michael@0: interface J : L {}; michael@0: interface H {}; michael@0: """) michael@0: parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should have thrown on indirectly implemented interfaces " michael@0: "duplicating each other's member names") michael@0: michael@0: # Same, but duplicated across an implemented interface and its parent michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: M implements N; michael@0: interface O { michael@0: attribute long x; michael@0: }; michael@0: interface N : O { michael@0: attribute long x; michael@0: }; michael@0: interface M {}; michael@0: """) michael@0: parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should have thrown on implemented interface and its " michael@0: "ancestor duplicating member names") michael@0: michael@0: # Reset the parser so we can actually find things where we expect michael@0: # them in the list michael@0: parser = parser.reset() michael@0: michael@0: # Diamonds should be allowed michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: P implements Q; michael@0: P implements R; michael@0: Q implements S; michael@0: R implements S; michael@0: interface Q {}; michael@0: interface R {}; michael@0: interface S { michael@0: attribute long x; michael@0: }; michael@0: interface P {}; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(not threw, "Diamond inheritance is fine") michael@0: harness.check(results[6].identifier.name, "S", "We should be looking at 'S'") michael@0: harness.check(len(results[6].members), 1, "S should have one member") michael@0: harness.check(results[6].members[0].identifier.name, "x", michael@0: "S's member should be 'x'") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface TestInterface { michael@0: }; michael@0: callback interface TestCallbackInterface { michael@0: }; michael@0: TestInterface implements TestCallbackInterface; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, michael@0: "Should not allow callback interfaces on the right-hand side " michael@0: "of 'implements'") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface TestInterface { michael@0: }; michael@0: callback interface TestCallbackInterface { michael@0: }; michael@0: TestCallbackInterface implements TestInterface; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, michael@0: "Should not allow callback interfaces on the left-hand side of " michael@0: "'implements'") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface TestInterface { michael@0: }; michael@0: dictionary Dict { michael@0: }; michael@0: Dict implements TestInterface; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, michael@0: "Should not allow non-interfaces on the left-hand side " michael@0: "of 'implements'") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface TestInterface { michael@0: }; michael@0: dictionary Dict { michael@0: }; michael@0: TestInterface implements Dict; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, michael@0: "Should not allow non-interfaces on the right-hand side " michael@0: "of 'implements'") michael@0: