test_record.py (1673B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser.parse( 6 """ 7 dictionary Dict {}; 8 interface RecordArg { 9 undefined foo(record<DOMString, Dict> arg); 10 }; 11 """ 12 ) 13 14 results = parser.finish() 15 16 harness.check(len(results), 2, "Should know about two things") 17 harness.ok( 18 isinstance(results[1], WebIDL.IDLInterface), "Should have an interface here" 19 ) 20 members = results[1].members 21 harness.check(len(members), 1, "Should have one member") 22 harness.ok(members[0].isMethod(), "Should have method") 23 signature = members[0].signatures()[0] 24 args = signature[1] 25 harness.check(len(args), 1, "Should have one arg") 26 harness.ok(args[0].type.isRecord(), "Should have a record type here") 27 harness.ok(args[0].type.inner.isDictionary(), "Should have a dictionary inner type") 28 29 parser = parser.reset() 30 threw = False 31 try: 32 parser.parse( 33 """ 34 interface RecordUndefinedArg { 35 undefined foo(record<DOMString, undefined> arg); 36 }; 37 """ 38 ) 39 40 results = parser.finish() 41 except WebIDL.WebIDLError: 42 threw = True 43 harness.ok( 44 threw, "Should have thrown because record can't have undefined as value type." 45 ) 46 47 parser = parser.reset() 48 threw = False 49 try: 50 parser.parse( 51 """ 52 dictionary Dict { 53 record<DOMString, Dict> val; 54 }; 55 """ 56 ) 57 58 results = parser.finish() 59 except WebIDL.WebIDLError: 60 threw = True 61 harness.ok(threw, "Should have thrown on dictionary containing itself via record.")