diff options
author | Camil Staps | 2017-11-22 09:58:14 +0100 |
---|---|---|
committer | Camil Staps | 2017-11-22 09:58:14 +0100 |
commit | 7644d57ce32264f35175518ed848b39cb0a62f0d (patch) | |
tree | 139162303642e3fedb7e434bddece9ae834808be | |
parent | Add parser (diff) |
Test setup
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | pf.icl | 35 | ||||
-rwxr-xr-x | test.sh | 14 | ||||
-rw-r--r-- | test.tsv | 15 |
4 files changed, 46 insertions, 20 deletions
@@ -1,6 +1,6 @@ BIN:=pf CLM:=clm -CLMFLAGS:=-b -IL Platform -IL Generics +CLMFLAGS:=-nr -IL Platform -IL Generics .PHONY: all clean @@ -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) @@ -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 |