Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/acronym/.meta/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0
1.7.1
7 changes: 7 additions & 0 deletions exercises/acronym/acronym_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@
[[ "$status" -eq 0 ]]
[[ "$output" == "TRNT" ]]
}

@test "contains shell globbing character" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
run bash acronym.sh "Two * Words"
[[ "$status" -eq 0 ]]
[[ "$output" == "TW" ]]
}
5 changes: 2 additions & 3 deletions exercises/acronym/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ if [ "$#" -ne 1 ]; then
exit 1
fi

phrase=$(echo "$1" | tr '-' ' ')
set -f -- junk $phrase
shift
phrase=$(echo "$1" | tr -s '*-' ' ')
set -f -- $phrase

shopt -s extglob
for word; do
Expand Down
2 changes: 1 addition & 1 deletion exercises/pig-latin/.meta/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.2.1
2 changes: 1 addition & 1 deletion exercises/pig-latin/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ translate() {
fi
}

main "$@"
main "$@"
8 changes: 8 additions & 0 deletions exercises/pig-latin/pig_latin_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@
[[ $status -eq 0 ]]
[[ $output == "ickquay astfay unray" ]]
}

# danger this way lies
@test "shell globbing" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
run bash pig_latin.sh "pig*"
[[ $status -eq 0 ]]
[[ $output == "ig*pay" ]]
}
2 changes: 1 addition & 1 deletion exercises/proverb/.meta/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
24 changes: 24 additions & 0 deletions exercises/proverb/proverb_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,27 @@ END
[[ $status -eq 0 ]]
[[ $output == "$expected" ]]
}

@test "items with whitespace" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
expected=$(cat <<END
For want of a rusty nail the horse shoe was lost.
And all for the want of a rusty nail.
END
)
run bash proverb.sh "rusty nail" "horse shoe"
[[ $status -eq 0 ]]
[[ $output == "$expected" ]]
}

@test "shell globbing character" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
expected=$(cat <<END
For want of a quotes the * was lost.
And all for the want of a quotes.
END
)
run bash proverb.sh quotes "*"
[[ $status -eq 0 ]]
[[ $output == "$expected" ]]
}
2 changes: 1 addition & 1 deletion exercises/resistor-color-duo/.meta/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
2.1.0
5 changes: 3 additions & 2 deletions exercises/resistor-color-duo/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ code() {
if [[ -n $code ]]; then
echo "$code"
else
echo "invalid color" >&2
echo "invalid color: $1" >&2
return 1
fi
}

# silently ignore extra colors
result=""
for color; do
for color in "$1" "$2"; do
if code=$(code "$color"); then
result+="$code"
else
Expand Down
9 changes: 8 additions & 1 deletion exercises/resistor-color-duo/resistor_color_duo_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@
[[ $BATS_RUN_SKIPPED == true ]] || skip
run bash resistor_color_duo.sh foo
[[ $status -eq 1 ]]
[[ $output == "invalid color" ]]
[[ $output == *"invalid color"* ]]
}

@test "ignore too many colors" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
run bash resistor_color_duo.sh green brown orange
[[ $status -eq 0 ]]
[[ $output == "51" ]]
}
2 changes: 1 addition & 1 deletion exercises/word-count/.meta/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.0
1.4.1
2 changes: 1 addition & 1 deletion exercises/word-count/example.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

init_var=$(echo -e "$1" | tr -d '!@$%^&:.')
init_var=$(echo -e "$1" | tr -d '*!@$%^&:.')
preprocessed_var=$(echo "${init_var//[$'\n,']/ }" | tr '[:upper:]' '[:lower:]')

read -r -a words <<< "$preprocessed_var"
Expand Down
9 changes: 9 additions & 0 deletions exercises/word-count/word_count_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,12 @@
[[ $(wc -l <<< "$output") -eq 3 ]]
}

@test "contains shell globbing character" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
run bash word_count.sh "two * words"
[[ $status -eq 0 ]]
echo "$output" | grep -qFx "two: 1"
echo "$output" | grep -qFx "words: 1"
[[ $(wc -l <<< "$output") -eq 2 ]]
}