From e873eb3d2dec2129daab1459a22325fe4481ed57 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Mon, 3 Feb 2025 17:55:40 +0100 Subject: [PATCH] chore: add some more tests for arithmetic expressions (#220) --- crates/tests/test-data/arithmetic.sh | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 crates/tests/test-data/arithmetic.sh diff --git a/crates/tests/test-data/arithmetic.sh b/crates/tests/test-data/arithmetic.sh new file mode 100644 index 0000000..74ae387 --- /dev/null +++ b/crates/tests/test-data/arithmetic.sh @@ -0,0 +1,52 @@ +# Test basic arithmetic +> echo $((2 + 5)) +7 + +> echo $((10 - 3)) +7 + +> echo $((3 * 4)) +12 + +> echo $((15 / 3)) +5 + +# Test operator precedence +> echo $((2 + 3 * 4)) +14 + +# Fails +# > echo $(((2 + 3) * 4)) +# 20 + +# Test with variables +> export NUM=5 +> echo $((NUM + 3)) +8 + +> export A=2 +> export B=3 +> echo $((A * B + 1)) +7 + +# # Test increment/decrement NOT IMPLEMENTED YET! +# > export COUNT=1 +# > echo $((COUNT++)) +# 1 +# > echo $COUNT +# 2 + +# > export X=5 +# > echo $((--X)) +# 4 + +# Test complex expressions +> export BASE=2 +> echo $((BASE ** 3 + 1)) +9 + +# Test division and modulo +> echo $((10 / 3)) +3 +> echo $((10 % 3)) +1 \ No newline at end of file