test_replaceable.py (2062B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import WebIDL 6 7 8 def should_throw(parser, harness, message, code): 9 parser = parser.reset() 10 threw = False 11 try: 12 parser.parse(code) 13 parser.finish() 14 except WebIDL.WebIDLError: 15 threw = True 16 17 harness.ok(threw, "Should have thrown: %s" % message) 18 19 20 def WebIDLTest(parser, harness): 21 # The [Replaceable] extended attribute MUST take no arguments. 22 should_throw( 23 parser, 24 harness, 25 "no arguments", 26 """ 27 interface I { 28 [Replaceable=X] readonly attribute long A; 29 }; 30 """, 31 ) 32 33 # An attribute with the [Replaceable] extended attribute MUST NOT also be 34 # declared with the [PutForwards] extended attribute. 35 should_throw( 36 parser, 37 harness, 38 "PutForwards", 39 """ 40 interface I { 41 [PutForwards=B, Replaceable] readonly attribute J A; 42 }; 43 interface J { 44 attribute long B; 45 }; 46 """, 47 ) 48 49 # The [Replaceable] extended attribute MUST NOT be used on an attribute 50 # that is not read only. 51 should_throw( 52 parser, 53 harness, 54 "writable attribute", 55 """ 56 interface I { 57 [Replaceable] attribute long A; 58 }; 59 """, 60 ) 61 62 # The [Replaceable] extended attribute MUST NOT be used on a static 63 # attribute. 64 should_throw( 65 parser, 66 harness, 67 "static attribute", 68 """ 69 interface I { 70 [Replaceable] static readonly attribute long A; 71 }; 72 """, 73 ) 74 75 # The [Replaceable] extended attribute MUST NOT be used on an attribute 76 # declared on a callback interface. 77 should_throw( 78 parser, 79 harness, 80 "callback interface", 81 """ 82 callback interface I { 83 [Replaceable] readonly attribute long A; 84 }; 85 """, 86 )