1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
def WebIDLTest(parser, harness):
# Test dictionary as inner type
harness.should_throw(
parser,
"""
dictionary A {
boolean member;
};
interface B {
attribute ObservableArray<A> foo;
};
""",
"use dictionary as inner type",
)
# Test sequence as inner type
harness.should_throw(
parser,
"""
interface A {
attribute ObservableArray<sequence<boolean>> foo;
};
""",
"use sequence as inner type",
)
# Test sequence<dictionary> as inner type
harness.should_throw(
parser,
"""
dictionary A {
boolean member;
};
interface B {
attribute ObservableArray<sequence<A>> foo;
};
""",
"use sequence<dictionary> as inner type",
)
# Test record as inner type
harness.should_throw(
parser,
"""
interface A {
attribute ObservableArray<record<DOMString, boolean>> foo;
};
""",
"use record as inner type",
)
# Test record<dictionary> as inner type
harness.should_throw(
parser,
"""
dictionary A {
boolean member;
};
interface B {
attribute ObservableArray<record<DOMString, A>> foo;
};
""",
"use record<dictionary> as inner type",
)
# Test observable array as inner type
harness.should_throw(
parser,
"""
interface A {
attribute ObservableArray<ObservableArray<boolean>> foo;
};
""",
"use ObservableArray as inner type",
)
# Test nullable attribute
harness.should_throw(
parser,
"""
interface A {
attribute ObservableArray<boolean>? foo;
};
""",
"nullable",
)
# Test sequence
harness.should_throw(
parser,
"""
interface A {
undefined foo(sequence<ObservableArray<boolean>> foo);
};
""",
"used in sequence",
)
# Test record
harness.should_throw(
parser,
"""
interface A {
undefined foo(record<DOMString, ObservableArray<boolean>> foo);
};
""",
"used in record",
)
# Test promise
harness.should_throw(
parser,
"""
interface A {
Promise<ObservableArray<boolean>> foo();
};
""",
"used in promise",
)
# Test union
harness.should_throw(
parser,
"""
interface A {
attribute (DOMString or ObservableArray<boolean>>) foo;
};
""",
"used in union",
)
# Test dictionary member
harness.should_throw(
parser,
"""
dictionary A {
ObservableArray<boolean> foo;
};
""",
"used on dictionary member type",
)
# Test argument
harness.should_throw(
parser,
"""
interface A {
undefined foo(ObservableArray<boolean> foo);
};
""",
"used on argument",
)
# Test static attribute
harness.should_throw(
parser,
"""
interface A {
static attribute ObservableArray<boolean> foo;
};
""",
"used on static attribute type",
)
# Test iterable
harness.should_throw(
parser,
"""
interface A {
iterable<ObservableArray<boolean>>;
};
""",
"used in iterable",
)
# Test maplike
harness.should_throw(
parser,
"""
interface A {
maplike<long, ObservableArray<boolean>>;
};
""",
"used in maplike",
)
# Test setlike
harness.should_throw(
parser,
"""
interface A {
setlike<ObservableArray<boolean>>;
};
""",
"used in setlike",
)
# Test JS implemented interface
harness.should_throw(
parser,
"""
[JSImplementation="@mozilla.org/dom/test-interface-js;1"]
interface A {
readonly attribute ObservableArray<boolean> foo;
};
""",
"used in JS implemented interface",
)
# Test namespace
harness.should_throw(
parser,
"""
namespace A {
readonly attribute ObservableArray<boolean> foo;
};
""",
"used in namespaces",
)
# Test [Cached] extended attribute
harness.should_throw(
parser,
"""
interface A {
[Cached, Pure]
readonly attribute ObservableArray<boolean> foo;
};
""",
"have Cached extended attribute",
)
# Test [StoreInSlot] extended attribute
harness.should_throw(
parser,
"""
interface A {
[StoreInSlot, Pure]
readonly attribute ObservableArray<boolean> foo;
};
""",
"have StoreInSlot extended attribute",
)
# Test regular attribute
parser = parser.reset()
parser.parse(
"""
interface A {
readonly attribute ObservableArray<boolean> foo;
attribute ObservableArray<[Clamp] octet> bar;
attribute ObservableArray<long?> baz;
attribute ObservableArray<(boolean or long)> qux;
};
"""
)
results = parser.finish()
A = results[0]
foo = A.members[0]
harness.ok(foo.readonly, "A.foo is readonly attribute")
harness.ok(foo.type.isObservableArray(), "A.foo is ObservableArray type")
harness.check(
foo.slotIndices[A.identifier.name], 0, "A.foo should be stored in slot"
)
bar = A.members[1]
harness.ok(bar.type.isObservableArray(), "A.bar is ObservableArray type")
harness.check(
bar.slotIndices[A.identifier.name], 1, "A.bar should be stored in slot"
)
harness.ok(bar.type.inner.hasClamp(), "A.bar's inner type should be clamped")
baz = A.members[2]
harness.ok(baz.type.isObservableArray(), "A.baz is ObservableArray type")
harness.check(
baz.slotIndices[A.identifier.name], 2, "A.baz should be stored in slot"
)
harness.ok(baz.type.inner.nullable(), "A.baz's inner type should be nullable")
qux = A.members[3]
harness.ok(qux.type.isObservableArray(), "A.qux is ObservableArray type")
harness.check(
qux.slotIndices[A.identifier.name], 3, "A.qux should be stored in slot"
)
harness.ok(qux.type.inner.isUnion(), "A.qux's inner type should be union")
|