michael@0: import WebIDL michael@0: michael@0: def WebIDLTest(parser, harness): michael@0: parser.parse(""" michael@0: interface TestConsts { michael@0: const byte zero = 0; michael@0: const byte b = -1; michael@0: const octet o = 2; michael@0: const short s = -3; michael@0: const unsigned short us = 0x4; michael@0: const long l = -0X5; michael@0: const unsigned long ul = 6; michael@0: const unsigned long long ull = 7; michael@0: const long long ll = -010; michael@0: const boolean t = true; michael@0: const boolean f = false; michael@0: const boolean? n = null; michael@0: const boolean? nt = true; michael@0: const boolean? nf = false; michael@0: }; michael@0: """) michael@0: michael@0: results = parser.finish() michael@0: michael@0: harness.ok(True, "TestConsts interface parsed without error.") michael@0: harness.check(len(results), 1, "Should be one production.") michael@0: iface = results[0] michael@0: harness.ok(isinstance(iface, WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.check(iface.identifier.QName(), "::TestConsts", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestConsts", "Interface has the right name") michael@0: harness.check(len(iface.members), 14, "Expect 14 members") michael@0: michael@0: consts = iface.members michael@0: michael@0: def checkConst(const, QName, name, type, value): michael@0: harness.ok(isinstance(const, WebIDL.IDLConst), michael@0: "Should be an IDLConst") michael@0: harness.ok(const.isConst(), "Const is a const") michael@0: harness.ok(not const.isAttr(), "Const is not an attr") michael@0: harness.ok(not const.isMethod(), "Const is not a method") michael@0: harness.check(const.identifier.QName(), QName, "Const has the right QName") michael@0: harness.check(const.identifier.name, name, "Const has the right name") michael@0: harness.check(str(const.type), type, "Const has the right type") michael@0: harness.ok(const.type.isPrimitive(), "All consts should be primitive") michael@0: harness.check(str(const.value.type), str(const.type), michael@0: "Const's value has the same type as the type") michael@0: harness.check(const.value.value, value, "Const value has the right value.") michael@0: michael@0: checkConst(consts[0], "::TestConsts::zero", "zero", "Byte", 0) michael@0: checkConst(consts[1], "::TestConsts::b", "b", "Byte", -1) michael@0: checkConst(consts[2], "::TestConsts::o", "o", "Octet", 2) michael@0: checkConst(consts[3], "::TestConsts::s", "s", "Short", -3) michael@0: checkConst(consts[4], "::TestConsts::us", "us", "UnsignedShort", 4) michael@0: checkConst(consts[5], "::TestConsts::l", "l", "Long", -5) michael@0: checkConst(consts[6], "::TestConsts::ul", "ul", "UnsignedLong", 6) michael@0: checkConst(consts[7], "::TestConsts::ull", "ull", "UnsignedLongLong", 7) michael@0: checkConst(consts[8], "::TestConsts::ll", "ll", "LongLong", -8) michael@0: checkConst(consts[9], "::TestConsts::t", "t", "Boolean", True) michael@0: checkConst(consts[10], "::TestConsts::f", "f", "Boolean", False) michael@0: checkConst(consts[11], "::TestConsts::n", "n", "BooleanOrNull", None) michael@0: checkConst(consts[12], "::TestConsts::nt", "nt", "BooleanOrNull", True) michael@0: checkConst(consts[13], "::TestConsts::nf", "nf", "BooleanOrNull", False) michael@0: