diff options
| author | Petr Štetiar | 2025-11-13 11:56:15 +0000 |
|---|---|---|
| committer | Álvaro Fernández Rojas | 2025-11-17 18:31:02 +0000 |
| commit | a3ff29ef93df3ec6e40447f6f4e029ebd07a29f1 (patch) | |
| tree | cc4ab8b2bb324ade8334d1ea9f66d0b098115647 | |
| parent | 440b4e988f39ecb7371fe36fd85f96a0eef23465 (diff) | |
| download | libubox-a3ff29ef93df3ec6e40447f6f4e029ebd07a29f1.tar.gz | |
tests: shunit2: add test for _jshn_append via JSON script
Add another test which verifies _jshn_append leading space fix in commit
82cb5fd66af9 ("libubox: Drop extraneous space when appending values to
variable") by appending keys to JSON objects, making sure there is no
leading space on the first key when adding second key.
test_jshn_append_via_json_script
ASSERT:expected:<first> but was:< first>
ASSERT:expected:<first second> but was:< first second>
Tests: #16
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Link: https://github.com/openwrt/libubox/pull/30
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
| -rwxr-xr-x | tests/shunit2/tests.sh | 21 |
1 files changed, 21 insertions, 0 deletions
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 |