Skip to content

Commit dd4afd8

Browse files
committed
refactor: No longer accept flag shorthands to bash_object.parse_filter
The function is only used internally, and it looks (and is) cleaner without a shorthand
1 parent 7533e18 commit dd4afd8

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

pkg/lib/parse.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ bash_object.parse_filter() {
1010
local flag_parser_type=
1111

1212
for arg; do case "$arg" in
13-
-s|--simple)
13+
--simple)
1414
flag_parser_type='simple'
1515
shift ;;
16-
-a|--advanced)
16+
--advanced)
1717
flag_parser_type='advanced'
1818
shift ;;
1919
esac done

tests/parse-filter-advanced.bats

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,157 +3,157 @@
33
load './util/init.sh'
44

55
@test "Advanced errors with no start dot 1" {
6-
run bash_object.parse_filter -s ''
6+
run bash_object.parse_filter --simple ''
77

88
assert_failure
99
assert_line -p "Filter must begin with a dot"
1010
}
1111

1212
@test "Advanced errors with no start dot 2" {
13-
run bash_object.parse_filter -a '["sub"]'
13+
run bash_object.parse_filter --advanced '["sub"]'
1414

1515
assert_failure
1616
assert_line -p "Filter must begin with a dot"
1717
}
1818

1919
@test "Advanced errors with missing dot" {
20-
run bash_object.parse_filter -a '.["one"]["two"]'
20+
run bash_object.parse_filter --advanced '.["one"]["two"]'
2121

2222
assert_failure
2323
assert_line -p "Each part in a filter must be deliminated by a dot"
2424
}
2525

2626
@test "Advanced errors with trailing dot" {
27-
run bash_object.parse_filter -a '.["one"].["ab"].'
27+
run bash_object.parse_filter --advanced '.["one"].["ab"].'
2828

2929
assert_failure
3030
assert_line -p "A dot MUST be followed by an opening bracket"
3131
}
3232

3333
@test "Advanced errors with trailing double dot" {
34-
run bash_object.parse_filter -a '.["one"].["ab"]..'
34+
run bash_object.parse_filter --advanced '.["one"].["ab"]..'
3535

3636
assert_failure
3737
assert_line -p "A dot MUST be followed by an opening bracket"
3838
}
3939

4040
@test "Advanced errors on incomplete 1" {
41-
run bash_object.parse_filter -a '.['
41+
run bash_object.parse_filter --advanced '.['
4242

4343
assert_failure
4444
assert_line -p "A number or opening quote must follow an open bracket"
4545
}
4646

4747
@test "Advanced errors on incomplete 2" {
48-
run bash_object.parse_filter -a '.["'
48+
run bash_object.parse_filter --advanced '.["'
4949

5050
assert_failure
5151
assert_line -p "Filter is not complete"
5252
}
5353

5454
@test "Advanced errors on incomplete 3" {
55-
run bash_object.parse_filter -a '.[""'
55+
run bash_object.parse_filter --advanced '.[""'
5656

5757
assert_failure
5858
assert_line -p "Key cannot be empty"
5959
}
6060

6161
@test "Advanced errors on incomplete 4" {
62-
run bash_object.parse_filter -a '.["bottom"].["'
62+
run bash_object.parse_filter --advanced '.["bottom"].["'
6363

6464
assert_failure
6565
assert_line -p "Filter is not complete"
6666
}
6767

6868
@test "Advanced errors on incomplete 5" {
69-
run bash_object.parse_filter -a '.["top"].[""'
69+
run bash_object.parse_filter --advanced '.["top"].[""'
7070

7171
assert_failure
7272
assert_line -p "Key cannot be empty"
7373
}
7474

7575
@test "Advanced errors on empty key" {
76-
run bash_object.parse_filter -a '.[""]'
76+
run bash_object.parse_filter --advanced '.[""]'
7777

7878
assert_failure
7979
assert_line -p "Key cannot be empty"
8080
}
8181

8282
@test "Advanced errors on empty key as subkey" {
83-
run bash_object.parse_filter -a '.["subkey"].[""]'
83+
run bash_object.parse_filter --advanced '.["subkey"].[""]'
8484

8585
assert_failure
8686
assert_line -p "Key cannot be empty"
8787
}
8888

8989
@test "Advanced errors on empty number key" {
90-
run bash_object.parse_filter -a '.[]'
90+
run bash_object.parse_filter --advanced '.[]'
9191

9292
assert_failure
9393
assert_line -p "Key cannot be empty"
9494
}
9595

9696
@test "Advanced errors on empty key as number subkey" {
97-
run bash_object.parse_filter -a '.["subkey"].[]'
97+
run bash_object.parse_filter --advanced '.["subkey"].[]'
9898

9999
assert_failure
100100
assert_line -p "Key cannot be empty"
101101
}
102102

103103
@test "Correctly parses advanced prop" {
104-
bash_object.parse_filter -a '.["one"]'
104+
bash_object.parse_filter --advanced '.["one"]'
105105

106106
assert [ "${#REPLIES[@]}" -eq 1 ]
107107
assert [ "${REPLIES[0]}" = 'one' ]
108108
}
109109

