harness.check(len(dict1.members), 2, "Dict1 has two members")
harness.check(len(dict2.members), 2, "Dict2 has four members")
harness.check(
dict1.members[0].identifier.name, "otherParent", "'o' comes before 'p'"
)
harness.check(
dict1.members[1].identifier.name, "parent", "'o' really comes before 'p'"
)
harness.check(
dict2.members[0].identifier.name, "aaandAnother", "'a' comes before 'c'"
)
harness.check(
dict2.members[1].identifier.name, "child", "'a' really comes before 'c'"
)
# Test partial dictionary.
parser = parser.reset()
parser.parse( """
dictionary A {
long c;
long g;
};
partial dictionary A {
long h;
long d;
}; """
)
results = parser.finish()
dict1 = results[0]
harness.check(len(dict1.members), 4, "Dict1 has four members")
harness.check(dict1.members[0].identifier.name, "c", "c should be first")
harness.check(dict1.members[1].identifier.name, "d", "d should come after c")
harness.check(dict1.members[2].identifier.name, "g", "g should come after d")
harness.check(dict1.members[3].identifier.name, "h", "h should be last")
harness.ok(threw, "Should not allow name duplication in a dictionary")
# Test no name duplication across normal and partial dictionary.
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
long prop = 5;
};
partial dictionary A {
long prop;
}; """
)
parser.finish() except WebIDL.WebIDLError:
threw = True
harness.ok(
threw, "Should not allow name duplication across normal and partial dictionary"
)
harness.ok(threw, "Dictionary arg followed by optional arg must be optional")
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional A arg1, optional long arg2);
}; """
)
parser.finish() except WebIDL.WebIDLError:
threw = True
harness.ok(threw, "Dictionary arg followed by optional arg must have default value")
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(A arg1, optional long arg2, long arg3);
}; """
)
parser.finish() except WebIDL.WebIDLError:
threw = True
harness.ok( not threw, "Dictionary arg followed by non-optional arg doesn't have to be optional",
)
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo((A or DOMString) arg1, optional long arg2);
}; """
)
parser.finish() except WebIDL.WebIDLError:
threw = True
harness.ok(
threw, "Union arg containing dictionary followed by optional arg must ""be optional",
)
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional (A or DOMString) arg1, optional long arg2);
}; """
)
parser.finish() except WebIDL.WebIDLError:
threw = True
harness.ok(
threw, "Union arg containing dictionary followed by optional arg must " "have a default value",
)
parser = parser.reset()
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(A arg1, long arg2);
}; """
)
parser.finish()
harness.ok(True, "Dictionary arg followed by required arg can be required")
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional A? arg1 = {});
}; """
)
parser.finish() except Exception as x:
threw = x
harness.ok(threw, "Optional dictionary arg must not be nullable")
harness.ok( "nullable"in str(threw), "Must have the expected exception for optional nullable dictionary arg",
)
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
required long x;
};
interface X {
undefined doFoo(A? arg1);
}; """
)
parser.finish() except Exception as x:
threw = x
harness.ok(threw, "Required dictionary arg must not be nullable")
harness.ok( "nullable"in str(threw), "Must have the expected exception for required nullable ""dictionary arg",
)
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional (A or long)? arg1 = {});
}; """
)
parser.finish() except Exception as x:
threw = x
harness.ok(threw, "Dictionary arg must not be in an optional nullable union")
harness.ok( "nullable"in str(threw), "Must have the expected exception for optional nullable union " "arg containing dictionary",
)
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
required long x;
};
interface X {
undefined doFoo((A or long)? arg1);
}; """
)
parser.finish() except Exception as x:
threw = x
harness.ok(threw, "Dictionary arg must not be in a required nullable union")
harness.ok( "nullable"in str(threw), "Must have the expected exception for required nullable union " "arg containing dictionary",
)
harness.ok(not threw, "Nullable union should be allowed in a sequence argument")
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional (A or long?) arg1);
}; """
)
parser.finish() except WebIDL.WebIDLError:
threw = True
harness.ok(threw, "Dictionary must not be in a union with a nullable type")
parser = parser.reset()
threw = False try:
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional (long? or A) arg1);
}; """
)
parser.finish() except WebIDL.WebIDLError:
threw = True
harness.ok(threw, "A nullable type must not be in a union with a dictionary")
parser = parser.reset()
parser.parse( """
dictionary A {
};
interface X {
A? doFoo();
}; """
)
parser.finish()
harness.ok(True, "Dictionary return value can be nullable")
parser = parser.reset()
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional A arg = {});
}; """
)
parser.finish()
harness.ok(True, "Dictionary arg should actually parse")
parser = parser.reset()
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional (A or DOMString) arg = {});
}; """
)
parser.finish()
harness.ok(True, "Union arg containing a dictionary should actually parse")
parser = parser.reset()
parser.parse( """
dictionary A {
};
interface X {
undefined doFoo(optional (A or DOMString) arg = "abc");
}; """
)
parser.finish()
harness.ok( True, "Union arg containing a dictionary with string default should actually parse",
)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.