From a80fefb7e7d469dae07280612862ff05861c3686 Mon Sep 17 00:00:00 2001 From: Chris HORLER Date: Wed, 28 Feb 2024 18:36:56 +0000 Subject: [PATCH 1/4] improve huddle tests to ensure coverage of all basic types --- tests/huddle.test | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/huddle.test b/tests/huddle.test index 1a20d8a..a2596b6 100755 --- a/tests/huddle.test +++ b/tests/huddle.test @@ -25,10 +25,6 @@ namespace eval ::yajl::test { set json_obj [yajl create #auto -beautify 0] set yajlstr2 [$json_obj parse $json] $json_obj delete - - # TODO: test next 2 lines are just a hack because the conversion to huddle is lossy with number types? - set yajlstr [string map {number string} $yajlstr] - set yajlstr2 [string map {number string} $yajlstr2] if {$yajlstr2 != $yajlstr} { puts "YAJL:\t\t$yajlstr" @@ -66,10 +62,10 @@ namespace eval ::yajl::test { } -result 1 # TODO: this test currently fails - # test 1.04 {: Array with null element - # } -body { - # dotest {{"moo": "cow", "pig": "oink", "rabbit" : null}} - # } -result 1 + test 1.04 {: Array with null element + } -body { + dotest {{"moo": "cow", "pig": "oink", "rabbit" : null}} + } -result 1 test 1.05 {: example from the yajl-tcl README file. @@ -154,6 +150,23 @@ namespace eval ::yajl::test { }} } -result 1 + # HUDDLE {D {A {b true}}} + test 1.08 {: basic types boolean + } -body { + dotest {{"key": true}} + } -result 1 + + # HUDDLE {D {A {num 42}}} + test 1.09 {: basic types integer + } -body { + dotest {{"key": 42}} + } -result 1 + + # HUDDLE {D {A null}} + test 1.11 {: basic types null + } -body { + dotest {{"key": null}} + } -result 1 } cleanupTests From 372c4e192a93db46b13e792d51cf2ebde049f687 Mon Sep 17 00:00:00 2001 From: Chris HORLER Date: Wed, 28 Feb 2024 18:37:40 +0000 Subject: [PATCH 2/4] fix huddle encoding of JSON null --- generic/yajltcl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/yajltcl.c b/generic/yajltcl.c index 37587f9..f8efbf3 100644 --- a/generic/yajltcl.c +++ b/generic/yajltcl.c @@ -445,7 +445,7 @@ parse2huddle_null_callback (void *context) { yajltcl_clientData *yajlData = context; - Tcl_DStringAppendElement (&yajlData->p2dString, "s null"); + Tcl_DStringAppendElement (&yajlData->p2dString, "null"); return 1; } From 4b2f98957ce8fa0edcb5209cf9e74ed662e8ed99 Mon Sep 17 00:00:00 2001 From: Chris HORLER Date: Wed, 28 Feb 2024 18:38:10 +0000 Subject: [PATCH 3/4] fix huddle encoding of boolean types --- generic/yajltcl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/yajltcl.c b/generic/yajltcl.c index f8efbf3..e78a22e 100644 --- a/generic/yajltcl.c +++ b/generic/yajltcl.c @@ -456,7 +456,7 @@ parse2huddle_boolean_callback (void *context, int boolean) { yajltcl_clientData *yajlData = context; - Tcl_DStringAppendElement (&yajlData->p2dString, boolean ? "1" : "0"); + Tcl_DStringAppendElement (&yajlData->p2dString, boolean ? "b true" : "b false"); return 1; } From 472df2cffe535d723a21edd8a732abbc9c115237 Mon Sep 17 00:00:00 2001 From: Chris HORLER Date: Wed, 28 Feb 2024 18:39:35 +0000 Subject: [PATCH 4/4] fix huddle encoding of number types --- generic/yajltcl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/yajltcl.c b/generic/yajltcl.c index e78a22e..0e6ba61 100644 --- a/generic/yajltcl.c +++ b/generic/yajltcl.c @@ -467,7 +467,7 @@ parse2huddle_number_callback (void *context, const char *s, size_t l) { yajltcl_clientData *yajlData = context; - Tcl_DStringAppend (&yajlData->p2dString, "{s ",3); + Tcl_DStringAppend (&yajlData->p2dString, "{num ", 5); Tcl_DStringSetLength (&yajlData->dString, 0); Tcl_DStringAppend (&yajlData->dString, s, l);