Skip to content

Commit

Permalink
update to latest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psdh authored and Prabhjyot Singh Sodhi committed Jan 21, 2016
1 parent 175b3c2 commit da40818
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 29 deletions.
43 changes: 41 additions & 2 deletions components/script/dom/bindings/codegen/parser/tests/test_attr.py
Expand Up @@ -293,10 +293,49 @@ def checkAttr(attr, QName, name, type, readonly):
try:
parser.parse("""
interface A {
[SetterInfallible] readonly attribute boolean foo;
[SetterThrows] readonly attribute boolean foo;
};
""")
results = parser.finish()
except Exception, x:
threw = True
harness.ok(threw, "Should not allow [SetterInfallible] on readonly attributes")
harness.ok(threw, "Should not allow [SetterThrows] on readonly attributes")

parser = parser.reset()
threw = False
try:
parser.parse("""
interface A {
[Throw] readonly attribute boolean foo;
};
""")
results = parser.finish()
except Exception, x:
threw = True
harness.ok(threw, "Should spell [Throws] correctly")

parser = parser.reset()
threw = False
try:
parser.parse("""
interface A {
[SameObject] readonly attribute boolean foo;
};
""")
results = parser.finish()
except Exception, x:
threw = True
harness.ok(threw, "Should not allow [SameObject] on attributes not of interface type")

parser = parser.reset()
threw = False
try:
parser.parse("""
interface A {
[SameObject] readonly attribute A foo;
};
""")
results = parser.finish()
except Exception, x:
threw = True
harness.ok(not threw, "Should allow [SameObject] on attributes of interface type")
Expand Up @@ -11,8 +11,9 @@ def checkArgument(argument, QName, name, type, optional, variadic):
harness.check(argument.variadic, variadic, "Argument has the right variadic value")

