diff --git a/tests/shunit2/tests.sh b/tests/shunit2/tests.sh index c24f634..8d0a644 100755 --- a/tests/shunit2/tests.sh +++ b/tests/shunit2/tests.sh @@ -452,4 +452,25 @@ test_jshn_add_multi() { set -u } +test_jshn_append_via_json_script() { + JSON_PREFIX="${JSON_PREFIX:-}" + . ../../sh/jshn.sh + + # __SHUNIT_SHELL_FLAGS='u' results in 'line 6: JSON_UNSET: unbound variable' in json_cleanup() + set +u + + # Test appending first key to empty variable without leading space + json_init + json_add_string "first" "value1" + json_get_keys keys + assertEquals "first" "$keys" + + # Test appending second key should maintain no leading space on first key + json_add_string "second" "value2" + json_get_keys keys + assertEquals "first second" "$keys" + + set -u +} + . ./shunit2/shunit2