diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2016-09-26 13:17:12 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2016-09-26 13:17:12 +0200 |
commit | 107b92cc62d07a48a13f9a7934268fdabf806793 (patch) | |
tree | a89a40a7e886bfca58169430ff9a34da26a034a8 /components/script/dom/bindings/codegen/parser/tests | |
parent | 4c084cefa3ea373d73aed225bdf3952f4f346d62 (diff) | |
download | servo-107b92cc62d07a48a13f9a7934268fdabf806793.tar.gz servo-107b92cc62d07a48a13f9a7934268fdabf806793.zip |
Update the WebIDL parser
Diffstat (limited to 'components/script/dom/bindings/codegen/parser/tests')
9 files changed, 56 insertions, 249 deletions
diff --git a/components/script/dom/bindings/codegen/parser/tests/test_array.py b/components/script/dom/bindings/codegen/parser/tests/test_array.py deleted file mode 100644 index 8f9e9c96854..00000000000 --- a/components/script/dom/bindings/codegen/parser/tests/test_array.py +++ /dev/null @@ -1,18 +0,0 @@ -def WebIDLTest(parser, harness): - threw = False - try: - parser.parse(""" - dictionary Foo { - short a; - }; - - dictionary Foo1 { - Foo[] b; - }; - """) - results = parser.finish() - except: - threw = True - - harness.ok(threw, "Array must not contain dictionary " - "as element type.") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_array_of_interface.py b/components/script/dom/bindings/codegen/parser/tests/test_array_of_interface.py deleted file mode 100644 index 26528984595..00000000000 --- a/components/script/dom/bindings/codegen/parser/tests/test_array_of_interface.py +++ /dev/null @@ -1,13 +0,0 @@ -import WebIDL - -def WebIDLTest(parser, harness): - parser.parse(""" - interface A { - attribute long a; - }; - - interface B { - attribute A[] b; - }; - """); - parser.finish() diff --git a/components/script/dom/bindings/codegen/parser/tests/test_arraybuffer.py b/components/script/dom/bindings/codegen/parser/tests/test_arraybuffer.py index 5b8e56f86ca..4a96c0ff512 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_arraybuffer.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_arraybuffer.py @@ -4,37 +4,37 @@ def WebIDLTest(parser, harness): parser.parse(""" interface TestArrayBuffer { attribute ArrayBuffer bufferAttr; - void bufferMethod(ArrayBuffer arg1, ArrayBuffer? arg2, ArrayBuffer[] arg3, sequence<ArrayBuffer> arg4); + void bufferMethod(ArrayBuffer arg1, ArrayBuffer? arg2, sequence<ArrayBuffer> arg3); attribute ArrayBufferView viewAttr; - void viewMethod(ArrayBufferView arg1, ArrayBufferView? arg2, ArrayBufferView[] arg3, sequence<ArrayBufferView> arg4); + void viewMethod(ArrayBufferView arg1, ArrayBufferView? arg2, sequence<ArrayBufferView> arg3); attribute Int8Array int8ArrayAttr; - void int8ArrayMethod(Int8Array arg1, Int8Array? arg2, Int8Array[] arg3, sequence<Int8Array> arg4); + void int8ArrayMethod(Int8Array arg1, Int8Array? arg2, sequence<Int8Array> arg3); attribute Uint8Array uint8ArrayAttr; - void uint8ArrayMethod(Uint8Array arg1, Uint8Array? arg2, Uint8Array[] arg3, sequence<Uint8Array> arg4); + void uint8ArrayMethod(Uint8Array arg1, Uint8Array? arg2, sequence<Uint8Array> arg3); attribute Uint8ClampedArray uint8ClampedArrayAttr; - void uint8ClampedArrayMethod(Uint8ClampedArray arg1, Uint8ClampedArray? arg2, Uint8ClampedArray[] arg3, sequence<Uint8ClampedArray> arg4); + void uint8ClampedArrayMethod(Uint8ClampedArray arg1, Uint8ClampedArray? arg2, sequence<Uint8ClampedArray> arg3); attribute Int16Array int16ArrayAttr; - void int16ArrayMethod(Int16Array arg1, Int16Array? arg2, Int16Array[] arg3, sequence<Int16Array> arg4); + void int16ArrayMethod(Int16Array arg1, Int16Array? arg2, sequence<Int16Array> arg3); attribute Uint16Array uint16ArrayAttr; - void uint16ArrayMethod(Uint16Array arg1, Uint16Array? arg2, Uint16Array[] arg3, sequence<Uint16Array> arg4); + void uint16ArrayMethod(Uint16Array arg1, Uint16Array? arg2, sequence<Uint16Array> arg3); attribute Int32Array int32ArrayAttr; - void int32ArrayMethod(Int32Array arg1, Int32Array? arg2, Int32Array[] arg3, sequence<Int32Array> arg4); + void int32ArrayMethod(Int32Array arg1, Int32Array? arg2, sequence<Int32Array> arg3); attribute Uint32Array uint32ArrayAttr; - void uint32ArrayMethod(Uint32Array arg1, Uint32Array? arg2, Uint32Array[] arg3, sequence<Uint32Array> arg4); + void uint32ArrayMethod(Uint32Array arg1, Uint32Array? arg2, sequence<Uint32Array> arg3); attribute Float32Array float32ArrayAttr; - void float32ArrayMethod(Float32Array arg1, Float32Array? arg2, Float32Array[] arg3, sequence<Float32Array> arg4); + void float32ArrayMethod(Float32Array arg1, Float32Array? arg2, sequence<Float32Array> arg3); attribute Float64Array float64ArrayAttr; - void float64ArrayMethod(Float64Array arg1, Float64Array? arg2, Float64Array[] arg3, sequence<Float64Array> arg4); + void float64ArrayMethod(Float64Array arg1, Float64Array? arg2, sequence<Float64Array> arg3); }; """) @@ -56,7 +56,7 @@ def WebIDLTest(parser, harness): (retType, arguments) = method.signatures()[0] harness.ok(retType.isVoid(), "Should have a void return type") - harness.check(len(arguments), 4, "Expect 4 arguments") + harness.check(len(arguments), 3, "Expect 3 arguments") harness.check(str(arguments[0].type), t, "Expect an ArrayBuffer type") harness.ok(arguments[0].type.isSpiderMonkeyInterface(), "Should test as a js interface") @@ -64,12 +64,9 @@ def WebIDLTest(parser, harness): harness.check(str(arguments[1].type), t + "OrNull", "Expect an ArrayBuffer type") harness.ok(arguments[1].type.inner.isSpiderMonkeyInterface(), "Should test as a js interface") - harness.check(str(arguments[2].type), t + "Array", "Expect an ArrayBuffer type") + harness.check(str(arguments[2].type), t + "Sequence", "Expect an ArrayBuffer type") harness.ok(arguments[2].type.inner.isSpiderMonkeyInterface(), "Should test as a js interface") - harness.check(str(arguments[3].type), t + "Sequence", "Expect an ArrayBuffer type") - harness.ok(arguments[3].type.inner.isSpiderMonkeyInterface(), "Should test as a js interface") - checkStuff(members[0], members[1], "ArrayBuffer") checkStuff(members[2], members[3], "ArrayBufferView") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_attr.py b/components/script/dom/bindings/codegen/parser/tests/test_attr.py index fb0c9196460..ad7aabc1918 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_attr.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_attr.py @@ -77,110 +77,6 @@ def WebIDLTest(parser, harness): attribute float? f; readonly attribute float? rf; }; - - interface TestAttrArray { - attribute byte[] b; - readonly attribute byte[] rb; - attribute octet[] o; - readonly attribute octet[] ro; - attribute short[] s; - readonly attribute short[] rs; - attribute unsigned short[] us; - readonly attribute unsigned short[] rus; - attribute long[] l; - readonly attribute long[] rl; - attribute unsigned long[] ul; - readonly attribute unsigned long[] rul; - attribute long long[] ll; - readonly attribute long long[] rll; - attribute unsigned long long[] ull; - readonly attribute unsigned long long[] rull; - attribute DOMString[] str; - readonly attribute DOMString[] rstr; - attribute object[] obj; - readonly attribute object[] robj; - attribute object[] _object; - attribute float[] f; - readonly attribute float[] rf; - }; - - interface TestAttrNullableArray { - attribute byte[]? b; - readonly attribute byte[]? rb; - attribute octet[]? o; - readonly attribute octet[]? ro; - attribute short[]? s; - readonly attribute short[]? rs; - attribute unsigned short[]? us; - readonly attribute unsigned short[]? rus; - attribute long[]? l; - readonly attribute long[]? rl; - attribute unsigned long[]? ul; - readonly attribute unsigned long[]? rul; - attribute long long[]? ll; - readonly attribute long long[]? rll; - attribute unsigned long long[]? ull; - readonly attribute unsigned long long[]? rull; - attribute DOMString[]? str; - readonly attribute DOMString[]? rstr; - attribute object[]? obj; - readonly attribute object[]? robj; - attribute object[]? _object; - attribute float[]? f; - readonly attribute float[]? rf; - }; - - interface TestAttrArrayOfNullableTypes { - attribute byte?[] b; - readonly attribute byte?[] rb; - attribute octet?[] o; - readonly attribute octet?[] ro; - attribute short?[] s; - readonly attribute short?[] rs; - attribute unsigned short?[] us; - readonly attribute unsigned short?[] rus; - attribute long?[] l; - readonly attribute long?[] rl; - attribute unsigned long?[] ul; - readonly attribute unsigned long?[] rul; - attribute long long?[] ll; - readonly attribute long long?[] rll; - attribute unsigned long long?[] ull; - readonly attribute unsigned long long?[] rull; - attribute DOMString?[] str; - readonly attribute DOMString?[] rstr; - attribute object?[] obj; - readonly attribute object?[] robj; - attribute object?[] _object; - attribute float?[] f; - readonly attribute float?[] rf; - }; - - interface TestAttrNullableArrayOfNullableTypes { - attribute byte?[]? b; - readonly attribute byte?[]? rb; - attribute octet?[]? o; - readonly attribute octet?[]? ro; - attribute short?[]? s; - readonly attribute short?[]? rs; - attribute unsigned short?[]? us; - readonly attribute unsigned short?[]? rus; - attribute long?[]? l; - readonly attribute long?[]? rl; - attribute unsigned long?[]? ul; - readonly attribute unsigned long?[]? rul; - attribute long long?[]? ll; - readonly attribute long long?[]? rll; - attribute unsigned long long?[]? ull; - readonly attribute unsigned long long?[]? rull; - attribute DOMString?[]? str; - readonly attribute DOMString?[]? rstr; - attribute object?[]? obj; - readonly attribute object?[]? robj; - attribute object?[]? _object; - attribute float?[]? f; - readonly attribute float?[]? rf; - }; """) results = parser.finish() @@ -197,7 +93,7 @@ def WebIDLTest(parser, harness): harness.check(attr.readonly, readonly, "Attr's readonly state is correct") harness.ok(True, "TestAttr interface parsed without error.") - harness.check(len(results), 6, "Should be six productions.") + harness.check(len(results), 2, "Should be two productions.") iface = results[0] harness.ok(isinstance(iface, WebIDL.IDLInterface), "Should be an IDLInterface") @@ -228,66 +124,6 @@ def WebIDLTest(parser, harness): (QName, name, type, readonly) = data checkAttr(attr, QName % "Nullable", name, type % "OrNull", readonly) - iface = results[2] - harness.ok(isinstance(iface, WebIDL.IDLInterface), - "Should be an IDLInterface") - harness.check(iface.identifier.QName(), "::TestAttrArray", "Interface has the right QName") - harness.check(iface.identifier.name, "TestAttrArray", "Interface has the right name") - harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) - - attrs = iface.members - - for i in range(len(attrs)): - data = testData[i] - attr = attrs[i] - (QName, name, type, readonly) = data - checkAttr(attr, QName % "Array", name, type % "Array", readonly) - - iface = results[3] - harness.ok(isinstance(iface, WebIDL.IDLInterface), - "Should be an IDLInterface") - harness.check(iface.identifier.QName(), "::TestAttrNullableArray", "Interface has the right QName") - harness.check(iface.identifier.name, "TestAttrNullableArray", "Interface has the right name") - harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) - - attrs = iface.members - - for i in range(len(attrs)): - data = testData[i] - attr = attrs[i] - (QName, name, type, readonly) = data - checkAttr(attr, QName % "NullableArray", name, type % "ArrayOrNull", readonly) - - iface = results[4] - harness.ok(isinstance(iface, WebIDL.IDLInterface), - "Should be an IDLInterface") - harness.check(iface.identifier.QName(), "::TestAttrArrayOfNullableTypes", "Interface has the right QName") - harness.check(iface.identifier.name, "TestAttrArrayOfNullableTypes", "Interface has the right name") - harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) - - attrs = iface.members - - for i in range(len(attrs)): - data = testData[i] - attr = attrs[i] - (QName, name, type, readonly) = data - checkAttr(attr, QName % "ArrayOfNullableTypes", name, type % "OrNullArray", readonly) - - iface = results[5] - harness.ok(isinstance(iface, WebIDL.IDLInterface), - "Should be an IDLInterface") - harness.check(iface.identifier.QName(), "::TestAttrNullableArrayOfNullableTypes", "Interface has the right QName") - harness.check(iface.identifier.name, "TestAttrNullableArrayOfNullableTypes", "Interface has the right name") - harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) - - attrs = iface.members - - for i in range(len(attrs)): - data = testData[i] - attr = attrs[i] - (QName, name, type, readonly) = data - checkAttr(attr, QName % "NullableArrayOfNullableTypes", name, type % "OrNullArrayOrNull", readonly) - parser = parser.reset() threw = False try: diff --git a/components/script/dom/bindings/codegen/parser/tests/test_bytestring.py b/components/script/dom/bindings/codegen/parser/tests/test_bytestring.py index d73455f8812..fa83e9e2d57 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_bytestring.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_bytestring.py @@ -13,7 +13,7 @@ def WebIDLTest(parser, harness): results = parser.finish(); harness.ok(True, "TestByteString interface parsed without error.") - + harness.check(len(results), 1, "Should be one production") harness.ok(isinstance(results[0], WebIDL.IDLInterface), "Should be an IDLInterface") @@ -54,10 +54,9 @@ def WebIDLTest(parser, harness): """) except WebIDL.WebIDLError: threw = True - harness.ok(threw, "Should have thrown a WebIDL error") + harness.ok(threw, "Should have thrown a WebIDL error for ByteString default in interface") - # Cannot have optional ByteStrings with default values - threw = False + # Can have optional ByteStrings with default values try: parser.parse(""" interface OptionalByteString { @@ -65,8 +64,36 @@ def WebIDLTest(parser, harness): }; """) results2 = parser.finish(); - except WebIDL.WebIDLError: - threw = True + except WebIDL.WebIDLError as e: + harness.ok(False, + "Should not have thrown a WebIDL error for ByteString " + "default in dictionary. " + str(e)) - harness.ok(threw, "Should have thrown a WebIDL error") + # Can have a default ByteString value in a dictionary + try: + parser.parse(""" + dictionary OptionalByteStringDict { + ByteString item = "some string"; + }; + """) + results3 = parser.finish(); + except WebIDL.WebIDLError as e: + harness.ok(False, + "Should not have thrown a WebIDL error for ByteString " + "default in dictionary. " + str(e)) + + # Don't allow control characters in ByteString literals + threw = False + try: + parser.parse(""" + dictionary OptionalByteStringDict2 { + ByteString item = "\x03"; + }; + """) + results4 = parser.finish() + except WebIDL.WebIDLError as e: + threw = True + harness.ok(threw, + "Should have thrown a WebIDL error for invalid ByteString " + "default in dictionary") diff --git a/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py b/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py index 866816f2e0c..d7780c1ffa1 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_distinguishability.py @@ -159,7 +159,7 @@ def WebIDLTest(parser, harness): "object", "Callback", "Callback2", "optional Dict", "optional Dict2", "sequence<long>", "sequence<short>", "MozMap<object>", "MozMap<Dict>", "MozMap<long>", - "long[]", "short[]", "Date", "Date?", "any", + "Date", "Date?", "any", "Promise<any>", "Promise<any>?", "USVString", "ArrayBuffer", "ArrayBufferView", "SharedArrayBuffer", "Uint8Array", "Uint16Array" ] @@ -187,7 +187,6 @@ def WebIDLTest(parser, harness): "Date?", "any", "Promise<any>?"] dates = [ "Date", "Date?" ] sequences = [ "sequence<long>", "sequence<short>" ] - arrays = [ "long[]", "short[]" ] nonUserObjects = nonObjects + interfaces + dates + sequences otherObjects = allBut(argTypes, nonUserObjects + ["object"]) notRelatedInterfaces = (nonObjects + ["UnrelatedInterface"] + @@ -229,14 +228,12 @@ def WebIDLTest(parser, harness): setDistinguishable("optional Dict", allBut(nonUserObjects, nullables)) setDistinguishable("optional Dict2", allBut(nonUserObjects, nullables)) setDistinguishable("sequence<long>", - allBut(argTypes, sequences + arrays + ["object"])) + allBut(argTypes, sequences + ["object"])) setDistinguishable("sequence<short>", - allBut(argTypes, sequences + arrays + ["object"])) + allBut(argTypes, sequences + ["object"])) setDistinguishable("MozMap<object>", nonUserObjects) setDistinguishable("MozMap<Dict>", nonUserObjects) setDistinguishable("MozMap<long>", nonUserObjects) - setDistinguishable("long[]", allBut(nonUserObjects, sequences)) - setDistinguishable("short[]", allBut(nonUserObjects, sequences)) setDistinguishable("Date", allBut(argTypes, dates + ["object"])) setDistinguishable("Date?", allBut(argTypes, dates + nullables + ["object"])) setDistinguishable("any", []) diff --git a/components/script/dom/bindings/codegen/parser/tests/test_method.py b/components/script/dom/bindings/codegen/parser/tests/test_method.py index f6f54c33ab6..cf7f1b40d76 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_method.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_method.py @@ -11,7 +11,6 @@ def WebIDLTest(parser, harness): boolean basicBooleanWithSimpleArgs(boolean arg1, byte arg2, unsigned long arg3); void optionalArg(optional byte? arg1, optional sequence<byte> arg2); void variadicArg(byte?... arg1); - void crazyTypes(sequence<long?[]>? arg1, boolean?[][]? arg2); object getObject(); void setObject(object arg1); void setAny(any arg1); @@ -28,7 +27,7 @@ def WebIDLTest(parser, harness): "Should be an IDLInterface") harness.check(iface.identifier.QName(), "::TestMethods", "Interface has the right QName") harness.check(iface.identifier.name, "TestMethods", "Interface has the right name") - harness.check(len(iface.members), 13, "Expect 13 members") + harness.check(len(iface.members), 12, "Expect 12 members") methods = iface.members @@ -98,22 +97,17 @@ def WebIDLTest(parser, harness): "variadicArg", [("Void", [("::TestMethods::variadicArg::arg1", "arg1", "ByteOrNull", True, True)])]) - checkMethod(methods[8], "::TestMethods::crazyTypes", - "crazyTypes", - [("Void", - [("::TestMethods::crazyTypes::arg1", "arg1", "LongOrNullArraySequenceOrNull", False, False), - ("::TestMethods::crazyTypes::arg2", "arg2", "BooleanOrNullArrayArrayOrNull", False, False)])]) - checkMethod(methods[9], "::TestMethods::getObject", + checkMethod(methods[8], "::TestMethods::getObject", "getObject", [("Object", [])]) - checkMethod(methods[10], "::TestMethods::setObject", + checkMethod(methods[9], "::TestMethods::setObject", "setObject", [("Void", [("::TestMethods::setObject::arg1", "arg1", "Object", False, False)])]) - checkMethod(methods[11], "::TestMethods::setAny", + checkMethod(methods[10], "::TestMethods::setAny", "setAny", [("Void", [("::TestMethods::setAny::arg1", "arg1", "Any", False, False)])]) - checkMethod(methods[12], "::TestMethods::doFloats", + checkMethod(methods[11], "::TestMethods::doFloats", "doFloats", [("Float", [("::TestMethods::doFloats::arg1", "arg1", "Float", False, False)])]) diff --git a/components/script/dom/bindings/codegen/parser/tests/test_nullable_equivalency.py b/components/script/dom/bindings/codegen/parser/tests/test_nullable_equivalency.py index 1f72b2c6e67..2b48b615dd4 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_nullable_equivalency.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_nullable_equivalency.py @@ -53,16 +53,6 @@ def WebIDLTest(parser, harness): attribute object a; attribute object? b; }; - - interface TestNullableEquivalency11 { - attribute double[] a; - attribute double[]? b; - }; - - interface TestNullableEquivalency12 { - attribute TestNullableEquivalency9[] a; - attribute TestNullableEquivalency9[]? b; - }; """) for decl in parser.finish(): diff --git a/components/script/dom/bindings/codegen/parser/tests/test_union.py b/components/script/dom/bindings/codegen/parser/tests/test_union.py index 36cacf3ccf4..9c4f2a56ab6 100644 --- a/components/script/dom/bindings/codegen/parser/tests/test_union.py +++ b/components/script/dom/bindings/codegen/parser/tests/test_union.py @@ -139,9 +139,6 @@ def WebIDLTest(parser, harness): void method${i}(${type} arg); ${type} returnMethod${i}(); attribute ${type} attr${i}; - void arrayMethod${i}(${type}[] arg); - ${type}[] arrayReturnMethod${i}(); - attribute ${type}[] arrayAttr${i}; void optionalMethod${i}(${type}? arg); """).substitute(i=i, type=type) interface += """ |