File tree Expand file tree Collapse file tree 10 files changed +83
-72
lines changed Expand file tree Collapse file tree 10 files changed +83
-72
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ assert [ "$REPLY" = rho ]
47
47
48
48
## Installation
49
49
50
- STATUS: ALPHA
50
+ STATUS: BETA
51
51
52
52
``` sh
53
53
echo " dependencies = [ 'hyperupcall/bash-object' ]" > ' bpm.toml'
Original file line number Diff line number Diff line change 1
- #! /usr/bin/env bash
1
+ #! /usr/bin/env bats
2
2
3
3
load ' ./util/init.sh'
4
+
5
+ @test " Error if getting more than a string" {
6
+ declare -A OBJECT=()
7
+ str=' golf'
8
+
9
+ bobject set-string --ref OBJECT ' .foxtrot' str
10
+ run bobject get-string --ref OBJECT ' .foxtrot.omega'
11
+
12
+ assert_failure
13
+ assert_line -p ' ERROR_NOT_FOUND'
14
+ assert_line -p " The passed querytree implies that 'foxtrot' accesses an object or array, but a string with a value of 'golf' was found instead"
15
+ }
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bats
2
+
3
+ load ' ./util/init.sh'
4
+
5
+ @test " Correctly gets object" {
6
+ declare -A inner_object=([cool]=' Wolf 359' )
7
+ declare -A OBJ=([stars]=$' \x1C\x1D type=object;&inner_object' )
8
+
9
+ bobject set-object --value
10
+ bobject get-object --value ' OBJ' ' .stars'
11
+ assert [ " ${REPLY[cool]} " = ' Wolf 359' ]
12
+
13
+ bobject get-string --value ' OBJ' ' .stars.cool'
14
+ assert [ " $REPLY " = ' Wolf 359' ]
15
+ }
File renamed without changes.
File renamed without changes.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2
2
3
3
load ' ./util/init.sh'
4
4
5
+ # object
6
+ @test " Correctly sets object" {
7
+ declare -A obj=([omicron]=pi [rho]=sigma [tau]=upsilon)
8
+ declare -A OBJECT=()
9
+
10
+ bobject set-object --ref ' OBJECT' ' .obj' obj
11
+
12
+ bobject get-object --value ' OBJECT' ' .obj'
13
+ assert [ ${# REPLY[@]} -eq 3 ]
14
+ assert [ " ${REPLY[omicron]} " = pi ]
15
+ assert [ " ${REPLY[rho]} " = sigma ]
16
+ assert [ " ${REPLY[tau]} " = upsilon ]
17
+
18
+ bobject get-string --value ' OBJECT' ' .obj.rho'
19
+ assert [ " $REPLY " = sigma ]
20
+ }
21
+
22
+ # array
23
+ @test " Correctly sets array" {
24
+ declare -a arr=(omicron pi rho)
25
+ declare -A OBJECT=()
26
+
27
+ bobject set-array --ref ' OBJECT' ' .arr' arr
28
+
29
+ bobject get-array --value ' OBJECT' ' .arr'
30
+ assert [ ${# REPLY[@]} -eq 3 ]
31
+ assert [ " ${REPLY[0]} " = omicron ]
32
+ assert [ " ${REPLY[1]} " = pi ]
33
+ assert [ " ${REPLY[2]} " = rho ]
34
+
35
+ bobject get-string --value ' OBJECT' ' .["arr"].[0]'
36
+ assert [ " $REPLY " = omicron ]
37
+
38
+ bobject get-string --value ' OBJECT' ' .["arr"].[1]'
39
+ assert [ " $REPLY " = pi ]
40
+
41
+ bobject get-string --value ' OBJECT' ' .["arr"].[2]'
42
+ assert [ " $REPLY " = rho ]
43
+ }
44
+
45
+ # string
5
46
@test " Correctly sets string at root" {
6
47
declare -A OBJECT=()
7
48
str=' my_value'
Original file line number Diff line number Diff line change 1
- # shellcheck shell=bash
1
+ #! /usr/bin/env bats
2
2
3
3
load ' ./util/init.sh'
4
4
5
+ @test " Error if setting more than a string" {
6
+ declare -A OBJECT=()
7
+ str=' golf'
8
+
9
+ bobject set-string --ref OBJECT ' .foxtrot' str
10
+ run bobject set-string --ref OBJECT ' .foxtrot.omega' str
11
+
12
+ assert_failure
13
+ assert_line -p ' ERROR_NOT_FOUND'
14
+ assert_line -p " The passed querytree implies that 'foxtrot' accesses an object or array, but a string with a value of 'golf' was found instead"
15
+ }
16
+
5
17
@test " Error if random variable already exists for set-object" {
6
18
declare -A OBJECT=()
7
19
declare -A obj=()
@@ -33,28 +45,3 @@ load './util/init.sh'
33
45
assert_output -p ' ERROR_INTERNAL'
34
46
assert_output -p " Variable 'some_other_var' exists, but it shouldn't"
35
47
}
36
-
37
- @test " Error if setting more than a string" {
38
- declare -A OBJECT=()
39
- str=' golf'
40
-
41
- bobject set-string --ref OBJECT ' .foxtrot' str
42
- run bobject set-string --ref OBJECT ' .foxtrot.omega' str
43
-
44
- assert_failure
45
- assert_line -p ' ERROR_NOT_FOUND'
46
- assert_line -p " The passed querytree implies that 'foxtrot' accesses an object or array, but a string with a value of 'golf' was found instead"
47
- }
48
-
49
- # TODO: move
50
- @test " Error if getting more than a string" {
51
- declare -A OBJECT=()
52
- str=' golf'
53
-
54
- bobject set-string --ref OBJECT ' .foxtrot' str
55
- run bobject get-string --ref OBJECT ' .foxtrot.omega'
56
-
57
- assert_failure
58
- assert_line -p ' ERROR_NOT_FOUND'
59
- assert_line -p " The passed querytree implies that 'foxtrot' accesses an object or array, but a string with a value of 'golf' was found instead"
60
- }
You can’t perform that action at this time.
0 commit comments