110110
@test "Correctly parses advanced prop and escape sequence" {
111-
bash_object.parse_filter -a '.["esca\\p\"\]e"]'
111+
bash_object.parse_filter --advanced '.["esca\\p\"\]e"]'
112112

113113
assert [ "${#REPLIES[@]}" -eq 1 ]
114114
assert [ "${REPLIES[0]}" = 'esca\p"]e' ]
115115
}
116116

117117
@test "Correctly parses advanced double prop" {
118-
bash_object.parse_filter -a '.["aone"].["a\\two"]'
118+
bash_object.parse_filter --advanced '.["aone"].["a\\two"]'
119119

120120
assert [ "${#REPLIES[@]}" -eq 2 ]
121121
assert [ "${REPLIES[0]}" = 'aone' ]
122122
assert [ "${REPLIES[1]}" = 'a\two' ]
123123
}
124124

125125
@test "Correctly parses advanced number single" {
126-
bash_object.parse_filter -a '.[3]'
126+
bash_object.parse_filter --advanced '.[3]'
127127

128128
assert [ "${#REPLIES[@]}" -eq 1 ]
129129
assert [ "${REPLIES[0]}" = $'\x1C3' ]
130130
}
131131

132132
@test "Correctly parses advanced number" {
133-
bash_object.parse_filter -a '.[341]'
133+
bash_object.parse_filter --advanced '.[341]'
134134

135135
assert [ "${#REPLIES[@]}" -eq 1 ]
136136
assert [ "${REPLIES[0]}" = $'\x1C341' ]
137137
}
138138

139139
@test "Correctly parses advanced number nested" {
140-
bash_object.parse_filter -a '.[341].[7]'
140+
bash_object.parse_filter --advanced '.[341].[7]'
141141

142142
assert [ "${#REPLIES[@]}" -eq 2 ]
143143
assert [ "${REPLIES[0]}" = $'\x1C341' ]
144144
assert [ "${REPLIES[1]}" = $'\x1C7' ]
145145
}
146146

147147
@test "Correctly parses advanced number then string" {
148-
bash_object.parse_filter -a '.[3].["subprop"]'
148+
bash_object.parse_filter --advanced '.[3].["subprop"]'
149149

150150
assert [ "${#REPLIES[@]}" -eq 2 ]
151151
assert [ "${REPLIES[0]}" = $'\x1C3' ]
152152
assert [ "${REPLIES[1]}" = 'subprop' ]
153153
}
154154

155155
@test "Correctly parses advanced string then number" {
156-
bash_object.parse_filter -a '.["subprop"].[9]'
156+
bash_object.parse_filter --advanced '.["subprop"].[9]'
157157

158158
assert [ "${#REPLIES[@]}" -eq 2 ]
159159
assert [ "${REPLIES[0]}" = 'subprop' ]

tests/parse-filter-simple.bats

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,50 @@
33
load './util/init.sh'
44

55
@test "Simple errors on no starting dot 1" {
6-
run bash_object.parse_filter -s ''
6+
run bash_object.parse_filter --simple ''
77

88
assert_failure
99
assert_line -p "Filter must begin with a dot"
1010
}
1111

1212
@test "Simple errors on no starting dot 2" {
13-
run bash_object.parse_filter -s 'something.here'
13+
run bash_object.parse_filter --simple 'something.here'
1414

1515
assert_failure
1616
assert_line -p "Filter must begin with a dot"
1717
}
1818

1919
@test "Simple succeeds on period" {
20-
bash_object.parse_filter -s '.'
20+
bash_object.parse_filter --simple '.'
2121

2222
assert [ "${#REPLIES[@]}" -eq 0 ]
2323
}
2424

2525
@test "Simple succeeds on key" {
26-
bash_object.parse_filter -s '.my_key'
26+
bash_object.parse_filter --simple '.my_key'
2727

2828
assert [ "${#REPLIES[@]}" -eq 1 ]
2929
assert [ "${REPLIES[0]}" = 'my_key' ]
3030
}
3131

3232
@test "Simple succeeds on key and subkey" {
33-
bash_object.parse_filter -s '.my_key.sub_key'
33+
bash_object.parse_filter --simple '.my_key.sub_key'
3434

3535
assert [ "${#REPLIES[@]}" -eq 2 ]
3636
assert [ "${REPLIES[0]}" = 'my_key' ]
3737
assert [ "${REPLIES[1]}" = 'sub_key' ]
3838
}
3939

4040
@test "Simple succeeds on key with weird characters" {
41-
bash_object.parse_filter -s '.12fNe- =='\\n'\+_m}\y.su/b []"_ke]y'\'
41+
bash_object.parse_filter --simple '.12fNe- =='\\n'\+_m}\y.su/b []"_ke]y'\'
4242

4343
assert [ "${#REPLIES[@]}" -eq 2 ]
4444
assert [ "${REPLIES[0]}" = '12fNe- =='\\n'\+_m}\y' ]
4545
assert [ "${REPLIES[1]}" = 'su/b []"_ke]y'\' ]
4646
}
4747

4848
@test "Simple succeeds on key with many periods" {
49-
bash_object.parse_filter -s '...lima...mike.....oscar'
49+
bash_object.parse_filter --simple '...lima...mike.....oscar'
5050

5151
assert [ "${#REPLIES[@]}" -eq 3 ]
5252
assert [ "${REPLIES[0]}" = 'lima' ]

0 commit comments

Comments
 (0)