Skip to content

Commit 4351b11

Browse files
committed
Account for parentheses in syntax theme setting assignment.
1 parent 338cc37 commit 4351b11

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

Diff for: nb

+22-9
Original file line numberDiff line numberDiff line change
@@ -24639,20 +24639,33 @@ HEREDOC
2463924639
if ! hash bat 2>/dev/null
2464024640
then
2464124641
printf "bat required: https://github.com/sharkdp/bat\\n"
24642+
elif [[ -z "${2:-}" ]]
24643+
then
24644+
return 1
2464224645
else
2464324646
local _theme_list=
2464424647
_theme_list=($(bat --list-themes --color never))
2464524648

24646-
if _contains "${2:-}" "${_theme_list[@]}"
24647-
then
24648-
return 0
24649-
else
24650-
_warn printf \
24651-
"%s must be one of the available themes.\\n" \
24652-
"${1}"
24649+
local __theme=
24650+
for __theme in "${_theme_list[@]}"
24651+
do
24652+
if [[ "${2}" =~ \( ]]
24653+
then
24654+
if [[ "${2}" == "${__theme:-}" ]]
24655+
then
24656+
return 0
24657+
fi
24658+
elif [[ "${2}" =~ ^${__theme%% (*} ]]
24659+
then
24660+
return 0
24661+
fi
24662+
done
2465324663

24654-
return 1
24655-
fi
24664+
_warn printf \
24665+
"%s must be one of the available themes.\\n" \
24666+
"${1}"
24667+
24668+
return 1
2465624669
fi
2465724670
else
2465824671
return 0

Diff for: test/settings.bats

+18-1
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ skip "Determine how to test interactive prompt."
11841184
[[ "$("${_NB}" settings get NB_SYNTAX_THEME)" == "Monokai Extended" ]]
11851185
}
11861186

1187-
@test "'settings set syntax' with valid argument sets and exits." {
1187+
@test "'settings set syntax' with valid 'Solarized (dark)' argument sets and exits." {
11881188
{
11891189
"${_NB}" init
11901190
}
@@ -1201,6 +1201,23 @@ skip "Determine how to test interactive prompt."
12011201
[[ "$("${_NB}" settings get NB_SYNTAX_THEME)" == "Solarized (dark)" ]]
12021202
}
12031203

1204+
@test "'settings set syntax' with valid 'Solarized (light)' argument sets and exits." {
1205+
{
1206+
"${_NB}" init
1207+
}
1208+
1209+
run "${_NB}" settings set syntax "Solarized (light)"
1210+
1211+
printf "\${status}: '%s'\\n" "${status}"
1212+
printf "\${output}: '%s'\\n" "${output}"
1213+
1214+
[[ ${status} -eq 0 ]]
1215+
[[ "${output}" =~ NB_SYNTAX_THEME ]]
1216+
[[ "${output}" =~ set\ to\ ]]
1217+
[[ "${output}" =~ Solarized\ \(light\) ]]
1218+
[[ "$("${_NB}" settings get NB_SYNTAX_THEME)" == "Solarized (light)" ]]
1219+
}
1220+
12041221
@test "'settings set NB_SYNTAX_THEME' with invalid argument exits with error." {
12051222
{
12061223
"${_NB}" init

0 commit comments

Comments
 (0)