1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/parser/tests/test_implements.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,216 @@ 1.4 +# Import the WebIDL module, so we can do isinstance checks and whatnot 1.5 +import WebIDL 1.6 + 1.7 +def WebIDLTest(parser, harness): 1.8 + # Basic functionality 1.9 + threw = False 1.10 + try: 1.11 + parser.parse(""" 1.12 + A implements B; 1.13 + interface B { 1.14 + attribute long x; 1.15 + }; 1.16 + interface A { 1.17 + attribute long y; 1.18 + }; 1.19 + """) 1.20 + results = parser.finish() 1.21 + except: 1.22 + threw = True 1.23 + 1.24 + harness.ok(not threw, "Should not have thrown on implements statement " 1.25 + "before interfaces") 1.26 + harness.check(len(results), 3, "We have three statements") 1.27 + harness.ok(isinstance(results[1], WebIDL.IDLInterface), "B is an interface") 1.28 + harness.check(len(results[1].members), 1, "B has one member") 1.29 + A = results[2] 1.30 + harness.ok(isinstance(A, WebIDL.IDLInterface), "A is an interface") 1.31 + harness.check(len(A.members), 2, "A has two members") 1.32 + harness.check(A.members[0].identifier.name, "y", "First member is 'y'") 1.33 + harness.check(A.members[1].identifier.name, "x", "Second member is 'x'") 1.34 + 1.35 + # Duplicated member names not allowed 1.36 + threw = False 1.37 + try: 1.38 + parser.parse(""" 1.39 + C implements D; 1.40 + interface D { 1.41 + attribute long x; 1.42 + }; 1.43 + interface C { 1.44 + attribute long x; 1.45 + }; 1.46 + """) 1.47 + parser.finish() 1.48 + except: 1.49 + threw = True 1.50 + 1.51 + harness.ok(threw, "Should have thrown on implemented interface duplicating " 1.52 + "a name on base interface") 1.53 + 1.54 + # Same, but duplicated across implemented interfaces 1.55 + threw = False 1.56 + try: 1.57 + parser.parse(""" 1.58 + E implements F; 1.59 + E implements G; 1.60 + interface F { 1.61 + attribute long x; 1.62 + }; 1.63 + interface G { 1.64 + attribute long x; 1.65 + }; 1.66 + interface E {}; 1.67 + """) 1.68 + parser.finish() 1.69 + except: 1.70 + threw = True 1.71 + 1.72 + harness.ok(threw, "Should have thrown on implemented interfaces " 1.73 + "duplicating each other's member names") 1.74 + 1.75 + # Same, but duplicated across indirectly implemented interfaces 1.76 + threw = False 1.77 + try: 1.78 + parser.parse(""" 1.79 + H implements I; 1.80 + H implements J; 1.81 + I implements K; 1.82 + interface K { 1.83 + attribute long x; 1.84 + }; 1.85 + interface L { 1.86 + attribute long x; 1.87 + }; 1.88 + interface I {}; 1.89 + interface J : L {}; 1.90 + interface H {}; 1.91 + """) 1.92 + parser.finish() 1.93 + except: 1.94 + threw = True 1.95 + 1.96 + harness.ok(threw, "Should have thrown on indirectly implemented interfaces " 1.97 + "duplicating each other's member names") 1.98 + 1.99 + # Same, but duplicated across an implemented interface and its parent 1.100 + threw = False 1.101 + try: 1.102 + parser.parse(""" 1.103 + M implements N; 1.104 + interface O { 1.105 + attribute long x; 1.106 + }; 1.107 + interface N : O { 1.108 + attribute long x; 1.109 + }; 1.110 + interface M {}; 1.111 + """) 1.112 + parser.finish() 1.113 + except: 1.114 + threw = True 1.115 + 1.116 + harness.ok(threw, "Should have thrown on implemented interface and its " 1.117 + "ancestor duplicating member names") 1.118 + 1.119 + # Reset the parser so we can actually find things where we expect 1.120 + # them in the list 1.121 + parser = parser.reset() 1.122 + 1.123 + # Diamonds should be allowed 1.124 + threw = False 1.125 + try: 1.126 + parser.parse(""" 1.127 + P implements Q; 1.128 + P implements R; 1.129 + Q implements S; 1.130 + R implements S; 1.131 + interface Q {}; 1.132 + interface R {}; 1.133 + interface S { 1.134 + attribute long x; 1.135 + }; 1.136 + interface P {}; 1.137 + """) 1.138 + results = parser.finish() 1.139 + except: 1.140 + threw = True 1.141 + 1.142 + harness.ok(not threw, "Diamond inheritance is fine") 1.143 + harness.check(results[6].identifier.name, "S", "We should be looking at 'S'") 1.144 + harness.check(len(results[6].members), 1, "S should have one member") 1.145 + harness.check(results[6].members[0].identifier.name, "x", 1.146 + "S's member should be 'x'") 1.147 + 1.148 + parser = parser.reset() 1.149 + threw = False 1.150 + try: 1.151 + parser.parse(""" 1.152 + interface TestInterface { 1.153 + }; 1.154 + callback interface TestCallbackInterface { 1.155 + }; 1.156 + TestInterface implements TestCallbackInterface; 1.157 + """) 1.158 + results = parser.finish() 1.159 + except: 1.160 + threw = True 1.161 + 1.162 + harness.ok(threw, 1.163 + "Should not allow callback interfaces on the right-hand side " 1.164 + "of 'implements'") 1.165 + 1.166 + parser = parser.reset() 1.167 + threw = False 1.168 + try: 1.169 + parser.parse(""" 1.170 + interface TestInterface { 1.171 + }; 1.172 + callback interface TestCallbackInterface { 1.173 + }; 1.174 + TestCallbackInterface implements TestInterface; 1.175 + """) 1.176 + results = parser.finish() 1.177 + except: 1.178 + threw = True 1.179 + 1.180 + harness.ok(threw, 1.181 + "Should not allow callback interfaces on the left-hand side of " 1.182 + "'implements'") 1.183 + 1.184 + parser = parser.reset() 1.185 + threw = False 1.186 + try: 1.187 + parser.parse(""" 1.188 + interface TestInterface { 1.189 + }; 1.190 + dictionary Dict { 1.191 + }; 1.192 + Dict implements TestInterface; 1.193 + """) 1.194 + results = parser.finish() 1.195 + except: 1.196 + threw = True 1.197 + 1.198 + harness.ok(threw, 1.199 + "Should not allow non-interfaces on the left-hand side " 1.200 + "of 'implements'") 1.201 + 1.202 + parser = parser.reset() 1.203 + threw = False 1.204 + try: 1.205 + parser.parse(""" 1.206 + interface TestInterface { 1.207 + }; 1.208 + dictionary Dict { 1.209 + }; 1.210 + TestInterface implements Dict; 1.211 + """) 1.212 + results = parser.finish() 1.213 + except: 1.214 + threw = True 1.215 + 1.216 + harness.ok(threw, 1.217 + "Should not allow non-interfaces on the right-hand side " 1.218 + "of 'implements'") 1.219 +