From 240d2d5ef58b7d5637604c0f687d1efbff549f2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Thu, 13 Nov 2025 10:38:41 +0000 Subject: [PATCH] tests: shunit2: add test for _jshn_append leading space fix MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Verifies the fix in commit 2065c3909935 ("libubox: Drop extraneous space when appending values to variable") that prevents leading spaces when appending to empty variables. test_jshn_append_no_leading_space ASSERT:expected: but was:< foo> ASSERT:expected: but was:< first second> References: #16 Signed-off-by: Petr Å tetiar --- tests/shunit2/tests.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/shunit2/tests.sh b/tests/shunit2/tests.sh index b27775a..bb02fcd 100755 --- a/tests/shunit2/tests.sh +++ b/tests/shunit2/tests.sh @@ -284,4 +284,25 @@ test_cmd_return() { %VAR% ow" } +test_jshn_append_no_leading_space() { + JSON_PREFIX="${JSON_PREFIX:-}" + . ../../sh/jshn.sh + + # Test appending to empty variable - should not have leading space + var='' + _jshn_append var 'foo' + assertEquals "foo" "$var" + + # Test appending to non-empty variable - should have space separator + var='bar' + _jshn_append var 'foo' + assertEquals "bar foo" "$var" + + # Test multiple appends to empty variable + var='' + _jshn_append var 'first' + _jshn_append var 'second' + assertEquals "first second" "$var" +} + . ./shunit2/shunit2 -- 2.30.2