Skip to content

Commit

Permalink
Add tests for matching regex
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoRSeifert committed Nov 22, 2024
1 parent 06f4528 commit d132882
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ exit" | ./example | grep -E "(ans =|Can't evaluate function/operator \".*\":)")
esac
}

function match_regex() {
input="$1"
regex="$2"

output=$(echo "$input
exit" | ./example | grep -E "(ans =|Can't evaluate function/operator \".*\":)")

if echo "$output" | egrep -q "$regex"; then
printf "\e[32mTest passed for input $input\e[0m\n"
else
printf "\e[31mTest failed for input $input: regex did not match\e[0m\n"
exit 1
fi
}

# Arithmetic tests
test_eval "2 + 2" "4"
test_eval "55 * 33" "1815"
Expand Down Expand Up @@ -329,5 +344,8 @@ test_eval 'weekday("2019-03-21", "invalidlocale")' 'The chosen locale is not sup
test_eval 'weekday("2024-32-21")' 'Invalid format on the parameter(s). Please use two "yyyy-mm-dd" for dates OR two "yyyy-mm-ddTHH:MM" for date_times.'
test_eval 'weekday("2024-09-17", "en", "one too many params")' 'Too many parameters passed to function "weekday".'

# Regex match test
match_regex 'current_time(5)' '\b([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\b'

echo "All tests passed!"

0 comments on commit d132882

Please sign in to comment.