File tree Expand file tree Collapse file tree 5 files changed +85
-326
lines changed Expand file tree Collapse file tree 5 files changed +85
-326
lines changed Original file line number Diff line number Diff line change 18
18
- name : Run shunit2 tests
19
19
uses : sudo-bot/action-shunit2@latest
20
20
with :
21
- cli : " ./tests /bash-map.test.sh"
21
+ cli : " ./test /bash-map.test.sh"
22
22
23
23
shellcheck :
24
24
name : Run ShellCheck
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ map::make items "
10
10
[grape] = 3.99
11
11
"
12
12
13
- # Create a map for a shopping cart
14
13
map::make cart "
15
14
[apple] = 3
16
15
[orange] = 4
Original file line number Diff line number Diff line change @@ -4,37 +4,63 @@ script_dir="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
4
4
source " ${script_dir%/* } /src/bash-map.sh"
5
5
6
6
# Create a new map
7
- map::make user_info "
7
+ map::make user "
8
8
[name] = John Doe
9
9
[age] = 30
10
10
[city] = New York
11
11
"
12
12
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
16
28
17
29
# Get and display a specific value
18
- name=$( map::get user_info name)
30
+ name=$( map::get user name)
19
31
echo " Name: $name "
20
32
21
33
# Update a value
22
- map::set user_info age 31
34
+ echo " Updating [age] to 31..."
35
+ map::set user age 31
23
36
24
37
# 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"
26
40
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
33
43
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 "
37
52
38
53
# 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
You can’t perform that action at this time.
0 commit comments