add spec tests

This commit is contained in:
Noah Hellman 2022-11-12 18:46:13 +01:00
parent 40a612df95
commit 8c0abca85f
7 changed files with 143 additions and 0 deletions

22
tests/suite/Makefile Normal file
View file

@ -0,0 +1,22 @@
.POSIX:
.SUFFIXES: .test .rs
TEST=$(shell find . -name '*.test' | sort)
TEST_RS=${TEST:.test=.rs}
.PHONY: suite
suite: mod.rs
mod.rs: ${TEST_RS}
printf "" > $@
for f in ${TEST}; do \
name=$$(basename -s .test $$f); \
echo "mod $$name;" >> $@; \
done
.test.rs:
awk -fgen.awk $< > $@
clean:
rm -f *.rs

47
tests/suite/gen.awk Normal file
View file

@ -0,0 +1,47 @@
BEGIN {
print "use crate::suite_test;"
print ""
}
$0 ~ "^`{3,}$" {
l=length($0)
if (fence == 0) { # enter fence
print "#[test]"
printf "fn test%02d() {\n", count
printf " let src = r##\""
fence=l
count+=1
} else if (fence == l) { # exit fence
if (ignore) {
ignore=0
} else {
print "\"##;"
print " suite_test!(src, expected);"
print "}"
print ""
}
fence=0
} else {
print $0 # md/html
}
next
}
fence == 0 && $0 ~ "^`{3,} .*$" {
ignore=1
fence=match($0, "[^`]")-1
next
}
$0 ~ "^\\.$" && !ignore { # enter html
print "\"##;"
printf " let expected = r##\""
next
}
!ignore {
if (fence==0 && $0 != "") { # comment
printf "// "
}
print $0 # comment/md/html
}