Verified Commit c681e3b2 authored by Camil Staps's avatar Camil Staps 🚀

Testsuite stolen from PCRE

parent 4e086a94
......@@ -10,3 +10,4 @@ Clean System Files/
sapl/
example
test
SHELL:=bash
CLM:=clm
CLMFLAGS:=\
-I $$CLEAN_HOME/lib/clean-platform/OS-Independent\
......@@ -7,14 +9,17 @@ CLMFLAGS:=\
DEPMODS:=Regex Regex/Match Regex/Parse Regex/Print Regex/Util
DEPS:=$(addsuffix .dcl,$(DEPMODS)) $(addsuffix .icl,$(DEPMODS))
EXE:=example
EXE:=example test
all: $(EXE)
run_test: test
diff -y <(./test < testdata/testinput1) testdata/testoutput1 | grep -v -e '^#' -e '# 0:' -e '# 1:' -e '#No match' | less
$(EXE): %: %.icl $(DEPS)
$(CLM) $(CLMFLAGS) $@ -o $@
clean:
$(RM) -r Clean\ System\ Files $(EXE)
.PHONY: all clean
.PHONY: all clean run_test
module test
import StdEnv
import Data.Error
from Data.Func import $
import Regex
Start :: *World -> *World
Start w
# (io,w) = stdio w
# io = loop (Error "waiting for regex") io
# (ok,w) = fclose io w
= w
loop :: (MaybeErrorString Regex) *File -> *File
loop r f
# (ln,f) = freadline f
# f = f <<< ln
| ln % (0,12) == "# End of test"
= f
| isMember ln.[0] ['#\\']
= loop r f
| ln.[0] == '/' && ln.[size ln-2] == '/' // modifiers not supported
= loop (compile $ fromString $ ln % (1,size ln-3)) f
| ln.[0] == '/'
= loop (Error "skipped modifiers") f
| ln % (0,3) == " "
| isError r = loop r f
= loop r (print_match (fromOk r) (fromString $ ln % (4,size ln-2)) f)
| otherwise
= loop r f
print_match :: !Regex ![Char] *File -> *File
print_match r s f
| isEmpty matches = f <<< "No match\n"
# f = f <<< " 0: " <<< toString m <<< '\n'
# f = f <<< foldl (+++) "" (map (\(NotNamed i,s) -> if (i < 9) " " "" +++ toString (i+1) +++ ": " +++ toString s +++ "\n") $ sort grps)
= f
where
(_,m,grps) = hd matches
matches = match r s
instance < GroupId where (<) (NotNamed a) (NotNamed b) = a < b
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment