aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2017-11-22 09:58:14 +0100
committerCamil Staps2017-11-22 09:58:14 +0100
commit7644d57ce32264f35175518ed848b39cb0a62f0d (patch)
tree139162303642e3fedb7e434bddece9ae834808be
parentAdd parser (diff)
Test setup
-rw-r--r--Makefile2
-rw-r--r--pf.icl35
-rwxr-xr-xtest.sh14
-rw-r--r--test.tsv15
4 files changed, 46 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 8b2f87f..1516dac 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
BIN:=pf
CLM:=clm
-CLMFLAGS:=-b -IL Platform -IL Generics
+CLMFLAGS:=-nr -IL Platform -IL Generics
.PHONY: all clean
diff --git a/pf.icl b/pf.icl
index a548922..7e0f76f 100644
--- a/pf.icl
+++ b/pf.icl
@@ -1,9 +1,11 @@
module pf
import StdBool
+import StdFile
from StdFunc import flip
import StdMisc
import StdString
+import StdTuple
import GenEq
@@ -14,6 +16,7 @@ from Data.Func import $
import Data.Functor
import Data.List
import Data.Maybe
+import System.CommandLine
import Yard
@@ -153,23 +156,17 @@ moveOutside id (f @ x)
g @ e=:(Ident id) -> Ident "(o)" @ f @ g @ e
moveOutside _ (Lambda x e) = Lambda x e // TODO
-Start = map do
- [ "\\x -> 5"
- , "\\x -> x"
- , "\\x -> y"
- , "\\x y -> x"
- , "\\x y -> y"
- , "\\x y -> 37"
- , "\\x y z -> x"
- , "\\x y z -> y"
- , "\\x y z -> z"
- , "\\x y z -> 37"
- , "\\x y -> x y"
- , "\\x y -> y x"
- , "\\x y -> y 10"
- , "\\f a b c d -> f b c d a"
- , "\\f x -> f x x"
- ]
+Start w
+# ([prg:cmd],w) = getCommandLine w
+| length cmd <> 1 = err ("Usage: " +++ prg +++ " EXPRESSION") w
+# e = parse (hd cmd)
+| isNothing e = err "Expression could not be parsed." w
+# e = fromJust e
+# (io,w) = stdio w
+# io = io <<< "Request: " <<< print e <<< "\n"
+# io = io <<< "Result: " <<< print (optim e) <<< "\n"
+# (_,w) = fclose io w
+= w
where
- do e = (print pe, " ==> ", print (optim pe), "\n")
- where pe = fromJust (parse e)
+ err :: a *World -> *World | <<< a
+ err e w = snd (fclose (stderr <<< e <<< "\n") w)
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..cc6a14b
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+SUCCESS=true
+while IFS=$'\t' read -r req res; do
+ outcome="$(./pf -nt "$req" | grep Result | cut -d' ' -f3-)"
+ if [ "$res" != "$outcome" ]; then
+ echo "Test failed: $req"
+ echo "Expected result: $res"
+ echo "Actual result: $outcome"
+ SUCCESS=false
+ fi
+done < "test.tsv"
+
+$SUCCESS && echo "All tests passed."
diff --git a/test.tsv b/test.tsv
new file mode 100644
index 0000000..bc25a74
--- /dev/null
+++ b/test.tsv
@@ -0,0 +1,15 @@
+\x -> 5 const 5
+\x -> x id
+\x -> y const y
+\x y -> x const
+\x y -> y const id
+\x y -> 37 const (const 37)
+\x y z -> x (o) const const
+\x y z -> y const const
+\x y z -> z const (const id)
+\x y z -> 37 const (const (const 37))
+\x y -> x y id
+\x y -> y x flip id
+\x y -> y 10 const (flip id 10)
+\f a b c d -> f b c d a (o) flip ((o) ((o) flip) ((o) ((o) flip)))
+\f x -> f x x join