Skip to content

Commit

Permalink
Change expected-value matching to a valueEquals recursive template. (#…
Browse files Browse the repository at this point in the history
…11560)

For now this does not change any functionality: there is no change in
the generated code.  It just cleans up how nullable and optional are
handled.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Nov 2, 2022
1 parent 71f87d0 commit 90e7847
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
20 changes: 1 addition & 19 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,8 @@ class {{filename}}: public TestCommand
{{/if}}
{{#chip_tests_item_response_parameters}}
{{~#*inline "item"}}{{asLowerCamelCase name}}{{#if isOptional}}.Value(){{/if}}{{/inline}}
{{~#*inline "itemValue"}}{{>item}}{{#if isNullable}}.Value(){{/if}}{{/inline}}
{{#if hasExpectedValue}}
{{#if isOptional}}
{{~#*inline "item"}}{{asLowerCamelCase name}}{{/inline}}
VerifyOrReturn(CheckValuePresent("{{> item}}", {{> item}}));
{{/if}}
{{#if (isLiteralNull expectedValue)}}
VerifyOrReturn(CheckValueNull("{{> item}}", {{> item}}));
{{else}}
{{#if isNullable}}
VerifyOrReturn(CheckValueNonNull("{{> item}}", {{> item}}));
{{/if}}
VerifyOrReturn(CheckValue
{{~#if isList}}AsListLength("{{>itemValue}}", {{>itemValue}}, {{expectedValue.length}})
{{else if isArray}}AsList("{{>itemValue}}", {{>itemValue}}{{#if expectedValue.length}}, {{expectedValue}}{{/if}})
{{else if (isString type)}}AsString("{{>itemValue}}", {{>itemValue}}, "{{expectedValue}}")
{{else}}<{{chipType}}>("{{>itemValue}}", {{>itemValue}}, {{expectedValue}}{{asTypeLiteralSuffix type}})
{{/if}}
);
{{/if}}
{{>valueEquals actual=(asLowerCamelCase name) label=(asLowerCamelCase name) expected=expectedValue}}
{{/if}}
{{#if hasExpectedConstraints}}
{{#if isOptional}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{#if isOptional}}
VerifyOrReturn(CheckValuePresent("{{label}}", {{actual}}));
{{>valueEquals label=(concat label ".Value()") actual=(concat actual ".Value()") expected=expected isOptional=false}}
{{else if isNullable}}
{{#if (isLiteralNull expected)}}
VerifyOrReturn(CheckValueNull("{{label}}", {{actual}}));
{{else}}
VerifyOrReturn(CheckValueNonNull("{{label}}", {{actual}}));
{{>valueEquals label=(concat label ".Value()") actual=(concat actual ".Value()") expected=expected isNullable=false}}
{{/if}}
{{else}}
VerifyOrReturn(CheckValue
{{~#if isList}}AsListLength("{{label}}", {{actual}}, {{expected.length}})
{{else if isArray}}AsList("{{label}}", {{actual}}{{#if expected.length}}, {{expected}}{{/if}})
{{else if (isString type)}}AsString("{{label}}", {{actual}}, "{{expected}}")
{{else}}<{{chipType}}>("{{label}}", {{actual}}, {{expected}}{{asTypeLiteralSuffix type}})
{{/if}}
);
{{/if}}
4 changes: 4 additions & 0 deletions examples/chip-tool/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
{
"name": "commandValue",
"path": "partials/test_cluster_command_value.zapt"
},
{
"name": "valueEquals",
"path": "partials/test_cluster_value_equals.zapt"
}
],
"templates": [
Expand Down
4 changes: 4 additions & 0 deletions examples/placeholder/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
{
"name": "commandValue",
"path": "../../../examples/chip-tool/templates/partials/test_cluster_command_value.zapt"
},
{
"name": "valueEquals",
"path": "../../../examples/chip-tool/templates/partials/test_cluster_value_equals.zapt"
}
],
"templates": [
Expand Down

0 comments on commit 90e7847

Please sign in to comment.