Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / bindings / parser / tests / test_nullable_equivalency.py
blob5790288ccb9d91b59ec12a313cd7e3aba91b3919
1 import WebIDL
4 def WebIDLTest(parser, harness):
5 parser.parse(
6 """
7 interface TestNullableEquivalency1 {
8 attribute long a;
9 attribute long? b;
12 interface TestNullableEquivalency2 {
13 attribute ArrayBuffer a;
14 attribute ArrayBuffer? b;
17 /* Can't have dictionary-valued attributes, so can't test that here */
19 enum TestNullableEquivalency4Enum {
20 "Foo",
21 "Bar"
24 interface TestNullableEquivalency4 {
25 attribute TestNullableEquivalency4Enum a;
26 attribute TestNullableEquivalency4Enum? b;
29 interface TestNullableEquivalency5 {
30 attribute TestNullableEquivalency4 a;
31 attribute TestNullableEquivalency4? b;
34 interface TestNullableEquivalency6 {
35 attribute boolean a;
36 attribute boolean? b;
39 interface TestNullableEquivalency7 {
40 attribute DOMString a;
41 attribute DOMString? b;
44 interface TestNullableEquivalency8 {
45 attribute float a;
46 attribute float? b;
49 interface TestNullableEquivalency9 {
50 attribute double a;
51 attribute double? b;
54 interface TestNullableEquivalency10 {
55 attribute object a;
56 attribute object? b;
58 """
61 for decl in parser.finish():
62 if decl.isInterface():
63 checkEquivalent(decl, harness)
66 def checkEquivalent(iface, harness):
67 type1 = iface.members[0].type
68 type2 = iface.members[1].type
70 harness.check(type1.nullable(), False, "attr1 should not be nullable")
71 harness.check(type2.nullable(), True, "attr2 should be nullable")
73 # We don't know about type1, but type2, the nullable type, definitely
74 # shouldn't be builtin.
75 harness.check(type2.builtin, False, "attr2 should not be builtin")
77 # Ensure that all attributes of type2 match those in type1, except for:
78 # - names on an ignore list,
79 # - names beginning with '_',
80 # - functions which throw when called with no args, and
81 # - class-level non-callables ("static variables").
83 # Yes, this is an ugly, fragile hack. But it finds bugs...
84 for attr in dir(type1):
85 if (
86 attr.startswith("_")
87 or attr
88 in [
89 "nullable",
90 "builtin",
91 "filename",
92 "location",
93 "inner",
94 "QName",
95 "getDeps",
96 "name",
97 "prettyName",
99 or (hasattr(type(type1), attr) and not callable(getattr(type1, attr)))
101 continue
103 a1 = getattr(type1, attr)
105 if callable(a1):
106 try:
107 v1 = a1()
108 except AssertionError:
109 # Various methods assert that they're called on objects of
110 # the right type, skip them if the assert fails.
111 continue
112 except TypeError:
113 # a1 requires positional arguments, so skip this attribute.
114 continue
116 try:
117 a2 = getattr(type2, attr)
118 except WebIDL.WebIDLError:
119 harness.ok(
120 False,
121 "Missing %s attribute on type %s in %s" % (attr, type2, iface),
123 continue
125 if not callable(a2):
126 harness.ok(
127 False,
128 "%s attribute on type %s in %s wasn't callable"
129 % (attr, type2, iface),
131 continue
133 v2 = a2()
134 harness.check(v2, v1, "%s method return value" % attr)
135 else:
136 try:
137 a2 = getattr(type2, attr)
138 except WebIDL.WebIDLError:
139 harness.ok(
140 False,
141 "Missing %s attribute on type %s in %s" % (attr, type2, iface),
143 continue
145 harness.check(a2, a1, "%s attribute should match" % attr)