1 # -*- coding: UTF-8 -*-
6 def WebIDLTest(parser
, harness
):
9 interface TestByteString {
10 attribute ByteString bs;
11 attribute DOMString ds;
16 results
= parser
.finish()
18 harness
.ok(True, "TestByteString interface parsed without error.")
20 harness
.check(len(results
), 1, "Should be one production")
21 harness
.ok(isinstance(results
[0], WebIDL
.IDLInterface
), "Should be an IDLInterface")
24 iface
.identifier
.QName(), "::TestByteString", "Interface has the right QName"
27 iface
.identifier
.name
, "TestByteString", "Interface has the right name"
29 harness
.check(iface
.parent
, None, "Interface has no parent")
31 members
= iface
.members
32 harness
.check(len(members
), 2, "Should be two productions")
35 harness
.ok(isinstance(attr
, WebIDL
.IDLAttribute
), "Should be an IDLAttribute")
37 attr
.identifier
.QName(), "::TestByteString::bs", "Attr has correct QName"
39 harness
.check(attr
.identifier
.name
, "bs", "Attr has correct name")
40 harness
.check(str(attr
.type), "ByteString", "Attr type is the correct name")
41 harness
.ok(attr
.type.isByteString(), "Should be ByteString type")
42 harness
.ok(attr
.type.isString(), "Should be String collective type")
43 harness
.ok(not attr
.type.isDOMString(), "Should be not be DOMString type")
45 # now check we haven't broken DOMStrings in the process.
47 harness
.ok(isinstance(attr
, WebIDL
.IDLAttribute
), "Should be an IDLAttribute")
49 attr
.identifier
.QName(), "::TestByteString::ds", "Attr has correct QName"
51 harness
.check(attr
.identifier
.name
, "ds", "Attr has correct name")
52 harness
.check(str(attr
.type), "String", "Attr type is the correct name")
53 harness
.ok(attr
.type.isDOMString(), "Should be DOMString type")
54 harness
.ok(attr
.type.isString(), "Should be String collective type")
55 harness
.ok(not attr
.type.isByteString(), "Should be not be ByteString type")
57 # Cannot represent constant ByteString in IDL.
62 interface ConstByteString {
63 const ByteString foo = "hello"
67 except WebIDL
.WebIDLError
:
70 threw
, "Should have thrown a WebIDL error for ByteString default in interface"
73 # Can have optional ByteStrings with default values
77 interface OptionalByteString {
78 undefined passByteString(optional ByteString arg = "hello");
83 except WebIDL
.WebIDLError
as e
:
86 "Should not have thrown a WebIDL error for ByteString "
87 "default in dictionary. " + str(e
),
90 # Can have a default ByteString value in a dictionary
94 dictionary OptionalByteStringDict {
95 ByteString item = "some string";
100 except WebIDL
.WebIDLError
as e
:
103 "Should not have thrown a WebIDL error for ByteString "
104 "default in dictionary. " + str(e
),
107 # Don't allow control characters in ByteString literals
112 dictionary OptionalByteStringDict2 {
113 ByteString item = "\x03";
118 except WebIDL
.WebIDLError
:
123 "Should have thrown a WebIDL error for invalid ByteString "
124 "default in dictionary",