codegen: add tests for non-nullable non-required values

This commit is contained in:
Emilio Cobos Álvarez 2016-05-12 21:08:35 +02:00
parent 92ba0b9c39
commit 093f5c01e4
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 16 additions and 6 deletions

View file

@ -347,11 +347,15 @@ impl TestBindingMethods for TestBinding {
unsignedLongValue: None, unsignedLongValue: None,
unsignedShortValue: None, unsignedShortValue: None,
usvstringValue: None, usvstringValue: None,
nonRequiredNullable: None,
nonRequiredNullable2: Some(None), // null
} }
} }
fn TypeKeywordIsSuccess(&self, arg: &TestDictionary) -> bool { fn DictMatchesPassedValues(&self, arg: &TestDictionary) -> bool {
arg.type_.as_ref().map(|s| s == "success").unwrap_or(false) arg.type_.as_ref().map(|s| s == "success").unwrap_or(false) &&
arg.nonRequiredNullable.is_none() &&
arg.nonRequiredNullable2 == Some(None)
} }
fn PassBoolean(&self, _: bool) {} fn PassBoolean(&self, _: bool) {}

View file

@ -32,6 +32,11 @@ dictionary TestDictionary {
sequence<TestDictionaryDefaults> seqDict; sequence<TestDictionaryDefaults> seqDict;
// Reserved rust keyword // Reserved rust keyword
DOMString type; DOMString type;
// These are used to test bidirectional conversion
// and differentiation of non-required and nullable types
// in dictionaries.
DOMString? nonRequiredNullable;
DOMString? nonRequiredNullable2;
}; };
dictionary TestDictionaryDefaults { dictionary TestDictionaryDefaults {
@ -199,7 +204,7 @@ interface TestBinding {
(unsigned long or boolean)? receiveNullableUnion5(); (unsigned long or boolean)? receiveNullableUnion5();
sequence<long>? receiveNullableSequence(); sequence<long>? receiveNullableSequence();
TestDictionary receiveTestDictionaryWithSuccessOnKeyword(); TestDictionary receiveTestDictionaryWithSuccessOnKeyword();
boolean typeKeywordIsSuccess(TestDictionary arg); boolean dictMatchesPassedValues(TestDictionary arg);
void passBoolean(boolean arg); void passBoolean(boolean arg);
void passByte(byte arg); void passByte(byte arg);

View file

@ -9,8 +9,9 @@ test(function() {
var dict = t.receiveTestDictionaryWithSuccessOnKeyword(); var dict = t.receiveTestDictionaryWithSuccessOnKeyword();
assert_equals(dict.type, "success"); assert_equals(dict.type, "success");
assert_equals(dict.nonRequiredNullable, undefined);
assert_equals(dict.nonRequiredNullable2, null);
var is_success = t.typeKeywordIsSuccess(dict); assert_true(t.dictMatchesPassedValues(dict));
assert_true(is_success); }, "Conversion of dictionary elements with rust keywords, and null non-required nullable properties works")
}, "Conversion of dictionary elements with rust keywords works")
</script> </script>