--- /dev/null
+# Scanner test code
+
+The focus of these tests is coverage of the code in scanner.mdc
+with the aim of being able to detect regressions.
+
+We have a few different input files, and scan each with a variety
+of different setting and ensure the output is as expected.
+
+The inputs are in sectoins called "test: name" and the expected
+outputs are in "test: name,arg,arg,arg". As we cannot (yet)
+extract a list of section names, we need to tell the make script
+about each test.
+
+###### File: scanner-tests.mk
+
+ scanner_tests :=
+ ## test list
+
+ tests:: scanner_test_suite
+ scanner_test_suite : md2c coverage_scanner
+ @rm -rf coverage; mkdir -p coverage
+ @cp *.gcno coverage
+ @for T in $(scanner_tests); do \
+ echo -n "Tests $$T ... "; \
+ i="$IFS"; IFS=,; set $$T; IFS="$$i"; t=$$1; shift; \
+ ./md2c scanner-tests.mdc "output: $$T" | grep -v '^#' > .tmp.want; \
+ echo '~~~~~~~' > .tmp.code ;\
+ ./md2c scanner-tests.mdc "test: $$t" | grep -v '^#' >> .tmp.code; \
+ ./coverage_scanner --file .tmp.code $${1+"$$@"} > .tmp.have; \
+ if ! cmp -s .tmp.want .tmp.have; then \
+ echo "FAILED"; diff -u .tmp.want .tmp.have; exit 1; fi ; \
+ echo "PASSED"; \
+ done
+
+ @gcov -o coverage scanner.c libscanner.c > /dev/null 2> /dev/null
+ @mv *.gcov coverage; [ -f .gcov ] && mv .gcov coverage || true
+ @awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
+ END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \
+ if (ran < (ran + skip) *0.85) exit(1) }' \
+ coverage/scanner.mdc.gcov
+ @rm -f .tmp*
+
+ coverage_scanner: scanner.c libscanner.c
+ $(CC) $(CFLAGS) --coverage -fprofile-dir=coverage -o coverage_scanner \
+ scanner.c libscanner.c \
+ libmdcode.o libnumber.o libstring.o -licuuc -lgmp
+
+
+## Basic tests
+
+Some simple tests... maybe all tests are simple.
+
+###### test list
+ scanner_tests += "test1,if,then,+,-"
+ scanner_tests += "test1,if,then,+,-,/"
+ scanner_tests += "test1,--ignore-indent,if,then,+,-,/"
+ scanner_tests += "test1,--ignore-indent,--ignore-newline,if,then,+,-,/"
+ scanner_tests += "test1,-Cc,--ignore-indent,--ignore-newline,if,then,+,-,/"
+ scanner_tests += "test1,-CcSz,--ignore-indent,--ignore-newline,if,then,+,-,/"
+
+###### test: test1
+
+ A B C
+ D E
+ F G
+ H
+ I
+
+ A
+ B
+ C
+ D
+ E
+ F
+ G
+ H
+
+ if else then fi while
+ 1234, 1.234 -123.456e45
+ 0x1234 + 0x543p3
+ "This is a string" &"so is this"a
+ a = """
+ This is a multi-
+ line string that
+ has three lines
+ """bb
+ I think # some comments are like this
+ and // some are like this
+ and some /* can go
+ over multiplt
+ lines */
+ divident /+ divisor
+
+###### output: test1,if,then,+,-
+ Tokenizing:
+ 2:0 ident(A)
+ 2:2 ident(B)
+ 2:4 ident(C)
+ 3:2 in()
+ 3:2 ident(D)
+ 3:4 ident(E)
+ 4:3 in()
+ 4:3 ident(F)
+ 4:5 ident(G)
+ 5:1 newline()
+ 5:1 out()
+ 5:1 newline()
+ 5:1 out()
+ 5:1 in()
+ 5:1 ident(H)
+ 6:0 newline()
+ 6:0 out()
+ 6:0 newline()
+ 6:0 ident(I)
+ 8:0 newline()
+ 8:0 newline()
+ 8:0 ident(A)
+ 9:2 in()
+ 9:2 ident(B)
+ 10:4 in()
+ 10:4 ident(C)
+ 11:4 newline()
+ 11:4 ident(D)
+ 12:2 newline()
+ 12:2 out()
+ 12:2 newline()
+ 12:2 ident(E)
+ 13:0 newline()
+ 13:0 out()
+ 13:0 newline()
+ 13:0 ident(F)
+ 14:2 in()
+ 14:2 ident(G)
+ 15:0 newline()
+ 15:0 out()
+ 15:0 newline()
+ 15:0 ident(H)
+ 17:0 newline()
+ 17:0 newline()
+ 17:0 if
+ 17:3 ident(else)
+ 17:8 then
+ 17:13 ident(fi)
+ 17:16 ident(while)
+ 18:0 newline()
+ 18:0 number(1234) 1234
+ 18:4 mark(,)
+ 18:7 number(1.234 ) 617/500
+ 18:13 -
+ 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
+ 19:0 newline()
+ 19:0 number(0x1234 ) 4660
+ 19:7 +
+ 19:10 number(0x543p3) 10776
+ 20:0 newline()
+ 20:0 string("This is a string") This is a string
+ 20:19 mark(&)
+ 20:20 string("so is this"a) a so is this
+ 21:0 newline()
+ 21:0 ident(a)
+ 21:2 mark(=)
+ 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
+ 26:0 newline()
+ 26:0 ident(I)
+ 26:2 ident(think)
+ 26:8 lcomment(# some comments ar..)
+ 27:0 newline()
+ 27:0 ident(and)
+ 27:4 lcomment(// some are like t..)
+ 28:0 newline()
+ 28:0 ident(and)
+ 28:4 ident(some)
+ 28:9 bcomment(/* can go\x0aover mul..)
+ 31:0 newline()
+ 31:0 ident(divident)
+ 31:9 mark(/+)
+ 31:12 ident(divisor)
+ 32:0 newline()
+ 32:0 eof()
+
+###### output: test1,if,then,+,-,/
+ Tokenizing:
+ 2:0 ident(A)
+ 2:2 ident(B)
+ 2:4 ident(C)
+ 3:2 in()
+ 3:2 ident(D)
+ 3:4 ident(E)
+ 4:3 in()
+ 4:3 ident(F)
+ 4:5 ident(G)
+ 5:1 newline()
+ 5:1 out()
+ 5:1 newline()
+ 5:1 out()
+ 5:1 in()
+ 5:1 ident(H)
+ 6:0 newline()
+ 6:0 out()
+ 6:0 newline()
+ 6:0 ident(I)
+ 8:0 newline()
+ 8:0 newline()
+ 8:0 ident(A)
+ 9:2 in()
+ 9:2 ident(B)
+ 10:4 in()
+ 10:4 ident(C)
+ 11:4 newline()
+ 11:4 ident(D)
+ 12:2 newline()
+ 12:2 out()
+ 12:2 newline()
+ 12:2 ident(E)
+ 13:0 newline()
+ 13:0 out()
+ 13:0 newline()
+ 13:0 ident(F)
+ 14:2 in()
+ 14:2 ident(G)
+ 15:0 newline()
+ 15:0 out()
+ 15:0 newline()
+ 15:0 ident(H)
+ 17:0 newline()
+ 17:0 newline()
+ 17:0 if
+ 17:3 ident(else)
+ 17:8 then
+ 17:13 ident(fi)
+ 17:16 ident(while)
+ 18:0 newline()
+ 18:0 number(1234) 1234
+ 18:4 mark(,)
+ 18:7 number(1.234 ) 617/500
+ 18:13 -
+ 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
+ 19:0 newline()
+ 19:0 number(0x1234 ) 4660
+ 19:7 +
+ 19:10 number(0x543p3) 10776
+ 20:0 newline()
+ 20:0 string("This is a string") This is a string
+ 20:19 mark(&)
+ 20:20 string("so is this"a) a so is this
+ 21:0 newline()
+ 21:0 ident(a)
+ 21:2 mark(=)
+ 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
+ 26:0 newline()
+ 26:0 ident(I)
+ 26:2 ident(think)
+ 26:8 lcomment(# some comments ar..)
+ 27:0 newline()
+ 27:0 ident(and)
+ 27:4 lcomment(// some are like t..)
+ 28:0 newline()
+ 28:0 ident(and)
+ 28:4 ident(some)
+ 28:9 bcomment(/* can go\x0aover mul..)
+ 31:0 newline()
+ 31:0 ident(divident)
+ 31:9 /
+ 31:10 +
+ 31:12 ident(divisor)
+ 32:0 newline()
+ 32:0 eof()
+
+###### output: test1,--ignore-indent,if,then,+,-,/
+ Tokenizing:
+ 2:0 ident(A)
+ 2:2 ident(B)
+ 2:4 ident(C)
+ 2:5 newline()
+ 3:2 ident(D)
+ 3:4 ident(E)
+ 3:5 newline()
+ 4:3 ident(F)
+ 4:5 ident(G)
+ 4:6 newline()
+ 5:1 ident(H)
+ 5:2 newline()
+ 6:0 ident(I)
+ 6:1 newline()
+ 7:0 newline()
+ 8:0 ident(A)
+ 8:1 newline()
+ 9:2 ident(B)
+ 9:3 newline()
+ 10:4 ident(C)
+ 10:5 newline()
+ 11:4 ident(D)
+ 11:5 newline()
+ 12:2 ident(E)
+ 12:3 newline()
+ 13:0 ident(F)
+ 13:1 newline()
+ 14:2 ident(G)
+ 14:3 newline()
+ 15:0 ident(H)
+ 15:1 newline()
+ 16:0 newline()
+ 17:0 if
+ 17:3 ident(else)
+ 17:8 then
+ 17:13 ident(fi)
+ 17:16 ident(while)
+ 17:21 newline()
+ 18:0 number(1234) 1234
+ 18:4 mark(,)
+ 18:7 number(1.234 ) 617/500
+ 18:13 -
+ 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
+ 18:24 newline()
+ 19:0 number(0x1234 ) 4660
+ 19:7 +
+ 19:10 number(0x543p3) 10776
+ 19:17 newline()
+ 20:0 string("This is a string") This is a string
+ 20:19 mark(&)
+ 20:20 string("so is this"a) a so is this
+ 20:33 newline()
+ 21:0 ident(a)
+ 21:2 mark(=)
+ 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
+ 25:8 newline()
+ 26:0 ident(I)
+ 26:2 ident(think)
+ 26:8 lcomment(# some comments ar..)
+ 26:37 newline()
+ 27:0 ident(and)
+ 27:4 lcomment(// some are like t..)
+ 27:25 newline()
+ 28:0 ident(and)
+ 28:4 ident(some)
+ 28:9 bcomment(/* can go\x0aover mul..)
+ 30:8 newline()
+ 31:0 ident(divident)
+ 31:9 /
+ 31:10 +
+ 31:12 ident(divisor)
+ 31:19 newline()
+ 32:0 eof()
+
+###### output: test1,--ignore-indent,--ignore-newline,if,then,+,-,/
+ Tokenizing:
+ 2:0 ident(A)
+ 2:2 ident(B)
+ 2:4 ident(C)
+ 3:2 ident(D)
+ 3:4 ident(E)
+ 4:3 ident(F)
+ 4:5 ident(G)
+ 5:1 ident(H)
+ 6:0 ident(I)
+ 8:0 ident(A)
+ 9:2 ident(B)
+ 10:4 ident(C)
+ 11:4 ident(D)
+ 12:2 ident(E)
+ 13:0 ident(F)
+ 14:2 ident(G)
+ 15:0 ident(H)
+ 17:0 if
+ 17:3 ident(else)
+ 17:8 then
+ 17:13 ident(fi)
+ 17:16 ident(while)
+ 18:0 number(1234) 1234
+ 18:4 mark(,)
+ 18:7 number(1.234 ) 617/500
+ 18:13 -
+ 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
+ 19:0 number(0x1234 ) 4660
+ 19:7 +
+ 19:10 number(0x543p3) 10776
+ 20:0 string("This is a string") This is a string
+ 20:19 mark(&)
+ 20:20 string("so is this"a) a so is this
+ 21:0 ident(a)
+ 21:2 mark(=)
+ 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
+ 26:0 ident(I)
+ 26:2 ident(think)
+ 26:8 lcomment(# some comments ar..)
+ 27:0 ident(and)
+ 27:4 lcomment(// some are like t..)
+ 28:0 ident(and)
+ 28:4 ident(some)
+ 28:9 bcomment(/* can go\x0aover mul..)
+ 31:0 ident(divident)
+ 31:9 /
+ 31:10 +
+ 31:12 ident(divisor)
+ 32:0 eof()
+
+###### output: test1,-Cc,--ignore-indent,--ignore-newline,if,then,+,-,/
+ Tokenizing:
+ 2:0 ident(A)
+ 2:2 ident(B)
+ 2:4 ident(C)
+ 3:2 ident(D)
+ 3:4 ident(E)
+ 4:3 ident(F)
+ 4:5 ident(G)
+ 5:1 ident(H)
+ 6:0 ident(I)
+ 8:0 ident(A)
+ 9:2 ident(B)
+ 10:4 ident(C)
+ 11:4 ident(D)
+ 12:2 ident(E)
+ 13:0 ident(F)
+ 14:2 ident(G)
+ 15:0 ident(H)
+ 17:0 if
+ 17:3 ident(else)
+ 17:8 then
+ 17:13 ident(fi)
+ 17:16 ident(while)
+ 18:0 number(1234) 1234
+ 18:4 mark(,)
+ 18:7 number(1.234 ) 617/500
+ 18:13 -
+ 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
+ 19:0 number(0x1234 ) 4660
+ 19:7 +
+ 19:10 number(0x543p3) 10776
+ 20:0 string("This is a string") This is a string
+ 20:19 mark(&)
+ 20:20 string("so is this"a) a so is this
+ 21:0 ident(a)
+ 21:2 mark(=)
+ 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
+ 26:0 ident(I)
+ 26:2 ident(think)
+ 27:0 ident(and)
+ 28:0 ident(and)
+ 28:4 ident(some)
+ 31:0 ident(divident)
+ 31:9 /
+ 31:10 +
+ 31:12 ident(divisor)
+ 32:0 eof()
+
+###### output: test1,-CcSz,--ignore-indent,--ignore-newline,if,then,+,-,/
+ Tokenizing:
+ 2:0 ident(A)
+ 2:2 ident(B)
+ 2:4 ident(C)
+ 3:2 ident(D)
+ 3:4 ident(E)
+ 4:3 ident(F)
+ 4:5 ident(G)
+ 5:1 ident(H)
+ 6:0 ident(I)
+ 8:0 ident(A)
+ 9:2 ident(B)
+ 10:4 ident(C)
+ 11:4 ident(D)
+ 12:2 ident(E)
+ 13:0 ident(F)
+ 14:2 ident(G)
+ 15:0 ident(H)
+ 17:0 if
+ 17:3 ident(else)
+ 17:8 then
+ 17:13 ident(fi)
+ 17:16 ident(while)
+ 18:0 number(1234) 1234
+ 18:4 mark(,)
+ 18:7 number(1.234 ) 617/500
+ 18:13 -
+ 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
+ 19:0 number(0x1234 ) 4660
+ 19:7 +
+ 19:10 number(0x543p3) 10776
+ 20:0 mark(")
+ 20:1 ident(This)
+ 20:6 ident(is)
+ 20:9 ident(a)
+ 20:11 ident(string)
+ 20:17 mark(")
+ 20:19 mark(&")
+ 20:21 ident(so)
+ 20:24 ident(is)
+ 20:27 ident(this)
+ 20:31 mark(")
+ 20:32 ident(a)
+ 21:0 ident(a)
+ 21:2 mark(=)
+ 21:4 mark(""")
+ 22:3 ident(This)
+ 22:8 ident(is)
+ 22:11 ident(a)
+ 22:13 ident(multi)
+ 22:18 -
+ 23:3 ident(line)
+ 23:8 ident(string)
+ 23:15 ident(that)
+ 24:3 ident(has)
+ 24:7 ident(three)
+ 24:13 ident(lines)
+ 25:3 mark(""")
+ 25:6 ident(bb)
+ 26:0 ident(I)
+ 26:2 ident(think)
+ 27:0 ident(and)
+ 28:0 ident(and)
+ 28:4 ident(some)
+ 31:0 ident(divident)
+ 31:9 /
+ 31:10 +
+ 31:12 ident(divisor)
+ 32:0 eof()