diff --git a/mc-test.sh b/mc-test.sh new file mode 100644 index 0000000..7e78b36 --- /dev/null +++ b/mc-test.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +source ./mc + + +function assert() { + echo "TEST: ${FUNCNAME[1]}" + if [[ "$1" == "$2" ]]; then + echo -e "\033[32m" " Pass" "\033[0m" + return 0 + fi + echo -e "\033[31m" " FAIL" "\033[0m" + return 1 +} + +function test_assert() { + local string="one two three four" + assert "$(rest ${string})" "$(rest ${string})" +} +test_assert + +function first_func_returns_first_item() { + local string="one two three four" + assert "$(first ${string})" "one" +} +first_func_returns_first_item + +function second_func_returns_second_item() { + local string="1 2 3 4 5" + assert "$(second ${string})" "2" +} +second_func_returns_second_item + +function rest_func_returns_rest_items() { + local string="one two three four" + assert "$(rest ${string})" "two three four" +} +rest_func_returns_rest_items + +function rest_func_returns_rest_items_from_array() { + local a=(one two "three four") + assert "$(rest ${a[@]})" "two three four" +} +rest_func_returns_rest_items_from_array + +function rest_func_returns_rest_items_from_array_w_spaces() { + local a=(two "three four") + local b=("three four") + assert "$(rest "${a[@]}")" "three four" +} +rest_func_returns_rest_items_from_array_w_spaces + +function rest_func_returns_rest_items_from_array_item_w_spaces_removed() { + local a=("two three" four) + assert "$(rest "${a[@]}")" "four" +} +rest_func_returns_rest_items_from_array_item_w_spaces_removed +