michael@0: def WebIDLTest(parser, harness): michael@0: parser.parse(""" michael@0: dictionary Dict2 : Dict1 { michael@0: long child = 5; michael@0: Dict1 aaandAnother; michael@0: }; michael@0: dictionary Dict1 { michael@0: long parent; michael@0: double otherParent; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: michael@0: dict1 = results[1]; michael@0: dict2 = results[0]; michael@0: michael@0: harness.check(len(dict1.members), 2, "Dict1 has two members") michael@0: harness.check(len(dict2.members), 2, "Dict2 has four members") michael@0: michael@0: harness.check(dict1.members[0].identifier.name, "otherParent", michael@0: "'o' comes before 'p'") michael@0: harness.check(dict1.members[1].identifier.name, "parent", michael@0: "'o' really comes before 'p'") michael@0: harness.check(dict2.members[0].identifier.name, "aaandAnother", michael@0: "'a' comes before 'c'") michael@0: harness.check(dict2.members[1].identifier.name, "child", michael@0: "'a' really comes before 'c'") michael@0: michael@0: # Now reset our parser michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Dict { michael@0: long prop = 5; michael@0: long prop; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should not allow name duplication in a dictionary") michael@0: michael@0: # Now reset our parser again michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Dict1 : Dict2 { michael@0: long prop = 5; michael@0: }; michael@0: dictionary Dict2 : Dict3 { michael@0: long prop2; michael@0: }; michael@0: dictionary Dict3 { michael@0: double prop; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should not allow name duplication in a dictionary and " michael@0: "its ancestor") michael@0: michael@0: # More reset michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface Iface {}; michael@0: dictionary Dict : Iface { michael@0: long prop; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should not allow non-dictionary parents for dictionaries") michael@0: michael@0: # Even more reset michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A : B {}; michael@0: dictionary B : A {}; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should not allow cycles in dictionary inheritance chains") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: [TreatNullAs=EmptyString] DOMString foo; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should not allow [TreatNullAs] on dictionary members"); michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(A arg); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Trailing dictionary arg must be optional") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo((A or DOMString) arg); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, michael@0: "Trailing union arg containing a dictionary must be optional") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(A arg1, optional long arg2); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Dictionary arg followed by optional arg must be optional") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(A arg1, optional long arg2, long arg3); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(not threw, michael@0: "Dictionary arg followed by non-optional arg doesn't have to be optional") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo((A or DOMString) arg1, optional long arg2); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, michael@0: "Union arg containing dictionary followed by optional arg must " michael@0: "be optional") michael@0: michael@0: parser = parser.reset() michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(A arg1, long arg2); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: harness.ok(True, "Dictionary arg followed by required arg can be required") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(optional A? arg1); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Dictionary arg must not be nullable") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(optional (A or long)? arg1); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Dictionary arg must not be in a nullable union") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(optional (A or long?) arg1); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: harness.ok(threw, michael@0: "Dictionary must not be in a union with a nullable type") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(optional (long? or A) arg1); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: harness.ok(threw, michael@0: "A nullable type must not be in a union with a dictionary") michael@0: michael@0: parser = parser.reset() michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: A? doFoo(); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: harness.ok(True, "Dictionary return value can be nullable") michael@0: michael@0: parser = parser.reset() michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(optional A arg); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: harness.ok(True, "Dictionary arg should actually parse") michael@0: michael@0: parser = parser.reset() michael@0: parser.parse(""" michael@0: dictionary A { michael@0: }; michael@0: interface X { michael@0: void doFoo(optional (A or DOMString) arg); michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: harness.ok(True, "Union arg containing a dictionary should actually parse") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: Foo foo; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Member type must not be its Dictionary.") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo3 : Foo { michael@0: short d; michael@0: }; michael@0: michael@0: dictionary Foo2 : Foo3 { michael@0: boolean c; michael@0: }; michael@0: michael@0: dictionary Foo1 : Foo2 { michael@0: long a; michael@0: }; michael@0: michael@0: dictionary Foo { michael@0: Foo1 b; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Member type must not be a Dictionary that " michael@0: "inherits from its Dictionary.") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: (Foo or DOMString)[]? b; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Member type must not be a Nullable type " michael@0: "whose inner type includes its Dictionary.") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: (DOMString or Foo) b; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Member type must not be a Union type, one of " michael@0: "whose member types includes its Dictionary.") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: sequence>> c; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Member type must not be a Sequence type " michael@0: "whose element type includes its Dictionary.") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: (DOMString or Foo)[] d; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Member type must not be an Array type " michael@0: "whose element type includes its Dictionary.") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: Foo1 b; michael@0: }; michael@0: michael@0: dictionary Foo3 { michael@0: Foo d; michael@0: }; michael@0: michael@0: dictionary Foo2 : Foo3 { michael@0: short c; michael@0: }; michael@0: michael@0: dictionary Foo1 : Foo2 { michael@0: long a; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Member type must not be a Dictionary, one of whose " michael@0: "members or inherited members has a type that includes " michael@0: "its Dictionary.") michael@0: michael@0: parser = parser.reset(); michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: }; michael@0: michael@0: dictionary Bar { michael@0: Foo? d; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Member type must not be a nullable dictionary") michael@0: michael@0: parser = parser.reset(); michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: unrestricted float urFloat = 0; michael@0: unrestricted float urFloat2 = 1.1; michael@0: unrestricted float urFloat3 = -1.1; michael@0: unrestricted float? urFloat4 = null; michael@0: unrestricted float infUrFloat = Infinity; michael@0: unrestricted float negativeInfUrFloat = -Infinity; michael@0: unrestricted float nanUrFloat = NaN; michael@0: michael@0: unrestricted double urDouble = 0; michael@0: unrestricted double urDouble2 = 1.1; michael@0: unrestricted double urDouble3 = -1.1; michael@0: unrestricted double? urDouble4 = null; michael@0: unrestricted double infUrDouble = Infinity; michael@0: unrestricted double negativeInfUrDouble = -Infinity; michael@0: unrestricted double nanUrDouble = NaN; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: harness.ok(True, "Parsing default values for unrestricted types succeeded.") michael@0: michael@0: parser = parser.reset(); michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: double f = Infinity; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Only unrestricted values can be initialized to Infinity") michael@0: michael@0: parser = parser.reset(); michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: double f = -Infinity; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Only unrestricted values can be initialized to -Infinity") michael@0: michael@0: parser = parser.reset(); michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: double f = NaN; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Only unrestricted values can be initialized to NaN") michael@0: michael@0: parser = parser.reset(); michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: float f = Infinity; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Only unrestricted values can be initialized to Infinity") michael@0: michael@0: michael@0: parser = parser.reset(); michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: float f = -Infinity; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Only unrestricted values can be initialized to -Infinity") michael@0: michael@0: parser = parser.reset(); michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: dictionary Foo { michael@0: float f = NaN; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Only unrestricted values can be initialized to NaN")