def checkMethod(method, QName, name, signatures,
static=False, getter=False, setter=False, creator=False,
deleter=False, legacycaller=False, stringifier=False):
static=True, getter=False, setter=False, creator=False,
deleter=False, legacycaller=False, stringifier=False,
chromeOnly=False):
harness.ok(isinstance(method, WebIDL.IDLMethod),
"Should be an IDLMethod")
harness.ok(method.isMethod(), "Method is a method")
Expand All @@ -27,6 +28,7 @@ def checkMethod(method, QName, name, signatures,
harness.check(method.isDeleter(), deleter, "Method has the correct deleter value")
harness.check(method.isLegacycaller(), legacycaller, "Method has the correct legacycaller value")
harness.check(method.isStringifier(), stringifier, "Method has the correct stringifier value")
harness.check(method.getExtendedAttribute("ChromeOnly") is not None, chromeOnly, "Method has the correct value for ChromeOnly")
harness.check(len(method.signatures()), len(signatures), "Method has the correct number of signatures")

sigpairs = zip(method.signatures(), signatures)
Expand Down Expand Up @@ -55,11 +57,13 @@ def checkMethod(method, QName, name, signatures,
};
""")
results = parser.finish()
harness.check(len(results), 3, "Should be two productions")
harness.check(len(results), 3, "Should be three productions")
harness.ok(isinstance(results[0], WebIDL.IDLInterface),
"Should be an IDLInterface")
harness.ok(isinstance(results[1], WebIDL.IDLInterface),
"Should be an IDLInterface")
harness.ok(isinstance(results[2], WebIDL.IDLInterface),
"Should be an IDLInterface")

checkMethod(results[0].ctor(), "::TestConstructorNoArgs::constructor",
"constructor", [("TestConstructorNoArgs (Wrapper)", [])])
Expand All @@ -73,3 +77,33 @@ def checkMethod(method, QName, name, signatures,
[("::TestConstructorOverloads::constructor::foo", "foo", "Object", False, False)]),
("TestConstructorOverloads (Wrapper)",
[("::TestConstructorOverloads::constructor::bar", "bar", "Boolean", False, False)])])

parser = parser.reset()
parser.parse("""
[ChromeConstructor()]
interface TestChromeConstructor {
};
""")
results = parser.finish()
harness.check(len(results), 1, "Should be one production")
harness.ok(isinstance(results[0], WebIDL.IDLInterface),
"Should be an IDLInterface")

checkMethod(results[0].ctor(), "::TestChromeConstructor::constructor",
"constructor", [("TestChromeConstructor (Wrapper)", [])],
chromeOnly=True)

parser = parser.reset()
threw = False
try:
parser.parse("""
[Constructor(),
ChromeConstructor(DOMString a)]
interface TestChromeConstructor {
};
""")
results = parser.finish()
except:
threw = True

harness.ok(threw, "Can't have both a Constructor and a ChromeConstructor")
Expand Up @@ -2,19 +2,19 @@

def WebIDLTest(parser, harness):
parser.parse("""
[Flippety]
[NoInterfaceObject]
interface TestExtendedAttr {
[Foopy] attribute byte b;
[Unforgeable] readonly attribute byte b;
};
""")

results = parser.finish()

parser = parser.reset()
parser.parse("""
[Flippety="foo.bar",Floppety=flop]
[Pref="foo.bar",Pref=flop]
interface TestExtendedAttr {
[Foopy="foo.bar"] attribute byte b;
[Pref="foo.bar"] attribute byte b;
};
""")

Expand Down
Expand Up @@ -39,28 +39,27 @@ def WebIDLTest(parser, harness):
attribute DOMString? b;
};
/* Not implemented. */
/*interface TestNullableEquivalency8 {
interface TestNullableEquivalency8 {
attribute float a;
attribute float? b;
};*/
};
interface TestNullableEquivalency8 {
interface TestNullableEquivalency9 {
attribute double a;
attribute double? b;
};
interface TestNullableEquivalency9 {
interface TestNullableEquivalency10 {
attribute object a;
attribute object? b;
};
interface TestNullableEquivalency10 {
interface TestNullableEquivalency11 {
attribute double[] a;
attribute double[]? b;
};
interface TestNullableEquivalency11 {
interface TestNullableEquivalency12 {
attribute TestNullableEquivalency9[] a;
attribute TestNullableEquivalency9[]? b;
};
Expand Down Expand Up @@ -91,7 +90,7 @@ def checkEquivalent(iface, harness):
for attr in dir(type1):
if attr.startswith('_') or \
attr in ['nullable', 'builtin', 'filename', 'location',
'inner', 'QName'] or \
'inner', 'QName', 'getDeps', 'name'] or \
(hasattr(type(type1), attr) and not callable(getattr(type1, attr))):
continue

Expand Down
Expand Up @@ -11,4 +11,20 @@ def WebIDLTest(parser, harness):
except:
threw = True

harness.ok(threw, "Should have thrown.")
harness.ok(not threw,
"Should not have thrown on non-optional argument following "
"optional argument.")

parser = parser.reset()
parser.parse("""
interface OptionalConstraints2 {
void foo(optional byte arg1 = 1, optional byte arg2 = 2,
optional byte arg3, optional byte arg4 = 4,
optional byte arg5, optional byte arg6 = 9);
};
""")
results = parser.finish()
args = results[0].members[0].signatures()[0][1]
harness.check(len(args), 6, "Should have 6 arguments")
harness.check(args[5].defaultValue.value, 9,
"Should have correct default value")
Expand Up @@ -2,11 +2,11 @@

def WebIDLTest(parser, harness):
parser.parse("""
callback Function = any(any... arguments);
[TreatNonCallableAsNull] callback Function = any(any... arguments);
interface TestTreatNonCallableAsNull1 {
[TreatNonCallableAsNull] attribute Function? onfoo;
attribute Function? onbar;
attribute Function? onfoo;
attribute Function onbar;
};
""")

Expand Down Expand Up @@ -54,3 +54,18 @@ def WebIDLTest(parser, harness):
threw = True

harness.ok(threw, "Should have thrown.")

parser = parser.reset()

threw = False
try:
parser.parse("""
[TreatNonCallableAsNull, TreatNonObjectAsNull]
callback Function = any(any... arguments);
""")

results = parser.finish()
except:
threw = True

harness.ok(threw, "Should have thrown.")
Expand Up @@ -12,7 +12,7 @@ def WebIDLTest(parser, harness):

results = parser.finish()

harness.check(results[2].members[1].type.name, "Long",
harness.check(results[2].members[1].type.name, "LongOrNull",
"Should expand typedefs")

parser = parser.reset()
Expand Down
@@ -1,39 +1,63 @@
def WebIDLTest(parser, harness):
threw = False
try:
results = parser.parse("""
parser.parse("""
interface VariadicConstraints1 {
void foo(byte... arg1, byte arg2);
};
""")
results = parser.finish()

except:
threw = True

harness.ok(threw, "Should have thrown.")
harness.ok(threw,
"Should have thrown on variadic argument followed by required "
"argument.")

parser = parser.reset()
threw = False
try:
results = parser.parse("""
parser.parse("""
interface VariadicConstraints2 {
void foo(byte... arg1, optional byte arg2);
};
""")

results = parser.finish();
except:
threw = True

harness.ok(threw, "Should have thrown.")
harness.ok(threw,
"Should have thrown on variadic argument followed by optional "
"argument.")

parser = parser.reset()
threw = False
try:
results = parser.parse("""
parser.parse("""
interface VariadicConstraints3 {
void foo(optional byte... arg1);
};
""")
results = parser.finish()

except:
threw = True

harness.ok(threw,
"Should have thrown on variadic argument explicitly flagged as "
"optional.")

parser = parser.reset()
threw = False
try:
parser.parse("""
interface VariadicConstraints4 {
void foo(byte... arg1 = 0);
};
""")
results = parser.finish()
except:
threw = True

harness.ok(threw, "Should have thrown.")
harness.ok(threw, "Should have thrown on variadic argument with default value.")

0 comments on commit da40818

Please sign in to comment.