dom/bindings/parser/tests/test_bytestring.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bindings/parser/tests/test_bytestring.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +# -*- coding: UTF-8 -*-
     1.5 +
     1.6 +import WebIDL
     1.7 +
     1.8 +def WebIDLTest(parser, harness):
     1.9 +    parser.parse("""
    1.10 +        interface TestByteString {
    1.11 +          attribute ByteString bs;
    1.12 +          attribute DOMString ds;
    1.13 +          };
    1.14 +    """)
    1.15 +
    1.16 +    results = parser.finish();
    1.17 +
    1.18 +    harness.ok(True, "TestByteString interface parsed without error.")
    1.19 +    
    1.20 +    harness.check(len(results), 1, "Should be one production")
    1.21 +    harness.ok(isinstance(results[0], WebIDL.IDLInterface),
    1.22 +               "Should be an IDLInterface")
    1.23 +    iface = results[0]
    1.24 +    harness.check(iface.identifier.QName(), "::TestByteString", "Interface has the right QName")
    1.25 +    harness.check(iface.identifier.name, "TestByteString", "Interface has the right name")
    1.26 +    harness.check(iface.parent, None, "Interface has no parent")
    1.27 +
    1.28 +    members = iface.members
    1.29 +    harness.check(len(members), 2, "Should be two productions")
    1.30 +
    1.31 +    attr = members[0]
    1.32 +    harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
    1.33 +    harness.check(attr.identifier.QName(), "::TestByteString::bs", "Attr has correct QName")
    1.34 +    harness.check(attr.identifier.name, "bs", "Attr has correct name")
    1.35 +    harness.check(str(attr.type), "ByteString", "Attr type is the correct name")
    1.36 +    harness.ok(attr.type.isByteString(), "Should be ByteString type")
    1.37 +    harness.ok(attr.type.isString(), "Should be String collective type")
    1.38 +    harness.ok(not attr.type.isDOMString(), "Should be not be DOMString type")
    1.39 +
    1.40 +    # now check we haven't broken DOMStrings in the process.
    1.41 +    attr = members[1]
    1.42 +    harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
    1.43 +    harness.check(attr.identifier.QName(), "::TestByteString::ds", "Attr has correct QName")
    1.44 +    harness.check(attr.identifier.name, "ds", "Attr has correct name")
    1.45 +    harness.check(str(attr.type), "String", "Attr type is the correct name")
    1.46 +    harness.ok(attr.type.isDOMString(), "Should be DOMString type")
    1.47 +    harness.ok(attr.type.isString(), "Should be String collective type")
    1.48 +    harness.ok(not attr.type.isByteString(), "Should be not be ByteString type")
    1.49 +
    1.50 +    # Cannot represent constant ByteString in IDL.
    1.51 +    threw = False
    1.52 +    try:
    1.53 +        parser.parse("""
    1.54 +            interface ConstByteString {
    1.55 +              const ByteString foo = "hello"
    1.56 +              };
    1.57 +        """)
    1.58 +    except WebIDL.WebIDLError:
    1.59 +        threw = True
    1.60 +    harness.ok(threw, "Should have thrown a WebIDL error")
    1.61 +
    1.62 +    # Cannot have optional ByteStrings with default values
    1.63 +    threw = False
    1.64 +    try:
    1.65 +        parser.parse("""
    1.66 +            interface OptionalByteString {
    1.67 +              void passByteString(optional ByteString arg = "hello");
    1.68 +              };
    1.69 +        """)
    1.70 +        results2 = parser.finish();
    1.71 +    except WebIDL.WebIDLError:
    1.72 +        threw = True
    1.73 +
    1.74 +    harness.ok(threw, "Should have thrown a WebIDL error")
    1.75 +

mercurial