File tree Expand file tree Collapse file tree 6 files changed +28
-19
lines changed Expand file tree Collapse file tree 6 files changed +28
-19
lines changed Original file line number Diff line number Diff line change 1
1
# shellcheck shell=bash
2
2
3
- if [ -n " ${DEBUG+x} " ]; then
4
- trap ' bash_toml.trap_error' ' ERR'
5
- bash_toml.trap_error () {
6
- bash_toml.debug
7
- }
8
- fi
9
-
10
3
for f in " $BASH_TOML_LIB_DIR " /util/?* .sh; do
11
4
# shellcheck disable=SC1090
12
5
source " $f "
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ bash_toml.do_parse() {
6
6
7
7
declare char=
8
8
declare mode=' MODE_DEFAULT'
9
- declare -i PARSER_LINE_NUMBER=0
9
+ declare -i PARSER_LINE_NUMBER=1
10
10
declare -i PARSER_COLUMN_NUMBER=0
11
11
12
12
while IFS= read -rn 1 char; do
@@ -78,7 +78,7 @@ bash_toml.do_parse() {
78
78
bash_toml.parse_fail ' KEY_INVALID'
79
79
return 1
80
80
else
81
- bash_toml.parse_fail ' UNEXPECTED_BRANCH '
81
+ bash_toml.parse_fail ' UNEXPECTED_CHARACTER ' " Char ' $char ' is not valid in toml bare keys "
82
82
return 1
83
83
fi
84
84
;;
Original file line number Diff line number Diff line change @@ -10,14 +10,14 @@ declare -gA BASH_TOML_ERRORS=(
10
10
[VALUE_STRING_INVALID]=' The value was not valid'
11
11
)
12
12
13
- declare -a token_history =()
13
+ declare -a BASH_TOKEN_HISTORY =()
14
14
15
15
# @description Appends to token history for improved error insight
16
16
bash_toml.token_history_add () {
17
17
local str=
18
- printf -v str ' %s\n ' " $mode ($char ) at $PARSER_LINE_NUMBER :$PARSER_COLUMN_NUMBER "
18
+ printf -v str ' %s' " $mode ($char ) at $PARSER_LINE_NUMBER :$PARSER_COLUMN_NUMBER "
19
19
20
- token_history +=(" $str " )
20
+ BASH_TOKEN_HISTORY +=(" $str " )
21
21
22
22
if [ -n " ${DEBUG_BASH_TOML+x} " ]; then
23
23
if [ -n " ${BATS_RUN_TMPDIR+x} " ]; then
@@ -32,6 +32,10 @@ bash_toml.parse_fail() {
32
32
local error_key=" $1 "
33
33
local error_context=" $2 "
34
34
35
+ if [ -z " $error_context " ]; then
36
+ error_context=" <empty>"
37
+ fi
38
+
35
39
local error_message=" ${BASH_TOML_ERRORS["$error_key"]} "
36
40
37
41
local error_output=
@@ -41,8 +45,8 @@ bash_toml.parse_fail() {
41
45
-> context: %s
42
46
-> history:' " $error_key " " $error_message " " $error_context "
43
47
44
- for history_item in " ${token_history [@]} " ; do
45
- printf -v error_output ' %s\n - %s\n ' " $error_output " " $history_item "
48
+ for history_item in " ${BASH_TOKEN_HISTORY [@]} " ; do
49
+ printf -v error_output ' %s\n - %s' " $error_output " " $history_item "
46
50
done
47
51
48
52
if [ " $TOML_MANUAL_ERROR " = yes ]; then
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bats
2
+
3
+ load ' ./util/init.sh'
4
+
5
+ @test " fails on invalid key 4" {
6
+ run bash_toml.do_parse << -"EOF "
7
+ fox=
8
+ EOF
9
+
10
+ assert_failure
11
+ assert_output -p ' VALUE_STRING_INVALID'
12
+ }
Original file line number Diff line number Diff line change 2
2
3
3
load ' ./util/init.sh'
4
4
5
- @test " fails on incomplete key" {
5
+ @test " fails on invalid bare key" {
6
6
run bash_toml.do_parse << -"EOF "
7
7
fox
8
8
EOF
@@ -11,7 +11,7 @@ load './util/init.sh'
11
11
assert_output -p ' KEY_INVALID'
12
12
}
13
13
14
- @test " fails on incomplete key 2" {
14
+ @test " fails on invalid bare key 2" {
15
15
run bash_toml.do_parse << -"EOF "
16
16
f ox
17
17
EOF
@@ -20,11 +20,11 @@ load './util/init.sh'
20
20
assert_output -p ' KEY_INVALID'
21
21
}
22
22
23
- @test " fails on incomplete key 3" {
23
+ @test " fails on invalid bare key 3" {
24
24
run bash_toml.do_parse << -"EOF "
25
- fox=
25
+ f!ox
26
26
EOF
27
27
28
28
assert_failure
29
- assert_output -p ' VALUE_STRING_INVALID '
29
+ assert_output -p ' UNEXPECTED_CHARACTER '
30
30
}
You can’t perform that action at this time.
0 commit comments