michael@0: # -*- coding: UTF-8 -*- michael@0: michael@0: import WebIDL michael@0: michael@0: def WebIDLTest(parser, harness): michael@0: parser.parse(""" michael@0: interface TestByteString { michael@0: attribute ByteString bs; michael@0: attribute DOMString ds; michael@0: }; michael@0: """) michael@0: michael@0: results = parser.finish(); michael@0: michael@0: harness.ok(True, "TestByteString interface parsed without error.") michael@0: michael@0: harness.check(len(results), 1, "Should be one production") michael@0: harness.ok(isinstance(results[0], WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: iface = results[0] michael@0: harness.check(iface.identifier.QName(), "::TestByteString", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestByteString", "Interface has the right name") michael@0: harness.check(iface.parent, None, "Interface has no parent") michael@0: michael@0: members = iface.members michael@0: harness.check(len(members), 2, "Should be two productions") michael@0: michael@0: attr = members[0] michael@0: harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute") michael@0: harness.check(attr.identifier.QName(), "::TestByteString::bs", "Attr has correct QName") michael@0: harness.check(attr.identifier.name, "bs", "Attr has correct name") michael@0: harness.check(str(attr.type), "ByteString", "Attr type is the correct name") michael@0: harness.ok(attr.type.isByteString(), "Should be ByteString type") michael@0: harness.ok(attr.type.isString(), "Should be String collective type") michael@0: harness.ok(not attr.type.isDOMString(), "Should be not be DOMString type") michael@0: michael@0: # now check we haven't broken DOMStrings in the process. michael@0: attr = members[1] michael@0: harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute") michael@0: harness.check(attr.identifier.QName(), "::TestByteString::ds", "Attr has correct QName") michael@0: harness.check(attr.identifier.name, "ds", "Attr has correct name") michael@0: harness.check(str(attr.type), "String", "Attr type is the correct name") michael@0: harness.ok(attr.type.isDOMString(), "Should be DOMString type") michael@0: harness.ok(attr.type.isString(), "Should be String collective type") michael@0: harness.ok(not attr.type.isByteString(), "Should be not be ByteString type") michael@0: michael@0: # Cannot represent constant ByteString in IDL. michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface ConstByteString { michael@0: const ByteString foo = "hello" michael@0: }; michael@0: """) michael@0: except WebIDL.WebIDLError: michael@0: threw = True michael@0: harness.ok(threw, "Should have thrown a WebIDL error") michael@0: michael@0: # Cannot have optional ByteStrings with default values michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface OptionalByteString { michael@0: void passByteString(optional ByteString arg = "hello"); michael@0: }; michael@0: """) michael@0: results2 = parser.finish(); michael@0: except WebIDL.WebIDLError: michael@0: threw = True michael@0: michael@0: harness.ok(threw, "Should have thrown a WebIDL error") michael@0: