aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-01-20 23:45:36 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-01-20 23:45:36 +0100
commitf663999eccd693ddbfd581a51213b816c461f092 (patch)
tree5759e5410a34673a3726e34cbd0ce60adc95dd03 /src
parent1626c2bb70e369c25bbd0fe713bf03e3ff52dff6 (diff)
downloadsylt-f663999eccd693ddbfd581a51213b816c461f092.tar.gz
add recursive tests
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 82905de..328d3ea 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -169,7 +169,7 @@ mod tests {
simplest: "f := fn {}
f()",
param_1: "f := fn a: int {}
- f(1)",
+ f(1)",
return_1: "f := fn -> int {
ret 1
}
@@ -222,7 +222,28 @@ mod tests {
}
1 + f(2, 3) <=> 6
2 * f(2, 3) <=> 10
- f(2, 3) - (2 + 3) <=> 0"
+ f(2, 3) - (2 + 3) <=> 0",
+ factorial: "factorial : fn int -> int = fn n: int -> int {
+ if n <= 1 {
+ ret 1
+ }
+ ret n * factorial(n - 1)
+ }
+ factorial(5) <=> 120
+ factorial(6) <=> 720
+ factorial(12) <=> 479001600",
+ fibonacci: "fibonacci : fn int -> int = fn n: int -> int {
+ if n == 0 {
+ ret 0
+ } else if n == 1 {
+ ret 1
+ } else if n < 0 {
+ <!>
+ }
+ ret fibonacci(n - 1) + fibonacci(n - 2)
+ }
+ fibonacci(10) <=> 55
+ fibonacci(20) <=> 6765"
);
test_file!(scoping, "tests/scoping.tdy");