|
1 import WebIDL |
|
2 |
|
3 def WebIDLTest(parser, harness): |
|
4 parser.parse(""" |
|
5 interface TestConsts { |
|
6 const byte zero = 0; |
|
7 const byte b = -1; |
|
8 const octet o = 2; |
|
9 const short s = -3; |
|
10 const unsigned short us = 0x4; |
|
11 const long l = -0X5; |
|
12 const unsigned long ul = 6; |
|
13 const unsigned long long ull = 7; |
|
14 const long long ll = -010; |
|
15 const boolean t = true; |
|
16 const boolean f = false; |
|
17 const boolean? n = null; |
|
18 const boolean? nt = true; |
|
19 const boolean? nf = false; |
|
20 }; |
|
21 """) |
|
22 |
|
23 results = parser.finish() |
|
24 |
|
25 harness.ok(True, "TestConsts interface parsed without error.") |
|
26 harness.check(len(results), 1, "Should be one production.") |
|
27 iface = results[0] |
|
28 harness.ok(isinstance(iface, WebIDL.IDLInterface), |
|
29 "Should be an IDLInterface") |
|
30 harness.check(iface.identifier.QName(), "::TestConsts", "Interface has the right QName") |
|
31 harness.check(iface.identifier.name, "TestConsts", "Interface has the right name") |
|
32 harness.check(len(iface.members), 14, "Expect 14 members") |
|
33 |
|
34 consts = iface.members |
|
35 |
|
36 def checkConst(const, QName, name, type, value): |
|
37 harness.ok(isinstance(const, WebIDL.IDLConst), |
|
38 "Should be an IDLConst") |
|
39 harness.ok(const.isConst(), "Const is a const") |
|
40 harness.ok(not const.isAttr(), "Const is not an attr") |
|
41 harness.ok(not const.isMethod(), "Const is not a method") |
|
42 harness.check(const.identifier.QName(), QName, "Const has the right QName") |
|
43 harness.check(const.identifier.name, name, "Const has the right name") |
|
44 harness.check(str(const.type), type, "Const has the right type") |
|
45 harness.ok(const.type.isPrimitive(), "All consts should be primitive") |
|
46 harness.check(str(const.value.type), str(const.type), |
|
47 "Const's value has the same type as the type") |
|
48 harness.check(const.value.value, value, "Const value has the right value.") |
|
49 |
|
50 checkConst(consts[0], "::TestConsts::zero", "zero", "Byte", 0) |
|
51 checkConst(consts[1], "::TestConsts::b", "b", "Byte", -1) |
|
52 checkConst(consts[2], "::TestConsts::o", "o", "Octet", 2) |
|
53 checkConst(consts[3], "::TestConsts::s", "s", "Short", -3) |
|
54 checkConst(consts[4], "::TestConsts::us", "us", "UnsignedShort", 4) |
|
55 checkConst(consts[5], "::TestConsts::l", "l", "Long", -5) |
|
56 checkConst(consts[6], "::TestConsts::ul", "ul", "UnsignedLong", 6) |
|
57 checkConst(consts[7], "::TestConsts::ull", "ull", "UnsignedLongLong", 7) |
|
58 checkConst(consts[8], "::TestConsts::ll", "ll", "LongLong", -8) |
|
59 checkConst(consts[9], "::TestConsts::t", "t", "Boolean", True) |
|
60 checkConst(consts[10], "::TestConsts::f", "f", "Boolean", False) |
|
61 checkConst(consts[11], "::TestConsts::n", "n", "BooleanOrNull", None) |
|
62 checkConst(consts[12], "::TestConsts::nt", "nt", "BooleanOrNull", True) |
|
63 checkConst(consts[13], "::TestConsts::nf", "nf", "BooleanOrNull", False) |
|
64 |