Skip to content

Commit 17832cc

Browse files
committed
test: For indexing object with a number string
This already worked, but I just wanted to be sure due to the recent change
1 parent e7c6171 commit 17832cc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/errors-bad-index.bats

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,27 @@ load './util/init.sh'
4747
assert_line -p "ERROR_ARGUMENTS_INCORRECT_TYPE"
4848
assert_line -p "Cannot index an array with a non-integer"
4949
}
50+
51+
# misc
52+
@test "Correctly indexes an object with a number string" {
53+
declare -A OBJECT=()
54+
55+
bobject set-object --value 'OBJECT' '.["2"]' -- keyy valuee a b
56+
bobject set-array --value 'OBJECT' '.["3"]' -- one two three
57+
bobject set-string --value 'OBJECT' '.["4"]' -- zeta
58+
59+
bobject get-object --value 'OBJECT' '.["2"]'
60+
local keys=("${!REPLY[@]}")
61+
assert [ "${#REPLY[@]}" = 2 ]
62+
assert [ "${keys[0]}" = 'keyy' ]
63+
assert [ "${keys[1]}" = 'a' ]
64+
65+
bobject get-array --value 'OBJECT' '.["3"]'
66+
assert [ ${#REPLY[@]} -eq 3 ]
67+
68+
bobject get-string --value 'OBJECT' '.["3"].[0]'
69+
assert [ "$REPLY" = 'one' ]
70+
71+
bobject get-string --value 'OBJECT' '.["4"]'
72+
assert [ "$REPLY" = 'zeta' ]
73+
}

0 commit comments

Comments
 (0)