test_builtins.py (1907B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser.parse( 6 """ 7 interface TestBuiltins { 8 attribute boolean b; 9 attribute byte s8; 10 attribute octet u8; 11 attribute short s16; 12 attribute unsigned short u16; 13 attribute long s32; 14 attribute unsigned long u32; 15 attribute long long s64; 16 attribute unsigned long long u64; 17 }; 18 """ 19 ) 20 21 results = parser.finish() 22 23 harness.ok(True, "TestBuiltins interface parsed without error.") 24 harness.check(len(results), 1, "Should be one production") 25 harness.ok(isinstance(results[0], WebIDL.IDLInterface), "Should be an IDLInterface") 26 iface = results[0] 27 harness.check( 28 iface.identifier.QName(), "::TestBuiltins", "Interface has the right QName" 29 ) 30 harness.check(iface.identifier.name, "TestBuiltins", "Interface has the right name") 31 harness.check(iface.parent, None, "Interface has no parent") 32 33 members = iface.members 34 harness.check(len(members), 9, "Should be one production") 35 36 names = ["b", "s8", "u8", "s16", "u16", "s32", "u32", "s64", "u64", "ts"] 37 types = [ 38 "Boolean", 39 "Byte", 40 "Octet", 41 "Short", 42 "UnsignedShort", 43 "Long", 44 "UnsignedLong", 45 "LongLong", 46 "UnsignedLongLong", 47 "UnsignedLongLong", 48 ] 49 for i in range(9): 50 attr = members[i] 51 harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute") 52 harness.check( 53 attr.identifier.QName(), 54 "::TestBuiltins::" + names[i], 55 "Attr has correct QName", 56 ) 57 harness.check(attr.identifier.name, names[i], "Attr has correct name") 58 harness.check(str(attr.type), types[i], "Attr type is the correct name") 59 harness.ok(attr.type.isPrimitive(), "Should be a primitive type")