Add more functional tests
This commit is contained in:
parent
363334967a
commit
39578c9478
9 changed files with 76 additions and 20 deletions
|
|
@ -1,5 +0,0 @@
|
|||
=== script ===
|
||||
print "Hello World!"
|
||||
|
||||
=== output ===
|
||||
Hello World!
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
=== script ===
|
||||
fac = {
|
||||
0 -> 1
|
||||
n -> * n (fac (--n ))
|
||||
}
|
||||
|
||||
print (fac 10)
|
||||
|
||||
=== output ===
|
||||
3628800
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
19
src/functional-tests/deconstruct.at
Normal file
19
src/functional-tests/deconstruct.at
Normal 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
|
||||
10
src/functional-tests/factorial.at
Normal file
10
src/functional-tests/factorial.at
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
===== script =====
|
||||
fac := {
|
||||
0 -> 1
|
||||
n -> * n (fac (- n 1))
|
||||
}
|
||||
|
||||
print (fac 10)
|
||||
|
||||
===== output =====
|
||||
3628800
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
14
src/functional-tests/map.at
Normal file
14
src/functional-tests/map.at
Normal 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
|
||||
]
|
||||
22
src/functional-tests/shadowing.at
Normal file
22
src/functional-tests/shadowing.at
Normal 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
|
||||
Loading…
Reference in a new issue