dom/bindings/parser/tests/test_dictionary.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 def WebIDLTest(parser, harness):
michael@0 2 parser.parse("""
michael@0 3 dictionary Dict2 : Dict1 {
michael@0 4 long child = 5;
michael@0 5 Dict1 aaandAnother;
michael@0 6 };
michael@0 7 dictionary Dict1 {
michael@0 8 long parent;
michael@0 9 double otherParent;
michael@0 10 };
michael@0 11 """)
michael@0 12 results = parser.finish()
michael@0 13
michael@0 14 dict1 = results[1];
michael@0 15 dict2 = results[0];
michael@0 16
michael@0 17 harness.check(len(dict1.members), 2, "Dict1 has two members")
michael@0 18 harness.check(len(dict2.members), 2, "Dict2 has four members")
michael@0 19
michael@0 20 harness.check(dict1.members[0].identifier.name, "otherParent",
michael@0 21 "'o' comes before 'p'")
michael@0 22 harness.check(dict1.members[1].identifier.name, "parent",
michael@0 23 "'o' really comes before 'p'")
michael@0 24 harness.check(dict2.members[0].identifier.name, "aaandAnother",
michael@0 25 "'a' comes before 'c'")
michael@0 26 harness.check(dict2.members[1].identifier.name, "child",
michael@0 27 "'a' really comes before 'c'")
michael@0 28
michael@0 29 # Now reset our parser
michael@0 30 parser = parser.reset()
michael@0 31 threw = False
michael@0 32 try:
michael@0 33 parser.parse("""
michael@0 34 dictionary Dict {
michael@0 35 long prop = 5;
michael@0 36 long prop;
michael@0 37 };
michael@0 38 """)
michael@0 39 results = parser.finish()
michael@0 40 except:
michael@0 41 threw = True
michael@0 42
michael@0 43 harness.ok(threw, "Should not allow name duplication in a dictionary")
michael@0 44
michael@0 45 # Now reset our parser again
michael@0 46 parser = parser.reset()
michael@0 47 threw = False
michael@0 48 try:
michael@0 49 parser.parse("""
michael@0 50 dictionary Dict1 : Dict2 {
michael@0 51 long prop = 5;
michael@0 52 };
michael@0 53 dictionary Dict2 : Dict3 {
michael@0 54 long prop2;
michael@0 55 };
michael@0 56 dictionary Dict3 {
michael@0 57 double prop;
michael@0 58 };
michael@0 59 """)
michael@0 60 results = parser.finish()
michael@0 61 except:
michael@0 62 threw = True
michael@0 63
michael@0 64 harness.ok(threw, "Should not allow name duplication in a dictionary and "
michael@0 65 "its ancestor")
michael@0 66
michael@0 67 # More reset
michael@0 68 parser = parser.reset()
michael@0 69 threw = False
michael@0 70 try:
michael@0 71 parser.parse("""
michael@0 72 interface Iface {};
michael@0 73 dictionary Dict : Iface {
michael@0 74 long prop;
michael@0 75 };
michael@0 76 """)
michael@0 77 results = parser.finish()
michael@0 78 except:
michael@0 79 threw = True
michael@0 80
michael@0 81 harness.ok(threw, "Should not allow non-dictionary parents for dictionaries")
michael@0 82
michael@0 83 # Even more reset
michael@0 84 parser = parser.reset()
michael@0 85 threw = False
michael@0 86 try:
michael@0 87 parser.parse("""
michael@0 88 dictionary A : B {};
michael@0 89 dictionary B : A {};
michael@0 90 """)
michael@0 91 results = parser.finish()
michael@0 92 except:
michael@0 93 threw = True
michael@0 94
michael@0 95 harness.ok(threw, "Should not allow cycles in dictionary inheritance chains")
michael@0 96
michael@0 97 parser = parser.reset()
michael@0 98 threw = False
michael@0 99 try:
michael@0 100 parser.parse("""
michael@0 101 dictionary A {
michael@0 102 [TreatNullAs=EmptyString] DOMString foo;
michael@0 103 };
michael@0 104 """)
michael@0 105 results = parser.finish()
michael@0 106 except:
michael@0 107 threw = True
michael@0 108
michael@0 109 harness.ok(threw, "Should not allow [TreatNullAs] on dictionary members");
michael@0 110
michael@0 111 parser = parser.reset()
michael@0 112 threw = False
michael@0 113 try:
michael@0 114 parser.parse("""
michael@0 115 dictionary A {
michael@0 116 };
michael@0 117 interface X {
michael@0 118 void doFoo(A arg);
michael@0 119 };
michael@0 120 """)
michael@0 121 results = parser.finish()
michael@0 122 except:
michael@0 123 threw = True
michael@0 124
michael@0 125 harness.ok(threw, "Trailing dictionary arg must be optional")
michael@0 126
michael@0 127 parser = parser.reset()
michael@0 128 threw = False
michael@0 129 try:
michael@0 130 parser.parse("""
michael@0 131 dictionary A {
michael@0 132 };
michael@0 133 interface X {
michael@0 134 void doFoo((A or DOMString) arg);
michael@0 135 };
michael@0 136 """)
michael@0 137 results = parser.finish()
michael@0 138 except:
michael@0 139 threw = True
michael@0 140
michael@0 141 harness.ok(threw,
michael@0 142 "Trailing union arg containing a dictionary must be optional")
michael@0 143
michael@0 144 parser = parser.reset()
michael@0 145 threw = False
michael@0 146 try:
michael@0 147 parser.parse("""
michael@0 148 dictionary A {
michael@0 149 };
michael@0 150 interface X {
michael@0 151 void doFoo(A arg1, optional long arg2);
michael@0 152 };
michael@0 153 """)
michael@0 154 results = parser.finish()
michael@0 155 except:
michael@0 156 threw = True
michael@0 157
michael@0 158 harness.ok(threw, "Dictionary arg followed by optional arg must be optional")
michael@0 159
michael@0 160 parser = parser.reset()
michael@0 161 threw = False
michael@0 162 try:
michael@0 163 parser.parse("""
michael@0 164 dictionary A {
michael@0 165 };
michael@0 166 interface X {
michael@0 167 void doFoo(A arg1, optional long arg2, long arg3);
michael@0 168 };
michael@0 169 """)
michael@0 170 results = parser.finish()
michael@0 171 except:
michael@0 172 threw = True
michael@0 173
michael@0 174 harness.ok(not threw,
michael@0 175 "Dictionary arg followed by non-optional arg doesn't have to be optional")
michael@0 176
michael@0 177 parser = parser.reset()
michael@0 178 threw = False
michael@0 179 try:
michael@0 180 parser.parse("""
michael@0 181 dictionary A {
michael@0 182 };
michael@0 183 interface X {
michael@0 184 void doFoo((A or DOMString) arg1, optional long arg2);
michael@0 185 };
michael@0 186 """)
michael@0 187 results = parser.finish()
michael@0 188 except:
michael@0 189 threw = True
michael@0 190
michael@0 191 harness.ok(threw,
michael@0 192 "Union arg containing dictionary followed by optional arg must "
michael@0 193 "be optional")
michael@0 194
michael@0 195 parser = parser.reset()
michael@0 196 parser.parse("""
michael@0 197 dictionary A {
michael@0 198 };
michael@0 199 interface X {
michael@0 200 void doFoo(A arg1, long arg2);
michael@0 201 };
michael@0 202 """)
michael@0 203 results = parser.finish()
michael@0 204 harness.ok(True, "Dictionary arg followed by required arg can be required")
michael@0 205
michael@0 206 parser = parser.reset()
michael@0 207 threw = False
michael@0 208 try:
michael@0 209 parser.parse("""
michael@0 210 dictionary A {
michael@0 211 };
michael@0 212 interface X {
michael@0 213 void doFoo(optional A? arg1);
michael@0 214 };
michael@0 215 """)
michael@0 216 results = parser.finish()
michael@0 217 except:
michael@0 218 threw = True
michael@0 219
michael@0 220 harness.ok(threw, "Dictionary arg must not be nullable")
michael@0 221
michael@0 222 parser = parser.reset()
michael@0 223 threw = False
michael@0 224 try:
michael@0 225 parser.parse("""
michael@0 226 dictionary A {
michael@0 227 };
michael@0 228 interface X {
michael@0 229 void doFoo(optional (A or long)? arg1);
michael@0 230 };
michael@0 231 """)
michael@0 232 results = parser.finish()
michael@0 233 except:
michael@0 234 threw = True
michael@0 235
michael@0 236 harness.ok(threw, "Dictionary arg must not be in a nullable union")
michael@0 237
michael@0 238 parser = parser.reset()
michael@0 239 threw = False
michael@0 240 try:
michael@0 241 parser.parse("""
michael@0 242 dictionary A {
michael@0 243 };
michael@0 244 interface X {
michael@0 245 void doFoo(optional (A or long?) arg1);
michael@0 246 };
michael@0 247 """)
michael@0 248 results = parser.finish()
michael@0 249 except:
michael@0 250 threw = True
michael@0 251 harness.ok(threw,
michael@0 252 "Dictionary must not be in a union with a nullable type")
michael@0 253
michael@0 254 parser = parser.reset()
michael@0 255 threw = False
michael@0 256 try:
michael@0 257 parser.parse("""
michael@0 258 dictionary A {
michael@0 259 };
michael@0 260 interface X {
michael@0 261 void doFoo(optional (long? or A) arg1);
michael@0 262 };
michael@0 263 """)
michael@0 264 results = parser.finish()
michael@0 265 except:
michael@0 266 threw = True
michael@0 267 harness.ok(threw,
michael@0 268 "A nullable type must not be in a union with a dictionary")
michael@0 269
michael@0 270 parser = parser.reset()
michael@0 271 parser.parse("""
michael@0 272 dictionary A {
michael@0 273 };
michael@0 274 interface X {
michael@0 275 A? doFoo();
michael@0 276 };
michael@0 277 """)
michael@0 278 results = parser.finish()
michael@0 279 harness.ok(True, "Dictionary return value can be nullable")
michael@0 280
michael@0 281 parser = parser.reset()
michael@0 282 parser.parse("""
michael@0 283 dictionary A {
michael@0 284 };
michael@0 285 interface X {
michael@0 286 void doFoo(optional A arg);
michael@0 287 };
michael@0 288 """)
michael@0 289 results = parser.finish()
michael@0 290 harness.ok(True, "Dictionary arg should actually parse")
michael@0 291
michael@0 292 parser = parser.reset()
michael@0 293 parser.parse("""
michael@0 294 dictionary A {
michael@0 295 };
michael@0 296 interface X {
michael@0 297 void doFoo(optional (A or DOMString) arg);
michael@0 298 };
michael@0 299 """)
michael@0 300 results = parser.finish()
michael@0 301 harness.ok(True, "Union arg containing a dictionary should actually parse")
michael@0 302
michael@0 303 parser = parser.reset()
michael@0 304 threw = False
michael@0 305 try:
michael@0 306 parser.parse("""
michael@0 307 dictionary Foo {
michael@0 308 Foo foo;
michael@0 309 };
michael@0 310 """)
michael@0 311 results = parser.finish()
michael@0 312 except:
michael@0 313 threw = True
michael@0 314
michael@0 315 harness.ok(threw, "Member type must not be its Dictionary.")
michael@0 316
michael@0 317 parser = parser.reset()
michael@0 318 threw = False
michael@0 319 try:
michael@0 320 parser.parse("""
michael@0 321 dictionary Foo3 : Foo {
michael@0 322 short d;
michael@0 323 };
michael@0 324
michael@0 325 dictionary Foo2 : Foo3 {
michael@0 326 boolean c;
michael@0 327 };
michael@0 328
michael@0 329 dictionary Foo1 : Foo2 {
michael@0 330 long a;
michael@0 331 };
michael@0 332
michael@0 333 dictionary Foo {
michael@0 334 Foo1 b;
michael@0 335 };
michael@0 336 """)
michael@0 337 results = parser.finish()
michael@0 338 except:
michael@0 339 threw = True
michael@0 340
michael@0 341 harness.ok(threw, "Member type must not be a Dictionary that "
michael@0 342 "inherits from its Dictionary.")
michael@0 343
michael@0 344 parser = parser.reset()
michael@0 345 threw = False
michael@0 346 try:
michael@0 347 parser.parse("""
michael@0 348 dictionary Foo {
michael@0 349 (Foo or DOMString)[]? b;
michael@0 350 };
michael@0 351 """)
michael@0 352 results = parser.finish()
michael@0 353 except:
michael@0 354 threw = True
michael@0 355
michael@0 356 harness.ok(threw, "Member type must not be a Nullable type "
michael@0 357 "whose inner type includes its Dictionary.")
michael@0 358
michael@0 359 parser = parser.reset()
michael@0 360 threw = False
michael@0 361 try:
michael@0 362 parser.parse("""
michael@0 363 dictionary Foo {
michael@0 364 (DOMString or Foo) b;
michael@0 365 };
michael@0 366 """)
michael@0 367 results = parser.finish()
michael@0 368 except:
michael@0 369 threw = True
michael@0 370
michael@0 371 harness.ok(threw, "Member type must not be a Union type, one of "
michael@0 372 "whose member types includes its Dictionary.")
michael@0 373
michael@0 374 parser = parser.reset()
michael@0 375 threw = False
michael@0 376 try:
michael@0 377 parser.parse("""
michael@0 378 dictionary Foo {
michael@0 379 sequence<sequence<sequence<Foo>>> c;
michael@0 380 };
michael@0 381 """)
michael@0 382 results = parser.finish()
michael@0 383 except:
michael@0 384 threw = True
michael@0 385
michael@0 386 harness.ok(threw, "Member type must not be a Sequence type "
michael@0 387 "whose element type includes its Dictionary.")
michael@0 388
michael@0 389 parser = parser.reset()
michael@0 390 threw = False
michael@0 391 try:
michael@0 392 parser.parse("""
michael@0 393 dictionary Foo {
michael@0 394 (DOMString or Foo)[] d;
michael@0 395 };
michael@0 396 """)
michael@0 397 results = parser.finish()
michael@0 398 except:
michael@0 399 threw = True
michael@0 400
michael@0 401 harness.ok(threw, "Member type must not be an Array type "
michael@0 402 "whose element type includes its Dictionary.")
michael@0 403
michael@0 404 parser = parser.reset()
michael@0 405 threw = False
michael@0 406 try:
michael@0 407 parser.parse("""
michael@0 408 dictionary Foo {
michael@0 409 Foo1 b;
michael@0 410 };
michael@0 411
michael@0 412 dictionary Foo3 {
michael@0 413 Foo d;
michael@0 414 };
michael@0 415
michael@0 416 dictionary Foo2 : Foo3 {
michael@0 417 short c;
michael@0 418 };
michael@0 419
michael@0 420 dictionary Foo1 : Foo2 {
michael@0 421 long a;
michael@0 422 };
michael@0 423 """)
michael@0 424 results = parser.finish()
michael@0 425 except:
michael@0 426 threw = True
michael@0 427
michael@0 428 harness.ok(threw, "Member type must not be a Dictionary, one of whose "
michael@0 429 "members or inherited members has a type that includes "
michael@0 430 "its Dictionary.")
michael@0 431
michael@0 432 parser = parser.reset();
michael@0 433 threw = False
michael@0 434 try:
michael@0 435 parser.parse("""
michael@0 436 dictionary Foo {
michael@0 437 };
michael@0 438
michael@0 439 dictionary Bar {
michael@0 440 Foo? d;
michael@0 441 };
michael@0 442 """)
michael@0 443 results = parser.finish()
michael@0 444 except:
michael@0 445 threw = True
michael@0 446
michael@0 447 harness.ok(threw, "Member type must not be a nullable dictionary")
michael@0 448
michael@0 449 parser = parser.reset();
michael@0 450 parser.parse("""
michael@0 451 dictionary Foo {
michael@0 452 unrestricted float urFloat = 0;
michael@0 453 unrestricted float urFloat2 = 1.1;
michael@0 454 unrestricted float urFloat3 = -1.1;
michael@0 455 unrestricted float? urFloat4 = null;
michael@0 456 unrestricted float infUrFloat = Infinity;
michael@0 457 unrestricted float negativeInfUrFloat = -Infinity;
michael@0 458 unrestricted float nanUrFloat = NaN;
michael@0 459
michael@0 460 unrestricted double urDouble = 0;
michael@0 461 unrestricted double urDouble2 = 1.1;
michael@0 462 unrestricted double urDouble3 = -1.1;
michael@0 463 unrestricted double? urDouble4 = null;
michael@0 464 unrestricted double infUrDouble = Infinity;
michael@0 465 unrestricted double negativeInfUrDouble = -Infinity;
michael@0 466 unrestricted double nanUrDouble = NaN;
michael@0 467 };
michael@0 468 """)
michael@0 469 results = parser.finish()
michael@0 470 harness.ok(True, "Parsing default values for unrestricted types succeeded.")
michael@0 471
michael@0 472 parser = parser.reset();
michael@0 473 threw = False
michael@0 474 try:
michael@0 475 parser.parse("""
michael@0 476 dictionary Foo {
michael@0 477 double f = Infinity;
michael@0 478 };
michael@0 479 """)
michael@0 480 results = parser.finish()
michael@0 481 except:
michael@0 482 threw = True
michael@0 483
michael@0 484 harness.ok(threw, "Only unrestricted values can be initialized to Infinity")
michael@0 485
michael@0 486 parser = parser.reset();
michael@0 487 threw = False
michael@0 488 try:
michael@0 489 parser.parse("""
michael@0 490 dictionary Foo {
michael@0 491 double f = -Infinity;
michael@0 492 };
michael@0 493 """)
michael@0 494 results = parser.finish()
michael@0 495 except:
michael@0 496 threw = True
michael@0 497
michael@0 498 harness.ok(threw, "Only unrestricted values can be initialized to -Infinity")
michael@0 499
michael@0 500 parser = parser.reset();
michael@0 501 threw = False
michael@0 502 try:
michael@0 503 parser.parse("""
michael@0 504 dictionary Foo {
michael@0 505 double f = NaN;
michael@0 506 };
michael@0 507 """)
michael@0 508 results = parser.finish()
michael@0 509 except:
michael@0 510 threw = True
michael@0 511
michael@0 512 harness.ok(threw, "Only unrestricted values can be initialized to NaN")
michael@0 513
michael@0 514 parser = parser.reset();
michael@0 515 threw = False
michael@0 516 try:
michael@0 517 parser.parse("""
michael@0 518 dictionary Foo {
michael@0 519 float f = Infinity;
michael@0 520 };
michael@0 521 """)
michael@0 522 results = parser.finish()
michael@0 523 except:
michael@0 524 threw = True
michael@0 525
michael@0 526 harness.ok(threw, "Only unrestricted values can be initialized to Infinity")
michael@0 527
michael@0 528
michael@0 529 parser = parser.reset();
michael@0 530 threw = False
michael@0 531 try:
michael@0 532 parser.parse("""
michael@0 533 dictionary Foo {
michael@0 534 float f = -Infinity;
michael@0 535 };
michael@0 536 """)
michael@0 537 results = parser.finish()
michael@0 538 except:
michael@0 539 threw = True
michael@0 540
michael@0 541 harness.ok(threw, "Only unrestricted values can be initialized to -Infinity")
michael@0 542
michael@0 543 parser = parser.reset();
michael@0 544 threw = False
michael@0 545 try:
michael@0 546 parser.parse("""
michael@0 547 dictionary Foo {
michael@0 548 float f = NaN;
michael@0 549 };
michael@0 550 """)
michael@0 551 results = parser.finish()
michael@0 552 except:
michael@0 553 threw = True
michael@0 554
michael@0 555 harness.ok(threw, "Only unrestricted values can be initialized to NaN")

mercurial