|
1 # -*- coding: UTF-8 -*- |
|
2 |
|
3 import WebIDL |
|
4 |
|
5 def WebIDLTest(parser, harness): |
|
6 parser.parse(""" |
|
7 interface TestByteString { |
|
8 attribute ByteString bs; |
|
9 attribute DOMString ds; |
|
10 }; |
|
11 """) |
|
12 |
|
13 results = parser.finish(); |
|
14 |
|
15 harness.ok(True, "TestByteString interface parsed without error.") |
|
16 |
|
17 harness.check(len(results), 1, "Should be one production") |
|
18 harness.ok(isinstance(results[0], WebIDL.IDLInterface), |
|
19 "Should be an IDLInterface") |
|
20 iface = results[0] |
|
21 harness.check(iface.identifier.QName(), "::TestByteString", "Interface has the right QName") |
|
22 harness.check(iface.identifier.name, "TestByteString", "Interface has the right name") |
|
23 harness.check(iface.parent, None, "Interface has no parent") |
|
24 |
|
25 members = iface.members |
|
26 harness.check(len(members), 2, "Should be two productions") |
|
27 |
|
28 attr = members[0] |
|
29 harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute") |
|
30 harness.check(attr.identifier.QName(), "::TestByteString::bs", "Attr has correct QName") |
|
31 harness.check(attr.identifier.name, "bs", "Attr has correct name") |
|
32 harness.check(str(attr.type), "ByteString", "Attr type is the correct name") |
|
33 harness.ok(attr.type.isByteString(), "Should be ByteString type") |
|
34 harness.ok(attr.type.isString(), "Should be String collective type") |
|
35 harness.ok(not attr.type.isDOMString(), "Should be not be DOMString type") |
|
36 |
|
37 # now check we haven't broken DOMStrings in the process. |
|
38 attr = members[1] |
|
39 harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute") |
|
40 harness.check(attr.identifier.QName(), "::TestByteString::ds", "Attr has correct QName") |
|
41 harness.check(attr.identifier.name, "ds", "Attr has correct name") |
|
42 harness.check(str(attr.type), "String", "Attr type is the correct name") |
|
43 harness.ok(attr.type.isDOMString(), "Should be DOMString type") |
|
44 harness.ok(attr.type.isString(), "Should be String collective type") |
|
45 harness.ok(not attr.type.isByteString(), "Should be not be ByteString type") |
|
46 |
|
47 # Cannot represent constant ByteString in IDL. |
|
48 threw = False |
|
49 try: |
|
50 parser.parse(""" |
|
51 interface ConstByteString { |
|
52 const ByteString foo = "hello" |
|
53 }; |
|
54 """) |
|
55 except WebIDL.WebIDLError: |
|
56 threw = True |
|
57 harness.ok(threw, "Should have thrown a WebIDL error") |
|
58 |
|
59 # Cannot have optional ByteStrings with default values |
|
60 threw = False |
|
61 try: |
|
62 parser.parse(""" |
|
63 interface OptionalByteString { |
|
64 void passByteString(optional ByteString arg = "hello"); |
|
65 }; |
|
66 """) |
|
67 results2 = parser.finish(); |
|
68 except WebIDL.WebIDLError: |
|
69 threw = True |
|
70 |
|
71 harness.ok(threw, "Should have thrown a WebIDL error") |
|
72 |