4 ("::TestConsts::zero", "zero", "Byte", 0),
5 ("::TestConsts::b", "b", "Byte", -1),
6 ("::TestConsts::o", "o", "Octet", 2),
7 ("::TestConsts::s", "s", "Short", -3),
8 ("::TestConsts::us", "us", "UnsignedShort", 4),
9 ("::TestConsts::l", "l", "Long", -5),
10 ("::TestConsts::ul", "ul", "UnsignedLong", 6),
11 ("::TestConsts::ull", "ull", "UnsignedLongLong", 7),
12 ("::TestConsts::ll", "ll", "LongLong", -8),
13 ("::TestConsts::t", "t", "Boolean", True),
14 ("::TestConsts::f", "f", "Boolean", False),
15 ("::TestConsts::fl", "fl", "Float", 0.2),
16 ("::TestConsts::db", "db", "Double", 0.2),
17 ("::TestConsts::ufl", "ufl", "UnrestrictedFloat", 0.2),
18 ("::TestConsts::udb", "udb", "UnrestrictedDouble", 0.2),
19 ("::TestConsts::fli", "fli", "Float", 2),
20 ("::TestConsts::dbi", "dbi", "Double", 2),
21 ("::TestConsts::ufli", "ufli", "UnrestrictedFloat", 2),
22 ("::TestConsts::udbi", "udbi", "UnrestrictedDouble", 2),
26 def WebIDLTest(parser
, harness
):
29 interface TestConsts {
34 const unsigned short us = 0x4;
36 const unsigned long ul = 6;
37 const unsigned long long ull = 7;
38 const long long ll = -010;
39 const boolean t = true;
40 const boolean f = false;
42 const double db = 0.2;
43 const unrestricted float ufl = 0.2;
44 const unrestricted double udb = 0.2;
47 const unrestricted float ufli = 2;
48 const unrestricted double udbi = 2;
53 results
= parser
.finish()
55 harness
.ok(True, "TestConsts interface parsed without error.")
56 harness
.check(len(results
), 1, "Should be one production.")
58 harness
.ok(isinstance(iface
, WebIDL
.IDLInterface
), "Should be an IDLInterface")
60 iface
.identifier
.QName(), "::TestConsts", "Interface has the right QName"
62 harness
.check(iface
.identifier
.name
, "TestConsts", "Interface has the right name")
64 len(iface
.members
), len(expected
), "Expect %s members" % len(expected
)
67 for const
, (QName
, name
, type, value
) in zip(iface
.members
, expected
):
68 harness
.ok(isinstance(const
, WebIDL
.IDLConst
), "Should be an IDLConst")
69 harness
.ok(const
.isConst(), "Const is a const")
70 harness
.ok(not const
.isAttr(), "Const is not an attr")
71 harness
.ok(not const
.isMethod(), "Const is not a method")
72 harness
.check(const
.identifier
.QName(), QName
, "Const has the right QName")
73 harness
.check(const
.identifier
.name
, name
, "Const has the right name")
74 harness
.check(str(const
.type), type, "Const has the right type")
75 harness
.ok(const
.type.isPrimitive(), "All consts should be primitive")
77 str(const
.value
.type),
79 "Const's value has the same type as the type",
81 harness
.check(const
.value
.value
, value
, "Const value has the right value.")
83 parser
= parser
.reset()
88 interface TestConsts {
89 const boolean? zero = 0;
94 except WebIDL
.WebIDLError
:
96 harness
.ok(threw
, "Nullable types are not allowed for consts.")