@@ -42,12 +42,10 @@ int main() {
4242
4343 JsonCommandInterpreter json (registry);
4444
45- // Canonical path + typed named parameters.
4645 auto result = json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":2,"state":true,"duty":0.5}})" );
4746 assert (result.success );
4847 assert (pin == 2 && state && std::fabs (duty - 0.5 ) < 0.000001 && calls == 1 );
4948
50- // Native JSON types are preserved into middleware/CommandInvocation.
5149 bool sawInteger = false ;
5250 bool sawBoolean = false ;
5351 bool sawFloating = false ;
@@ -63,23 +61,18 @@ int main() {
6361 result = json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":3,"state":false,"duty":0.25}})" );
6462 assert (result.success && sawInteger && sawBoolean && sawFloating);
6563
66- // Convenience command string.
6764 result = json.Invoke (R"( {"command":"gpio write","parameters":{"pin":4,"state":true}})" );
6865 assert (result.success && pin == 4 && state && duty == 1.0 );
6966
70- // Positional JSON values.
7167 result = json.Invoke (R"( {"path":["gpio","write"],"positional":[5,false,0.75]})" );
7268 assert (result.success && pin == 5 && !state && std::fabs (duty - 0.75 ) < 0.000001 );
7369
74- // Strings remain strings and preserve spaces without command-line quoting.
7570 result = json.Invoke (R"( {"path":["system","label"],"parameters":{"value":"Main Controller"}})" );
7671 assert (result.success && label == " Main Controller" );
7772
78- // 'named' is accepted as an alias for 'parameters'.
7973 result = json.Invoke (R"( {"path":["gpio","write"],"named":{"pin":6,"state":true}})" );
8074 assert (result.success && pin == 6 && state);
8175
82- // Parsing can be used independently from invocation.
8376 CommandInvocation invocation;
8477 std::string error;
8578 assert (json.Parse (R"( {"path":["gpio","write"],"parameters":{"pin":7,"state":true}})" , invocation, &error));
@@ -88,7 +81,6 @@ int main() {
8881 assert (invocation.named .at (" pin" ).GetType () == CommandValue::Type::SignedInteger);
8982 assert (invocation.named .at (" state" ).GetType () == CommandValue::Type::Boolean);
9083
91- // Invalid JSON and malformed envelopes.
9284 assert (!json.Invoke (" {" ).success );
9385 assert (!json.Invoke (R"( [])" ).success );
9486 assert (!json.Invoke (R"( {})" ).success );
@@ -98,19 +90,16 @@ int main() {
9890 assert (!json.Invoke (R"( {"path":["gpio","write"],"parameters":{},"named":{}})" ).success );
9991 assert (!json.Invoke (R"( {"path":["gpio","write"],"positional":"not-an-array"})" ).success );
10092
101- // Current Command parameter model is scalar: reject object/array/null values.
10293 assert (!json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":{"value":2},"state":true}})" ).success );
10394 assert (!json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":[2],"state":true}})" ).success );
10495 assert (!json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":null,"state":true}})" ).success );
10596
106- // Registry validation remains authoritative.
10797 assert (!json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":99,"state":true}})" ).success );
10898 assert (!json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":2.5,"state":true}})" ).success );
10999 assert (!json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":2,"state":"not-a-bool"}})" ).success );
110100 assert (!json.Invoke (R"( {"path":["gpio","write"],"parameters":{"pin":2,"state":true,"unknown":5}})" ).success );
111101 assert (!json.Invoke (R"( {"path":["missing"],"parameters":{}})" ).success );
112102
113- // Structured result JSON is deterministic and machine-readable.
114103 const std::string resultJson = json.InvokeToJson (R"( {"path":["gpio","write"],"parameters":{"pin":8,"state":false}})" );
115104 ArduinoJson::JsonDocument resultDocument;
116105 assert (!ArduinoJson::deserializeJson (resultDocument, resultJson));
@@ -125,7 +114,6 @@ int main() {
125114 assert (errorDocument[" code" ].as <int >() != 0 );
126115 assert (std::string (errorDocument[" message" ].as <const char *>()).find (" range" ) != std::string::npos);
127116
128- // Discovery exposes command and parameter metadata.
129117 const std::string discoveryJson = json.Describe ();
130118 ArduinoJson::JsonDocument discovery;
131119 assert (!ArduinoJson::deserializeJson (discovery, discoveryJson));
@@ -154,7 +142,6 @@ int main() {
154142 assert (parameters[0 ][" minimum" ].as <double >() == 0.0 );
155143 assert (parameters[0 ][" maximum" ].as <double >() == 48.0 );
156144
157- // Hidden commands can be explicitly included for privileged tooling.
158145 const std::string fullDiscoveryJson = json.Describe ({}, true );
159146 ArduinoJson::JsonDocument fullDiscovery;
160147 assert (!ArduinoJson::deserializeJson (fullDiscovery, fullDiscoveryJson));
0 commit comments