4 def WebIDLTest(parser
, harness
):
7 interface TestMethods {
9 static undefined basicStatic();
10 undefined basicWithSimpleArgs(boolean arg1, byte arg2, unsigned long arg3);
11 boolean basicBoolean();
12 static boolean basicStaticBoolean();
13 boolean basicBooleanWithSimpleArgs(boolean arg1, byte arg2, unsigned long arg3);
14 undefined optionalArg(optional byte? arg1, optional sequence<byte> arg2);
15 undefined variadicArg(byte?... arg1);
17 undefined setObject(object arg1);
18 undefined setAny(any arg1);
19 float doFloats(float arg1);
24 results
= parser
.finish()
26 harness
.ok(True, "TestMethods interface parsed without error.")
27 harness
.check(len(results
), 1, "Should be one production.")
29 harness
.ok(isinstance(iface
, WebIDL
.IDLInterface
), "Should be an IDLInterface")
31 iface
.identifier
.QName(), "::TestMethods", "Interface has the right QName"
33 harness
.check(iface
.identifier
.name
, "TestMethods", "Interface has the right name")
34 harness
.check(len(iface
.members
), 12, "Expect 12 members")
36 methods
= iface
.members
38 def checkArgument(argument
, QName
, name
, type, optional
, variadic
):
39 harness
.ok(isinstance(argument
, WebIDL
.IDLArgument
), "Should be an IDLArgument")
41 argument
.identifier
.QName(), QName
, "Argument has the right QName"
43 harness
.check(argument
.identifier
.name
, name
, "Argument has the right name")
44 harness
.check(str(argument
.type), type, "Argument has the right return type")
46 argument
.optional
, optional
, "Argument has the right optional value"
49 argument
.variadic
, variadic
, "Argument has the right variadic value"
64 harness
.ok(isinstance(method
, WebIDL
.IDLMethod
), "Should be an IDLMethod")
65 harness
.ok(method
.isMethod(), "Method is a method")
66 harness
.ok(not method
.isAttr(), "Method is not an attr")
67 harness
.ok(not method
.isConst(), "Method is not a const")
68 harness
.check(method
.identifier
.QName(), QName
, "Method has the right QName")
69 harness
.check(method
.identifier
.name
, name
, "Method has the right name")
70 harness
.check(method
.isStatic(), static
, "Method has the correct static value")
71 harness
.check(method
.isGetter(), getter
, "Method has the correct getter value")
72 harness
.check(method
.isSetter(), setter
, "Method has the correct setter value")
74 method
.isDeleter(), deleter
, "Method has the correct deleter value"
77 method
.isLegacycaller(),
79 "Method has the correct legacycaller value",
82 method
.isStringifier(),
84 "Method has the correct stringifier value",
87 len(method
.signatures()),
89 "Method has the correct number of signatures",
92 sigpairs
= zip(method
.signatures(), signatures
)
93 for gotSignature
, expectedSignature
in sigpairs
:
94 (gotRetType
, gotArgs
) = gotSignature
95 (expectedRetType
, expectedArgs
) = expectedSignature
98 str(gotRetType
), expectedRetType
, "Method has the expected return type."
101 for i
in range(0, len(gotArgs
)):
102 (QName
, name
, type, optional
, variadic
) = expectedArgs
[i
]
103 checkArgument(gotArgs
[i
], QName
, name
, type, optional
, variadic
)
105 checkMethod(methods
[0], "::TestMethods::basic", "basic", [("Undefined", [])])
108 "::TestMethods::basicStatic",
115 "::TestMethods::basicWithSimpleArgs",
116 "basicWithSimpleArgs",
122 "::TestMethods::basicWithSimpleArgs::arg1",
129 "::TestMethods::basicWithSimpleArgs::arg2",
136 "::TestMethods::basicWithSimpleArgs::arg3",
147 methods
[3], "::TestMethods::basicBoolean", "basicBoolean", [("Boolean", [])]
151 "::TestMethods::basicStaticBoolean",
152 "basicStaticBoolean",
158 "::TestMethods::basicBooleanWithSimpleArgs",
159 "basicBooleanWithSimpleArgs",
165 "::TestMethods::basicBooleanWithSimpleArgs::arg1",
172 "::TestMethods::basicBooleanWithSimpleArgs::arg2",
179 "::TestMethods::basicBooleanWithSimpleArgs::arg3",
191 "::TestMethods::optionalArg",
198 "::TestMethods::optionalArg::arg1",
205 "::TestMethods::optionalArg::arg2",
217 "::TestMethods::variadicArg",
224 "::TestMethods::variadicArg::arg1",
234 checkMethod(methods
[8], "::TestMethods::getObject", "getObject", [("Object", [])])
237 "::TestMethods::setObject",
242 [("::TestMethods::setObject::arg1", "arg1", "Object", False, False)],
248 "::TestMethods::setAny",
250 [("Undefined", [("::TestMethods::setAny::arg1", "arg1", "Any", False, False)])],
254 "::TestMethods::doFloats",
256 [("Float", [("::TestMethods::doFloats::arg1", "arg1", "Float", False, False)])],
259 parser
= parser
.reset()
265 undefined foo(optional float bar = 1);
269 results
= parser
.finish()
270 except WebIDL
.WebIDLError
:
272 harness
.ok(not threw
, "Should allow integer to float type corecion")
274 parser
= parser
.reset()
280 [GetterThrows] undefined foo();
284 results
= parser
.finish()
285 except WebIDL
.WebIDLError
:
287 harness
.ok(threw
, "Should not allow [GetterThrows] on methods")
289 parser
= parser
.reset()
295 [SetterThrows] undefined foo();
299 results
= parser
.finish()
300 except WebIDL
.WebIDLError
:
302 harness
.ok(threw
, "Should not allow [SetterThrows] on methods")
304 parser
= parser
.reset()
310 [Throw] undefined foo();
314 results
= parser
.finish()
315 except WebIDL
.WebIDLError
:
317 harness
.ok(threw
, "Should spell [Throws] correctly on methods")
319 parser
= parser
.reset()
325 undefined __noSuchMethod__();
329 results
= parser
.finish()
330 except WebIDL
.WebIDLError
:
332 harness
.ok(threw
, "Should not allow __noSuchMethod__ methods")
334 parser
= parser
.reset()
340 [Throws, LenientFloat]
341 undefined foo(float myFloat);
347 results
= parser
.finish()
348 except WebIDL
.WebIDLError
:
350 harness
.ok(not threw
, "Should allow LenientFloat to be only in a specific overload")
352 parser
= parser
.reset()
358 [Throws, LenientFloat]
359 undefined foo(float myFloat);
363 results
= parser
.finish()
365 methods
= iface
.members
366 lenientFloat
= methods
[0].getExtendedAttribute("LenientFloat")
368 lenientFloat
is not None,
369 "LenientFloat in overloads must be added to the method",
372 parser
= parser
.reset()
378 [Throws, LenientFloat]
379 undefined foo(float myFloat);
381 undefined foo(float myFloat, float yourFloat);
385 results
= parser
.finish()
386 except WebIDL
.WebIDLError
:
390 "Should prevent overloads from getting different restricted float behavior",
393 parser
= parser
.reset()
400 undefined foo(float myFloat, float yourFloat);
401 [Throws, LenientFloat]
402 undefined foo(float myFloat);
406 results
= parser
.finish()
407 except WebIDL
.WebIDLError
:
411 "Should prevent overloads from getting different restricted float behavior (2)",
414 parser
= parser
.reset()
420 [Throws, LenientFloat]
421 undefined foo(float myFloat);
422 [Throws, LenientFloat]
423 undefined foo(short myShort);
427 results
= parser
.finish()
428 except WebIDL
.WebIDLError
:
430 harness
.ok(threw
, "Should prevent overloads from getting redundant [LenientFloat]")