dom/bindings/parser/tests/test_builtins.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bindings/parser/tests/test_builtins.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,41 @@
     1.4 +import WebIDL
     1.5 +
     1.6 +def WebIDLTest(parser, harness):
     1.7 +    parser.parse("""
     1.8 +        interface TestBuiltins {
     1.9 +          attribute boolean b;
    1.10 +          attribute byte s8;
    1.11 +          attribute octet u8;
    1.12 +          attribute short s16;
    1.13 +          attribute unsigned short u16;
    1.14 +          attribute long s32;
    1.15 +          attribute unsigned long u32;
    1.16 +          attribute long long s64;
    1.17 +          attribute unsigned long long u64;
    1.18 +          attribute DOMTimeStamp ts;
    1.19 +        };
    1.20 +    """)
    1.21 +
    1.22 +    results = parser.finish()
    1.23 +
    1.24 +    harness.ok(True, "TestBuiltins interface parsed without error.")
    1.25 +    harness.check(len(results), 1, "Should be one production")
    1.26 +    harness.ok(isinstance(results[0], WebIDL.IDLInterface),
    1.27 +               "Should be an IDLInterface")
    1.28 +    iface = results[0]
    1.29 +    harness.check(iface.identifier.QName(), "::TestBuiltins", "Interface has the right QName")
    1.30 +    harness.check(iface.identifier.name, "TestBuiltins", "Interface has the right name")
    1.31 +    harness.check(iface.parent, None, "Interface has no parent")
    1.32 +
    1.33 +    members = iface.members
    1.34 +    harness.check(len(members), 10, "Should be one production")
    1.35 +
    1.36 +    names = ["b", "s8", "u8", "s16", "u16", "s32", "u32", "s64", "u64", "ts"]
    1.37 +    types = ["Boolean", "Byte", "Octet", "Short", "UnsignedShort", "Long", "UnsignedLong", "LongLong", "UnsignedLongLong", "UnsignedLongLong"]
    1.38 +    for i in range(10):
    1.39 +        attr = members[i]
    1.40 +        harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
    1.41 +        harness.check(attr.identifier.QName(), "::TestBuiltins::" + names[i], "Attr has correct QName")
    1.42 +        harness.check(attr.identifier.name, names[i], "Attr has correct name")
    1.43 +        harness.check(str(attr.type), types[i], "Attr type is the correct name")
    1.44 +        harness.ok(attr.type.isPrimitive(), "Should be a primitive type")

mercurial