Add more functional tests

This commit is contained in:
Laria 2022-10-30 23:07:53 +01:00
parent 363334967a
commit 39578c9478
9 changed files with 76 additions and 20 deletions

View file

@ -1,5 +0,0 @@
=== script ===
print "Hello World!"
=== output ===
Hello World!

View file

@ -1,10 +0,0 @@
=== script ===
fac = {
0 -> 1
n -> * n (fac (--n ))
}
print (fac 10)
=== output ===
3628800

View file

@ -53,6 +53,12 @@ function(functionaltest name)
endfunction()
functionaltest("hello-world")
functionaltest("factorial")
functionaltest("function-const-capture")
functionaltest("function-mutable-capture")
functionaltest("map")
functionaltest("deconstruct")
functionaltest("shadowing")
install(TARGETS apfl DESTINATION lib)
install(TARGETS apfl-bin DESTINATION bin)

View file

@ -0,0 +1,19 @@
===== script =====
[a 1 "Hello" b [_ ~c] d e] = [0 1 "Hello" "world" [1 2 3 4 5] true nil]
print a
print b
print c
print d
print e
===== output =====
0
world
[
2
3
4
5
]
true
nil

View file

@ -0,0 +1,10 @@
===== script =====
fac := {
0 -> 1
n -> * n (fac (- n 1))
}
print (fac 10)
===== output =====
3628800

View file

@ -1,4 +1,4 @@
=== script ===
===== script =====
adder = { a ->
{ b -> + a b }
}
@ -9,6 +9,6 @@ inc = adder 1
print (add10 32)
print (inc 665)
=== output ===
===== output =====
42
666

View file

@ -1,7 +1,7 @@
=== script ===
===== script =====
counter = {
i = 0
{ i = i + 1 }
{ i = + i 1 }
}
c1 = (counter)
@ -15,7 +15,7 @@ print (c2)
print (c1)
print (c2)
=== output ===
===== output =====
1
1
2

View file

@ -0,0 +1,14 @@
===== script =====
map := {
_ [] -> []
f [x ~xs] -> [(f x) ~(map f xs)]
}
print (map {x -> + x 1} [1 2 3])
===== output =====
[
2
3
4
]

View file

@ -0,0 +1,22 @@
===== script =====
foo := 1
bar := 1
({
foo = 2
bar := 2
print "Inside:"
print foo
print bar
})
print "Outside:"
print foo
print bar
===== output =====
Inside:
2
2
Outside:
2
1