Add integration tests
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
tests/*.got
|
||||
/target
|
||||
|
||||
28
runtests.sh
Executable file
28
runtests.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
function die() {
|
||||
local msg
|
||||
msg="$1"
|
||||
echo "$msg - exiting"
|
||||
exit 1
|
||||
}
|
||||
|
||||
here="$(realpath "$(dirname "$0")")"
|
||||
tests="$here/tests"
|
||||
flags="--quiet --release"
|
||||
|
||||
echo "building"
|
||||
cargo build $flags || die "build failed"
|
||||
|
||||
echo "testing"
|
||||
find "$tests" -type f -name '*.npp' | while read f; do
|
||||
result="$(cargo run $flags -- "$f")"
|
||||
|
||||
echo "$result" > "$f.got"
|
||||
|
||||
if [[ "$result" != "$(cat "$f.expect")" ]]; then
|
||||
echo "$f did not match expected output"
|
||||
diff "$f.got" "$f.expect"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "done"
|
||||
101
tests/int.npp
Normal file
101
tests/int.npp
Normal file
@@ -0,0 +1,101 @@
|
||||
# Int type operator and function tests
|
||||
|
||||
# assign
|
||||
a = 10
|
||||
b = 20
|
||||
|
||||
println(a)
|
||||
println(b)
|
||||
|
||||
# __add__
|
||||
println("__add__")
|
||||
println(1 + 1)
|
||||
println(1 + 2 + 3)
|
||||
println(1938 + 481)
|
||||
println(a + b)
|
||||
println(b + a)
|
||||
|
||||
# __sub__
|
||||
println("__sub__")
|
||||
println(1 - 2)
|
||||
println(2 - 1)
|
||||
println(0 - 10)
|
||||
println(185 - 86171)
|
||||
println(a - b)
|
||||
println(b - a)
|
||||
|
||||
# __mul__
|
||||
println("__mul__")
|
||||
println(1 * 1)
|
||||
println(1 * -1)
|
||||
println(-1 * 1)
|
||||
println(0 * -1)
|
||||
println(-1 * 0)
|
||||
println(2 * 32768)
|
||||
println(2 * 2 * 2 * 2)
|
||||
println(999 * 999)
|
||||
println(a * b)
|
||||
println(a * a * b * b)
|
||||
|
||||
# __div__
|
||||
println("__div__")
|
||||
println(1 / 1)
|
||||
println(1 / 2)
|
||||
println(2 / 1)
|
||||
println(363 / 3)
|
||||
println(3 / 363)
|
||||
println(a / b)
|
||||
println(b / a)
|
||||
|
||||
# __gt__
|
||||
println("__gt__")
|
||||
println(1 > 2)
|
||||
println(2 > 1)
|
||||
println(5831 > -391)
|
||||
println(-34888 > 1000)
|
||||
println(1 > 1)
|
||||
println(2 > 2)
|
||||
|
||||
# __ge__
|
||||
println("__ge__")
|
||||
println(1 >= 2)
|
||||
println(2 >= 1)
|
||||
println(81001 >= 81001)
|
||||
println(-81001 >= 1000)
|
||||
println(1 >= 1)
|
||||
println(2 >= 2)
|
||||
|
||||
# __lt__
|
||||
println("__lt__")
|
||||
println(1 < 2)
|
||||
println(2 < 1)
|
||||
println(81001 < 81001)
|
||||
println(-81001 < 1000)
|
||||
println(1 < 1)
|
||||
println(2 < 2)
|
||||
|
||||
# __le__
|
||||
println("__le__")
|
||||
println(1 <= 2)
|
||||
println(2 <= 1)
|
||||
println(81001 <= 81001)
|
||||
println(-81001 <= 1000)
|
||||
println(1 <= 1)
|
||||
println(2 <= 2)
|
||||
|
||||
# __pos__
|
||||
println("__pos__")
|
||||
println(+1)
|
||||
println(+(-1))
|
||||
println(+(10 - 20))
|
||||
println(+(20 - 10))
|
||||
|
||||
# __neg__
|
||||
println("__neg__")
|
||||
println(-1)
|
||||
println(--1)
|
||||
println(---1)
|
||||
println(----1)
|
||||
println(10 - -20)
|
||||
println(-10 - 20)
|
||||
println(-10 - -20)
|
||||
75
tests/int.npp.expect
Normal file
75
tests/int.npp.expect
Normal file
@@ -0,0 +1,75 @@
|
||||
10
|
||||
20
|
||||
__add__
|
||||
2
|
||||
6
|
||||
2419
|
||||
30
|
||||
30
|
||||
__sub__
|
||||
-1
|
||||
1
|
||||
-10
|
||||
-85986
|
||||
-10
|
||||
10
|
||||
__mul__
|
||||
1
|
||||
-1
|
||||
-1
|
||||
0
|
||||
0
|
||||
65536
|
||||
16
|
||||
998001
|
||||
200
|
||||
40000
|
||||
__div__
|
||||
1
|
||||
0
|
||||
2
|
||||
121
|
||||
0
|
||||
0
|
||||
2
|
||||
__gt__
|
||||
false
|
||||
true
|
||||
true
|
||||
false
|
||||
false
|
||||
false
|
||||
__ge__
|
||||
false
|
||||
true
|
||||
true
|
||||
false
|
||||
true
|
||||
true
|
||||
__lt__
|
||||
true
|
||||
false
|
||||
false
|
||||
true
|
||||
false
|
||||
false
|
||||
__le__
|
||||
true
|
||||
false
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
__pos__
|
||||
1
|
||||
1
|
||||
10
|
||||
10
|
||||
__neg__
|
||||
-1
|
||||
1
|
||||
-1
|
||||
1
|
||||
30
|
||||
-30
|
||||
10
|
||||
40
tests/str.npp
Normal file
40
tests/str.npp
Normal file
@@ -0,0 +1,40 @@
|
||||
# Str type operator and function tests
|
||||
|
||||
a = "asdf"
|
||||
b = 'This is a longer sentence'
|
||||
c = 'the quick brown fox jumped over the lazy dog\'s escaped characters'
|
||||
|
||||
# to_str
|
||||
println("to_str")
|
||||
println(a)
|
||||
println(a.to_str())
|
||||
println(b)
|
||||
println(b.to_str())
|
||||
println(c)
|
||||
println(c.to_str())
|
||||
|
||||
# to_repr
|
||||
println("to_repr")
|
||||
println("to_repr".to_repr())
|
||||
println(a.to_repr())
|
||||
println(b.to_repr())
|
||||
println(c.to_repr())
|
||||
println('I would\ninclude a\nmultiline string if\nit wasn\'t such a\npain to\ntest in the\n.expect file'.to_repr())
|
||||
|
||||
# len
|
||||
println("len")
|
||||
println(a.len())
|
||||
println(b.len())
|
||||
println(c.len())
|
||||
|
||||
# __add__
|
||||
println("__add__")
|
||||
println(a + a)
|
||||
println(a + a + a)
|
||||
println(a + b)
|
||||
println(b + a)
|
||||
# __mul__
|
||||
println("__mul__")
|
||||
println(a * 4)
|
||||
println(b * 5)
|
||||
println((a * 6).to_repr())
|
||||
26
tests/str.npp.expect
Normal file
26
tests/str.npp.expect
Normal file
@@ -0,0 +1,26 @@
|
||||
to_str
|
||||
asdf
|
||||
asdf
|
||||
This is a longer sentence
|
||||
This is a longer sentence
|
||||
the quick brown fox jumped over the lazy dog's escaped characters
|
||||
the quick brown fox jumped over the lazy dog's escaped characters
|
||||
to_repr
|
||||
'to_repr'
|
||||
'asdf'
|
||||
'This is a longer sentence'
|
||||
'the quick brown fox jumped over the lazy dog\'s escaped characters'
|
||||
'I would\ninclude a\nmultiline string if\nit wasn\'t such a\npain to\ntest in the\n.expect file'
|
||||
len
|
||||
4
|
||||
25
|
||||
65
|
||||
__add__
|
||||
asdfasdf
|
||||
asdfasdfasdf
|
||||
asdfThis is a longer sentence
|
||||
This is a longer sentenceasdf
|
||||
__mul__
|
||||
asdfasdfasdfasdf
|
||||
This is a longer sentenceThis is a longer sentenceThis is a longer sentenceThis is a longer sentenceThis is a longer sentence
|
||||
'asdfasdfasdfasdfasdfasdf'
|
||||
Reference in New Issue
Block a user