aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/parser/tests/test_bytestring.py
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/codegen/parser/tests/test_bytestring.py')
-rw-r--r--components/script/dom/bindings/codegen/parser/tests/test_bytestring.py86
1 files changed, 56 insertions, 30 deletions
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 51289f5db6e..a6f9f6ab9cb 100644
--- a/components/script/dom/bindings/codegen/parser/tests/test_bytestring.py
+++ b/components/script/dom/bindings/codegen/parser/tests/test_bytestring.py
@@ -2,24 +2,30 @@
import WebIDL
+
def WebIDLTest(parser, harness):
- parser.parse("""
+ parser.parse(
+ """
interface TestByteString {
attribute ByteString bs;
attribute DOMString ds;
};
- """)
+ """
+ )
- results = parser.finish();
+ 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")
+ harness.ok(isinstance(results[0], WebIDL.IDLInterface), "Should be an IDLInterface")
iface = results[0]
- harness.check(iface.identifier.QName(), "::TestByteString", "Interface has the right QName")
- harness.check(iface.identifier.name, "TestByteString", "Interface has the right name")
+ harness.check(
+ iface.identifier.QName(), "::TestByteString", "Interface has the right QName"
+ )
+ harness.check(
+ iface.identifier.name, "TestByteString", "Interface has the right name"
+ )
harness.check(iface.parent, None, "Interface has no parent")
members = iface.members
@@ -27,7 +33,9 @@ def WebIDLTest(parser, harness):
attr = members[0]
harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
- harness.check(attr.identifier.QName(), "::TestByteString::bs", "Attr has correct QName")
+ harness.check(
+ attr.identifier.QName(), "::TestByteString::bs", "Attr has correct QName"
+ )
harness.check(attr.identifier.name, "bs", "Attr has correct name")
harness.check(str(attr.type), "ByteString", "Attr type is the correct name")
harness.ok(attr.type.isByteString(), "Should be ByteString type")
@@ -37,7 +45,9 @@ def WebIDLTest(parser, harness):
# now check we haven't broken DOMStrings in the process.
attr = members[1]
harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
- harness.check(attr.identifier.QName(), "::TestByteString::ds", "Attr has correct QName")
+ harness.check(
+ attr.identifier.QName(), "::TestByteString::ds", "Attr has correct QName"
+ )
harness.check(attr.identifier.name, "ds", "Attr has correct name")
harness.check(str(attr.type), "String", "Attr type is the correct name")
harness.ok(attr.type.isDOMString(), "Should be DOMString type")
@@ -47,53 +57,69 @@ def WebIDLTest(parser, harness):
# Cannot represent constant ByteString in IDL.
threw = False
try:
- parser.parse("""
+ parser.parse(
+ """
interface ConstByteString {
const ByteString foo = "hello"
};
- """)
+ """
+ )
except WebIDL.WebIDLError:
threw = True
- harness.ok(threw, "Should have thrown a WebIDL error for ByteString default in interface")
+ harness.ok(
+ threw, "Should have thrown a WebIDL error for ByteString default in interface"
+ )
# Can have optional ByteStrings with default values
try:
- parser.parse("""
+ parser.parse(
+ """
interface OptionalByteString {
undefined passByteString(optional ByteString arg = "hello");
- };
- """)
- results2 = parser.finish();
+ };
+ """
+ )
+ results2 = parser.finish()
except WebIDL.WebIDLError as e:
- harness.ok(False,
- "Should not have thrown a WebIDL error for ByteString "
- "default in dictionary. " + str(e))
+ harness.ok(
+ False,
+ "Should not have thrown a WebIDL error for ByteString "
+ "default in dictionary. " + str(e),
+ )
# Can have a default ByteString value in a dictionary
try:
- parser.parse("""
+ parser.parse(
+ """
dictionary OptionalByteStringDict {
ByteString item = "some string";
};
- """)
- results3 = parser.finish();
+ """
+ )
+ 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))
+ 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("""
+ 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")
+ harness.ok(
+ threw,
+ "Should have thrown a WebIDL error for invalid ByteString "
+ "default in dictionary",
+ )