1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/parser/tests/test_const.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +import WebIDL 1.5 + 1.6 +def WebIDLTest(parser, harness): 1.7 + parser.parse(""" 1.8 + interface TestConsts { 1.9 + const byte zero = 0; 1.10 + const byte b = -1; 1.11 + const octet o = 2; 1.12 + const short s = -3; 1.13 + const unsigned short us = 0x4; 1.14 + const long l = -0X5; 1.15 + const unsigned long ul = 6; 1.16 + const unsigned long long ull = 7; 1.17 + const long long ll = -010; 1.18 + const boolean t = true; 1.19 + const boolean f = false; 1.20 + const boolean? n = null; 1.21 + const boolean? nt = true; 1.22 + const boolean? nf = false; 1.23 + }; 1.24 + """) 1.25 + 1.26 + results = parser.finish() 1.27 + 1.28 + harness.ok(True, "TestConsts interface parsed without error.") 1.29 + harness.check(len(results), 1, "Should be one production.") 1.30 + iface = results[0] 1.31 + harness.ok(isinstance(iface, WebIDL.IDLInterface), 1.32 + "Should be an IDLInterface") 1.33 + harness.check(iface.identifier.QName(), "::TestConsts", "Interface has the right QName") 1.34 + harness.check(iface.identifier.name, "TestConsts", "Interface has the right name") 1.35 + harness.check(len(iface.members), 14, "Expect 14 members") 1.36 + 1.37 + consts = iface.members 1.38 + 1.39 + def checkConst(const, QName, name, type, value): 1.40 + harness.ok(isinstance(const, WebIDL.IDLConst), 1.41 + "Should be an IDLConst") 1.42 + harness.ok(const.isConst(), "Const is a const") 1.43 + harness.ok(not const.isAttr(), "Const is not an attr") 1.44 + harness.ok(not const.isMethod(), "Const is not a method") 1.45 + harness.check(const.identifier.QName(), QName, "Const has the right QName") 1.46 + harness.check(const.identifier.name, name, "Const has the right name") 1.47 + harness.check(str(const.type), type, "Const has the right type") 1.48 + harness.ok(const.type.isPrimitive(), "All consts should be primitive") 1.49 + harness.check(str(const.value.type), str(const.type), 1.50 + "Const's value has the same type as the type") 1.51 + harness.check(const.value.value, value, "Const value has the right value.") 1.52 + 1.53 + checkConst(consts[0], "::TestConsts::zero", "zero", "Byte", 0) 1.54 + checkConst(consts[1], "::TestConsts::b", "b", "Byte", -1) 1.55 + checkConst(consts[2], "::TestConsts::o", "o", "Octet", 2) 1.56 + checkConst(consts[3], "::TestConsts::s", "s", "Short", -3) 1.57 + checkConst(consts[4], "::TestConsts::us", "us", "UnsignedShort", 4) 1.58 + checkConst(consts[5], "::TestConsts::l", "l", "Long", -5) 1.59 + checkConst(consts[6], "::TestConsts::ul", "ul", "UnsignedLong", 6) 1.60 + checkConst(consts[7], "::TestConsts::ull", "ull", "UnsignedLongLong", 7) 1.61 + checkConst(consts[8], "::TestConsts::ll", "ll", "LongLong", -8) 1.62 + checkConst(consts[9], "::TestConsts::t", "t", "Boolean", True) 1.63 + checkConst(consts[10], "::TestConsts::f", "f", "Boolean", False) 1.64 + checkConst(consts[11], "::TestConsts::n", "n", "BooleanOrNull", None) 1.65 + checkConst(consts[12], "::TestConsts::nt", "nt", "BooleanOrNull", True) 1.66 + checkConst(consts[13], "::TestConsts::nf", "nf", "BooleanOrNull", False) 1.67 +