Skip to content

Commit 1070648

Browse files
jmeg-sfyrestyled-commits
authored andcommitted
YAML : Constraints with nullable types fixed for Min, Max & NotValue (#12958)
* Fix: Constraintswith nullable type fixed for Min Max NotValue * Restyled by clang-format * DEV: Add constraint checks on nullable * DEV: Update darwin test_cluster.zapt * Restyled by prettier-yaml * Darwin compile remove large integer u64x tests Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 34a46d6 commit 1070648

File tree

6 files changed

+4394
-2021
lines changed

6 files changed

+4394
-2021
lines changed

examples/chip-tool/commands/tests/TestCommand.h

+27
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ class TestCommand : public CHIPCommand
9292

9393
return true;
9494
}
95+
template <typename T, typename U>
96+
bool CheckConstraintMinValue(const char * itemName, const chip::app::DataModel::Nullable<T> & current, U expected)
97+
{
98+
if (current.IsNull())
99+
{
100+
return true;
101+
}
102+
return CheckConstraintMinValue(itemName, current.Value(), static_cast<T>(expected));
103+
}
95104
template <typename T>
96105
bool CheckConstraintMaxValue(const char * itemName, T current, T expected)
97106
{
@@ -104,6 +113,15 @@ class TestCommand : public CHIPCommand
104113
return true;
105114
}
106115
template <typename T, typename U>
116+
bool CheckConstraintMaxValue(const char * itemName, const chip::app::DataModel::Nullable<T> & current, U expected)
117+
{
118+
if (current.IsNull())
119+
{
120+
return true;
121+
}
122+
return CheckConstraintMaxValue(itemName, current.Value(), static_cast<T>(expected));
123+
}
124+
template <typename T, typename U>
107125
bool CheckConstraintNotValue(const char * itemName, T current, U expected)
108126
{
109127
if (current == expected)
@@ -114,6 +132,15 @@ class TestCommand : public CHIPCommand
114132

115133
return true;
116134
}
135+
template <typename T, typename U>
136+
bool CheckConstraintNotValue(const char * itemName, const chip::app::DataModel::Nullable<T> & current, U expected)
137+
{
138+
if (current.IsNull())
139+
{
140+
return true;
141+
}
142+
return CheckConstraintNotValue(itemName, current.Value(), expected);
143+
}
117144

118145
bool CheckConstraintNotValue(const char * itemName, chip::CharSpan current, chip::CharSpan expected)
119146
{

examples/chip-tool/templates/partials/test_cluster.zapt

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ class {{filename}}: public TestCommand
318318
{{~#if expectedConstraints.endsWith}}VerifyOrReturn(CheckConstraintEndsWith("{{>item}}", {{>item}}, "{{expectedConstraints.endsWith}}"));{{/if}}
319319
{{~#if expectedConstraints.minLength}}VerifyOrReturn(CheckConstraintMinLength("{{>item}}", {{>item}}.size(), {{expectedConstraints.minLength}}));{{/if}}
320320
{{~#if expectedConstraints.maxLength}}VerifyOrReturn(CheckConstraintMaxLength("{{>item}}", {{>item}}.size(), {{expectedConstraints.maxLength}}));{{/if}}
321-
{{~#if expectedConstraints.minValue}}VerifyOrReturn(CheckConstraintMinValue<{{chipType}}>("{{>item}}", {{>item}}, {{expectedConstraints.minValue}}));{{/if}}
322-
{{~#if expectedConstraints.maxValue}}VerifyOrReturn(CheckConstraintMaxValue<{{chipType}}>("{{>item}}", {{>item}}, {{expectedConstraints.maxValue}}));{{/if}}
321+
{{~#if expectedConstraints.minValue}}VerifyOrReturn(CheckConstraintMinValue<{{chipType}}>("{{>item}}", {{>item}}, {{asTypedLiteral expectedConstraints.minValue type}}));{{/if}}
322+
{{~#if expectedConstraints.maxValue}}VerifyOrReturn(CheckConstraintMaxValue<{{chipType}}>("{{>item}}", {{>item}}, {{asTypedLiteral expectedConstraints.maxValue type}}));{{/if}}
323323
{{~#if expectedConstraints.notValue}}VerifyOrReturn(CheckConstraintNotValue("{{>item}}", {{>item}}, {{asTypedLiteral expectedConstraints.notValue type}}));{{/if}}
324324
{{/if}}
325325

0 commit comments

Comments
 (0)