test(hemar): update parser test to match better paths

This commit is contained in:
2025-12-09 14:21:03 +00:00
parent 93a7636c61
commit 13fdfac2ef
3 changed files with 26 additions and 16 deletions

View File

@@ -5,37 +5,37 @@
log notice "test case: ${WHITE}simple interpolation"
answer="$(printf '%s' '{[hello]}' | hemar -c)"
expected='[{"type":"interpolation","path":"hello"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"hello"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}interpolation with text before and after"
answer="$(printf '%s' 'foo {[bar]} baz' | hemar -c)"
expected='[{"type":"text","value":"foo "},{"type":"interpolation","path":"bar"},{"type":"text","value":" baz"}]'
expected='[{"type":"text","value":"foo "},{"type":"interpolation","path":[{"type":"key","key":"bar"}]},{"type":"text","value":" baz"}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}root path"
answer="$(printf '%s' '{[.]}' | hemar -c)"
expected='[{"type":"interpolation","path":"."}]'
expected='[{"type":"interpolation","path":[{"type":"root"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}simple path"
answer="$(printf '%s' '{[key]}' | hemar -c)"
expected='[{"type":"interpolation","path":"key"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"key"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}dot-separated path"
answer="$(printf '%s' '{[key.subkey]}' | hemar -c)"
expected='[{"type":"interpolation","path":"key.subkey"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"key"},{"type":"key","key":"subkey"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}long path"
answer="$(printf '%s' '{[key.subkey.subsubkey]}' | hemar -c)"
expected='[{"type":"interpolation","path":"key.subkey.subsubkey"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"key"},{"type":"key","key":"subkey"},{"type":"key","key":"subsubkey"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}multiple interpolations"
answer="$(printf '%s' '{[a]} {[b]} {[c]}' | hemar -c)"
expected='[{"type":"interpolation","path":"a"},{"type":"text","value":" "},{"type":"interpolation","path":"b"},{"type":"text","value":" "},{"type":"interpolation","path":"c"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"a"}]},{"type":"text","value":" "},{"type":"interpolation","path":[{"type":"key","key":"b"}]},{"type":"text","value":" "},{"type":"interpolation","path":[{"type":"key","key":"c"}]}]'
json_diff "$answer" "$expected"
log notice "test passed"

View File

@@ -5,42 +5,42 @@
log notice "test case: ${WHITE}quoted string in path"
answer="$(printf '%s' '{["key with spaces"]}' | hemar -c)"
expected='[{"type":"interpolation","path":"key with spaces"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"key with spaces"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}quoted dot in path"
answer="$(printf '%s' '{[".key"]}' | hemar -c)"
expected='[{"type":"interpolation","path":".key"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":".key"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}quoted vs unquoted dot"
answer="$(printf '%s' '{["."]} {[.]}' | hemar -c)"
expected='[{"type":"interpolation","path":"."},{"type":"text","value":" "},{"type":"interpolation","path":"."}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"."}]},{"type":"text","value":" "},{"type":"interpolation","path":[{"type":"root"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}path with index"
answer="$(printf '%s' '{[key[0]]}' | hemar -c)"
expected='[{"type":"interpolation","path":"key[0]"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"key"},{"type":"index","index":0}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}path with multiple indices"
answer="$(printf '%s' '{[[0][1][2]]}' | hemar -c)"
expected='[{"type":"interpolation","path":"[0][1][2]"}]'
expected='[{"type":"interpolation","path":[{"type":"index","index":0},{"type":"index","index":1},{"type":"index","index":2}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}path with negative index"
answer="$(printf '%s' '{[key[-1]]}' | hemar -c)"
expected='[{"type":"interpolation","path":"key[-1]"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"key"},{"type":"index","index":-1}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}complex path with mixed segments"
answer="$(printf '%s' '{["key".subkey[0]."subsubkey"]}' | hemar -c)"
expected='[{"type":"interpolation","path":"key.subkey[0].subsubkey"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"key"},{"type":"key","key":"subkey"},{"type":"index","index":0},{"type":"key","key":"subsubkey"}]}]'
json_diff "$answer" "$expected"
log notice "test case: ${WHITE}quoted string with escaped quote"
answer="$(printf '%s' '{["key""with""quotes"]}' | hemar -c)"
expected='[{"type":"interpolation","path":"key\"with\"quotes"}]'
expected='[{"type":"interpolation","path":[{"type":"key","key":"key\"with\"quotes"}]}]'
json_diff "$answer" "$expected"
log notice "test passed"