1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/parser/tests/test_dictionary.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,555 @@ 1.4 +def WebIDLTest(parser, harness): 1.5 + parser.parse(""" 1.6 + dictionary Dict2 : Dict1 { 1.7 + long child = 5; 1.8 + Dict1 aaandAnother; 1.9 + }; 1.10 + dictionary Dict1 { 1.11 + long parent; 1.12 + double otherParent; 1.13 + }; 1.14 + """) 1.15 + results = parser.finish() 1.16 + 1.17 + dict1 = results[1]; 1.18 + dict2 = results[0]; 1.19 + 1.20 + harness.check(len(dict1.members), 2, "Dict1 has two members") 1.21 + harness.check(len(dict2.members), 2, "Dict2 has four members") 1.22 + 1.23 + harness.check(dict1.members[0].identifier.name, "otherParent", 1.24 + "'o' comes before 'p'") 1.25 + harness.check(dict1.members[1].identifier.name, "parent", 1.26 + "'o' really comes before 'p'") 1.27 + harness.check(dict2.members[0].identifier.name, "aaandAnother", 1.28 + "'a' comes before 'c'") 1.29 + harness.check(dict2.members[1].identifier.name, "child", 1.30 + "'a' really comes before 'c'") 1.31 + 1.32 + # Now reset our parser 1.33 + parser = parser.reset() 1.34 + threw = False 1.35 + try: 1.36 + parser.parse(""" 1.37 + dictionary Dict { 1.38 + long prop = 5; 1.39 + long prop; 1.40 + }; 1.41 + """) 1.42 + results = parser.finish() 1.43 + except: 1.44 + threw = True 1.45 + 1.46 + harness.ok(threw, "Should not allow name duplication in a dictionary") 1.47 + 1.48 + # Now reset our parser again 1.49 + parser = parser.reset() 1.50 + threw = False 1.51 + try: 1.52 + parser.parse(""" 1.53 + dictionary Dict1 : Dict2 { 1.54 + long prop = 5; 1.55 + }; 1.56 + dictionary Dict2 : Dict3 { 1.57 + long prop2; 1.58 + }; 1.59 + dictionary Dict3 { 1.60 + double prop; 1.61 + }; 1.62 + """) 1.63 + results = parser.finish() 1.64 + except: 1.65 + threw = True 1.66 + 1.67 + harness.ok(threw, "Should not allow name duplication in a dictionary and " 1.68 + "its ancestor") 1.69 + 1.70 + # More reset 1.71 + parser = parser.reset() 1.72 + threw = False 1.73 + try: 1.74 + parser.parse(""" 1.75 + interface Iface {}; 1.76 + dictionary Dict : Iface { 1.77 + long prop; 1.78 + }; 1.79 + """) 1.80 + results = parser.finish() 1.81 + except: 1.82 + threw = True 1.83 + 1.84 + harness.ok(threw, "Should not allow non-dictionary parents for dictionaries") 1.85 + 1.86 + # Even more reset 1.87 + parser = parser.reset() 1.88 + threw = False 1.89 + try: 1.90 + parser.parse(""" 1.91 + dictionary A : B {}; 1.92 + dictionary B : A {}; 1.93 + """) 1.94 + results = parser.finish() 1.95 + except: 1.96 + threw = True 1.97 + 1.98 + harness.ok(threw, "Should not allow cycles in dictionary inheritance chains") 1.99 + 1.100 + parser = parser.reset() 1.101 + threw = False 1.102 + try: 1.103 + parser.parse(""" 1.104 + dictionary A { 1.105 + [TreatNullAs=EmptyString] DOMString foo; 1.106 + }; 1.107 + """) 1.108 + results = parser.finish() 1.109 + except: 1.110 + threw = True 1.111 + 1.112 + harness.ok(threw, "Should not allow [TreatNullAs] on dictionary members"); 1.113 + 1.114 + parser = parser.reset() 1.115 + threw = False 1.116 + try: 1.117 + parser.parse(""" 1.118 + dictionary A { 1.119 + }; 1.120 + interface X { 1.121 + void doFoo(A arg); 1.122 + }; 1.123 + """) 1.124 + results = parser.finish() 1.125 + except: 1.126 + threw = True 1.127 + 1.128 + harness.ok(threw, "Trailing dictionary arg must be optional") 1.129 + 1.130 + parser = parser.reset() 1.131 + threw = False 1.132 + try: 1.133 + parser.parse(""" 1.134 + dictionary A { 1.135 + }; 1.136 + interface X { 1.137 + void doFoo((A or DOMString) arg); 1.138 + }; 1.139 + """) 1.140 + results = parser.finish() 1.141 + except: 1.142 + threw = True 1.143 + 1.144 + harness.ok(threw, 1.145 + "Trailing union arg containing a dictionary must be optional") 1.146 + 1.147 + parser = parser.reset() 1.148 + threw = False 1.149 + try: 1.150 + parser.parse(""" 1.151 + dictionary A { 1.152 + }; 1.153 + interface X { 1.154 + void doFoo(A arg1, optional long arg2); 1.155 + }; 1.156 + """) 1.157 + results = parser.finish() 1.158 + except: 1.159 + threw = True 1.160 + 1.161 + harness.ok(threw, "Dictionary arg followed by optional arg must be optional") 1.162 + 1.163 + parser = parser.reset() 1.164 + threw = False 1.165 + try: 1.166 + parser.parse(""" 1.167 + dictionary A { 1.168 + }; 1.169 + interface X { 1.170 + void doFoo(A arg1, optional long arg2, long arg3); 1.171 + }; 1.172 + """) 1.173 + results = parser.finish() 1.174 + except: 1.175 + threw = True 1.176 + 1.177 + harness.ok(not threw, 1.178 + "Dictionary arg followed by non-optional arg doesn't have to be optional") 1.179 + 1.180 + parser = parser.reset() 1.181 + threw = False 1.182 + try: 1.183 + parser.parse(""" 1.184 + dictionary A { 1.185 + }; 1.186 + interface X { 1.187 + void doFoo((A or DOMString) arg1, optional long arg2); 1.188 + }; 1.189 + """) 1.190 + results = parser.finish() 1.191 + except: 1.192 + threw = True 1.193 + 1.194 + harness.ok(threw, 1.195 + "Union arg containing dictionary followed by optional arg must " 1.196 + "be optional") 1.197 + 1.198 + parser = parser.reset() 1.199 + parser.parse(""" 1.200 + dictionary A { 1.201 + }; 1.202 + interface X { 1.203 + void doFoo(A arg1, long arg2); 1.204 + }; 1.205 + """) 1.206 + results = parser.finish() 1.207 + harness.ok(True, "Dictionary arg followed by required arg can be required") 1.208 + 1.209 + parser = parser.reset() 1.210 + threw = False 1.211 + try: 1.212 + parser.parse(""" 1.213 + dictionary A { 1.214 + }; 1.215 + interface X { 1.216 + void doFoo(optional A? arg1); 1.217 + }; 1.218 + """) 1.219 + results = parser.finish() 1.220 + except: 1.221 + threw = True 1.222 + 1.223 + harness.ok(threw, "Dictionary arg must not be nullable") 1.224 + 1.225 + parser = parser.reset() 1.226 + threw = False 1.227 + try: 1.228 + parser.parse(""" 1.229 + dictionary A { 1.230 + }; 1.231 + interface X { 1.232 + void doFoo(optional (A or long)? arg1); 1.233 + }; 1.234 + """) 1.235 + results = parser.finish() 1.236 + except: 1.237 + threw = True 1.238 + 1.239 + harness.ok(threw, "Dictionary arg must not be in a nullable union") 1.240 + 1.241 + parser = parser.reset() 1.242 + threw = False 1.243 + try: 1.244 + parser.parse(""" 1.245 + dictionary A { 1.246 + }; 1.247 + interface X { 1.248 + void doFoo(optional (A or long?) arg1); 1.249 + }; 1.250 + """) 1.251 + results = parser.finish() 1.252 + except: 1.253 + threw = True 1.254 + harness.ok(threw, 1.255 + "Dictionary must not be in a union with a nullable type") 1.256 + 1.257 + parser = parser.reset() 1.258 + threw = False 1.259 + try: 1.260 + parser.parse(""" 1.261 + dictionary A { 1.262 + }; 1.263 + interface X { 1.264 + void doFoo(optional (long? or A) arg1); 1.265 + }; 1.266 + """) 1.267 + results = parser.finish() 1.268 + except: 1.269 + threw = True 1.270 + harness.ok(threw, 1.271 + "A nullable type must not be in a union with a dictionary") 1.272 + 1.273 + parser = parser.reset() 1.274 + parser.parse(""" 1.275 + dictionary A { 1.276 + }; 1.277 + interface X { 1.278 + A? doFoo(); 1.279 + }; 1.280 + """) 1.281 + results = parser.finish() 1.282 + harness.ok(True, "Dictionary return value can be nullable") 1.283 + 1.284 + parser = parser.reset() 1.285 + parser.parse(""" 1.286 + dictionary A { 1.287 + }; 1.288 + interface X { 1.289 + void doFoo(optional A arg); 1.290 + }; 1.291 + """) 1.292 + results = parser.finish() 1.293 + harness.ok(True, "Dictionary arg should actually parse") 1.294 + 1.295 + parser = parser.reset() 1.296 + parser.parse(""" 1.297 + dictionary A { 1.298 + }; 1.299 + interface X { 1.300 + void doFoo(optional (A or DOMString) arg); 1.301 + }; 1.302 + """) 1.303 + results = parser.finish() 1.304 + harness.ok(True, "Union arg containing a dictionary should actually parse") 1.305 + 1.306 + parser = parser.reset() 1.307 + threw = False 1.308 + try: 1.309 + parser.parse(""" 1.310 + dictionary Foo { 1.311 + Foo foo; 1.312 + }; 1.313 + """) 1.314 + results = parser.finish() 1.315 + except: 1.316 + threw = True 1.317 + 1.318 + harness.ok(threw, "Member type must not be its Dictionary.") 1.319 + 1.320 + parser = parser.reset() 1.321 + threw = False 1.322 + try: 1.323 + parser.parse(""" 1.324 + dictionary Foo3 : Foo { 1.325 + short d; 1.326 + }; 1.327 + 1.328 + dictionary Foo2 : Foo3 { 1.329 + boolean c; 1.330 + }; 1.331 + 1.332 + dictionary Foo1 : Foo2 { 1.333 + long a; 1.334 + }; 1.335 + 1.336 + dictionary Foo { 1.337 + Foo1 b; 1.338 + }; 1.339 + """) 1.340 + results = parser.finish() 1.341 + except: 1.342 + threw = True 1.343 + 1.344 + harness.ok(threw, "Member type must not be a Dictionary that " 1.345 + "inherits from its Dictionary.") 1.346 + 1.347 + parser = parser.reset() 1.348 + threw = False 1.349 + try: 1.350 + parser.parse(""" 1.351 + dictionary Foo { 1.352 + (Foo or DOMString)[]? b; 1.353 + }; 1.354 + """) 1.355 + results = parser.finish() 1.356 + except: 1.357 + threw = True 1.358 + 1.359 + harness.ok(threw, "Member type must not be a Nullable type " 1.360 + "whose inner type includes its Dictionary.") 1.361 + 1.362 + parser = parser.reset() 1.363 + threw = False 1.364 + try: 1.365 + parser.parse(""" 1.366 + dictionary Foo { 1.367 + (DOMString or Foo) b; 1.368 + }; 1.369 + """) 1.370 + results = parser.finish() 1.371 + except: 1.372 + threw = True 1.373 + 1.374 + harness.ok(threw, "Member type must not be a Union type, one of " 1.375 + "whose member types includes its Dictionary.") 1.376 + 1.377 + parser = parser.reset() 1.378 + threw = False 1.379 + try: 1.380 + parser.parse(""" 1.381 + dictionary Foo { 1.382 + sequence<sequence<sequence<Foo>>> c; 1.383 + }; 1.384 + """) 1.385 + results = parser.finish() 1.386 + except: 1.387 + threw = True 1.388 + 1.389 + harness.ok(threw, "Member type must not be a Sequence type " 1.390 + "whose element type includes its Dictionary.") 1.391 + 1.392 + parser = parser.reset() 1.393 + threw = False 1.394 + try: 1.395 + parser.parse(""" 1.396 + dictionary Foo { 1.397 + (DOMString or Foo)[] d; 1.398 + }; 1.399 + """) 1.400 + results = parser.finish() 1.401 + except: 1.402 + threw = True 1.403 + 1.404 + harness.ok(threw, "Member type must not be an Array type " 1.405 + "whose element type includes its Dictionary.") 1.406 + 1.407 + parser = parser.reset() 1.408 + threw = False 1.409 + try: 1.410 + parser.parse(""" 1.411 + dictionary Foo { 1.412 + Foo1 b; 1.413 + }; 1.414 + 1.415 + dictionary Foo3 { 1.416 + Foo d; 1.417 + }; 1.418 + 1.419 + dictionary Foo2 : Foo3 { 1.420 + short c; 1.421 + }; 1.422 + 1.423 + dictionary Foo1 : Foo2 { 1.424 + long a; 1.425 + }; 1.426 + """) 1.427 + results = parser.finish() 1.428 + except: 1.429 + threw = True 1.430 + 1.431 + harness.ok(threw, "Member type must not be a Dictionary, one of whose " 1.432 + "members or inherited members has a type that includes " 1.433 + "its Dictionary.") 1.434 + 1.435 + parser = parser.reset(); 1.436 + threw = False 1.437 + try: 1.438 + parser.parse(""" 1.439 + dictionary Foo { 1.440 + }; 1.441 + 1.442 + dictionary Bar { 1.443 + Foo? d; 1.444 + }; 1.445 + """) 1.446 + results = parser.finish() 1.447 + except: 1.448 + threw = True 1.449 + 1.450 + harness.ok(threw, "Member type must not be a nullable dictionary") 1.451 + 1.452 + parser = parser.reset(); 1.453 + parser.parse(""" 1.454 + dictionary Foo { 1.455 + unrestricted float urFloat = 0; 1.456 + unrestricted float urFloat2 = 1.1; 1.457 + unrestricted float urFloat3 = -1.1; 1.458 + unrestricted float? urFloat4 = null; 1.459 + unrestricted float infUrFloat = Infinity; 1.460 + unrestricted float negativeInfUrFloat = -Infinity; 1.461 + unrestricted float nanUrFloat = NaN; 1.462 + 1.463 + unrestricted double urDouble = 0; 1.464 + unrestricted double urDouble2 = 1.1; 1.465 + unrestricted double urDouble3 = -1.1; 1.466 + unrestricted double? urDouble4 = null; 1.467 + unrestricted double infUrDouble = Infinity; 1.468 + unrestricted double negativeInfUrDouble = -Infinity; 1.469 + unrestricted double nanUrDouble = NaN; 1.470 + }; 1.471 + """) 1.472 + results = parser.finish() 1.473 + harness.ok(True, "Parsing default values for unrestricted types succeeded.") 1.474 + 1.475 + parser = parser.reset(); 1.476 + threw = False 1.477 + try: 1.478 + parser.parse(""" 1.479 + dictionary Foo { 1.480 + double f = Infinity; 1.481 + }; 1.482 + """) 1.483 + results = parser.finish() 1.484 + except: 1.485 + threw = True 1.486 + 1.487 + harness.ok(threw, "Only unrestricted values can be initialized to Infinity") 1.488 + 1.489 + parser = parser.reset(); 1.490 + threw = False 1.491 + try: 1.492 + parser.parse(""" 1.493 + dictionary Foo { 1.494 + double f = -Infinity; 1.495 + }; 1.496 + """) 1.497 + results = parser.finish() 1.498 + except: 1.499 + threw = True 1.500 + 1.501 + harness.ok(threw, "Only unrestricted values can be initialized to -Infinity") 1.502 + 1.503 + parser = parser.reset(); 1.504 + threw = False 1.505 + try: 1.506 + parser.parse(""" 1.507 + dictionary Foo { 1.508 + double f = NaN; 1.509 + }; 1.510 + """) 1.511 + results = parser.finish() 1.512 + except: 1.513 + threw = True 1.514 + 1.515 + harness.ok(threw, "Only unrestricted values can be initialized to NaN") 1.516 + 1.517 + parser = parser.reset(); 1.518 + threw = False 1.519 + try: 1.520 + parser.parse(""" 1.521 + dictionary Foo { 1.522 + float f = Infinity; 1.523 + }; 1.524 + """) 1.525 + results = parser.finish() 1.526 + except: 1.527 + threw = True 1.528 + 1.529 + harness.ok(threw, "Only unrestricted values can be initialized to Infinity") 1.530 + 1.531 + 1.532 + parser = parser.reset(); 1.533 + threw = False 1.534 + try: 1.535 + parser.parse(""" 1.536 + dictionary Foo { 1.537 + float f = -Infinity; 1.538 + }; 1.539 + """) 1.540 + results = parser.finish() 1.541 + except: 1.542 + threw = True 1.543 + 1.544 + harness.ok(threw, "Only unrestricted values can be initialized to -Infinity") 1.545 + 1.546 + parser = parser.reset(); 1.547 + threw = False 1.548 + try: 1.549 + parser.parse(""" 1.550 + dictionary Foo { 1.551 + float f = NaN; 1.552 + }; 1.553 + """) 1.554 + results = parser.finish() 1.555 + except: 1.556 + threw = True 1.557 + 1.558 + harness.ok(threw, "Only unrestricted values can be initialized to NaN")