Skip to content

Commit 48a95d8

Browse files
committed
Fix output consistency across the board + bugs + tests
1 parent c44bf2b commit 48a95d8

File tree

5 files changed

+85
-326
lines changed

5 files changed

+85
-326
lines changed

.github/workflows/shell-ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Run shunit2 tests
1919
uses: sudo-bot/action-shunit2@latest
2020
with:
21-
cli: "./tests/bash-map.test.sh"
21+
cli: "./test/bash-map.test.sh"
2222

2323
shellcheck:
2424
name: Run ShellCheck

examples/advanced.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ map::make items "
1010
[grape] = 3.99
1111
"
1212

13-
# Create a map for a shopping cart
1413
map::make cart "
1514
[apple] = 3
1615
[orange] = 4

examples/basic.sh

100644100755
Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,63 @@ script_dir="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
44
source "${script_dir%/*}/src/bash-map.sh"
55

66
# Create a new map
7-
map::make user_info "
7+
map::make user "
88
[name] = John Doe
99
[age] = 30
1010
[city] = New York
1111
"
1212

13-
# Print the map
14-
echo "User Information:"
15-
map::print user_info
13+
show_profile() {
14+
echo "User Profile"
15+
map::print "$1"
16+
echo
17+
}
18+
19+
has_email() {
20+
if map::has "$1" email; then
21+
echo "Email exists"
22+
else
23+
echo "Email does not exist"
24+
fi
25+
}
26+
27+
show_profile user
1628

1729
# Get and display a specific value
18-
name=$(map::get user_info name)
30+
name=$(map::get user name)
1931
echo "Name: $name"
2032

2133
# Update a value
22-
map::set user_info age 31
34+
echo "Updating [age] to 31..."
35+
map::set user age 31
2336

2437
# Add a new key-value pair
25-
map::set user_info job "Pinball Wizard"
38+
echo "Adding [job] property..."
39+
map::set user job "Pinball Wizard"
2640

27-
# Check if a key exists
28-
if map::has user_info email; then
29-
echo "Email exists"
30-
else
31-
echo "Email does not exist"
32-
fi
41+
echo
42+
show_profile user
3343

34-
# Print the updated map
35-
echo "Updated User Information:"
36-
map::print user_info
44+
echo "Metadata"
45+
# Get the keys
46+
keys=$(map::keys user)
47+
echo "keys: $keys"
48+
49+
# Get the values
50+
values=$(map::values user)
51+
echo "values: $values"
3752

3853
# Get the size of the map
39-
size=$(map::size user_info)
40-
echo "Number of entries: $size"
54+
size=$(map::size user)
55+
echo "size: $size"
56+
57+
map::make test "
58+
[name] = John Doe
59+
[age] = 30
60+
[city] = New York
61+
"
62+
63+
map::clear test
64+
map::print test
65+
map::keys test
66+
map::size test

0 commit comments

Comments
 (0)