test_callback.py (1603B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser.parse( 6 """ 7 interface TestCallback { 8 attribute CallbackType? listener; 9 }; 10 11 callback CallbackType = boolean (unsigned long arg); 12 """ 13 ) 14 15 results = parser.finish() 16 17 harness.ok(True, "TestCallback interface parsed without error.") 18 harness.check(len(results), 2, "Should be two productions.") 19 iface = results[0] 20 harness.ok(isinstance(iface, WebIDL.IDLInterface), "Should be an IDLInterface") 21 harness.check( 22 iface.identifier.QName(), "::TestCallback", "Interface has the right QName" 23 ) 24 harness.check(iface.identifier.name, "TestCallback", "Interface has the right name") 25 harness.check(len(iface.members), 1, "Expect %s members" % 1) 26 27 attr = iface.members[0] 28 harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute") 29 harness.ok(attr.isAttr(), "Should be an attribute") 30 harness.ok(not attr.isMethod(), "Attr is not an method") 31 harness.ok(not attr.isConst(), "Attr is not a const") 32 harness.check( 33 attr.identifier.QName(), "::TestCallback::listener", "Attr has the right QName" 34 ) 35 harness.check(attr.identifier.name, "listener", "Attr has the right name") 36 t = attr.type 37 harness.ok(not isinstance(t, WebIDL.IDLWrapperType), "Attr has the right type") 38 harness.ok(isinstance(t, WebIDL.IDLNullableType), "Attr has the right type") 39 harness.ok(t.isCallback(), "Attr has the right type") 40 41 callback = results[1] 42 harness.ok(not callback.isConstructor(), "callback is not constructor")