Expand parser and Unicode test coverage

This commit is contained in:
Petri Lehtinen 2009-07-18 15:59:55 +03:00
parent 9240146c10
commit 20efe4aa26
7 changed files with 123 additions and 17 deletions

View File

@ -16,15 +16,12 @@ run_testprog() {
esac esac
} }
if [ ! -f $TESTFILE ]; then for testfile in $TESTFILES; do
echo "$TESTFILE cannot be found" >&2 mkdir -p $TMPDIR
exit 1 ${srcdir}/split-testfile.py $testfile $TMPDIR | while read input output; do
fi run_test load_dump $input $output
run_test loadf_dumpf $input $output
mkdir -p $TMPDIR run_test loads_dumps $input $output
${srcdir}/split-testfile.py $TESTFILE $TMPDIR | \ done || exit 1
while read input output; do rm -rf $TMPDIR
run_test load_dump $input $output
run_test loadf_dumpf $input $output
run_test loads_dumps $input $output
done done

View File

@ -17,8 +17,8 @@ def main():
print 'usage: %s input-file output-directory' % sys.argv[0] print 'usage: %s input-file output-directory' % sys.argv[0]
return 2 return 2
infile = sys.argv[1] infile = os.path.normpath(sys.argv[1])
outdir = sys.argv[2] outdir = os.path.normpath(sys.argv[2])
if not os.path.exists(outdir): if not os.path.exists(outdir):
print >>sys.stderr, 'output directory %r does not exist!' % outdir print >>sys.stderr, 'output directory %r does not exist!' % outdir
@ -40,7 +40,7 @@ def main():
current.write(line) current.write(line)
close_files(input, output) close_files(input, output)
print >>sys.stderr, "%d test cases" % (i + 1) print >>sys.stderr, "%s: %d test cases" % (infile, i + 1)
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main() or 0) sys.exit(main() or 0)

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
TESTFILE="${srcdir}/testdata/invalid" TESTFILES="${srcdir}/testdata/invalid ${srcdir}/testdata/invalid-unicode"
TMPDIR="tmp" TMPDIR="tmp"
run_test() { run_test() {

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
TESTFILE="${srcdir}/testdata/valid" TESTFILES="${srcdir}/testdata/valid"
TMPDIR="tmp" TMPDIR="tmp"
run_test() { run_test() {

20
test/testdata/invalid vendored
View File

@ -77,6 +77,11 @@ unexpected token near end of file
1 1
unexpected newline near '"a' unexpected newline near '"a'
======== ========
{"a":"a" 123}
====
1
'}' expected near '123'
========
{[ {[
==== ====
1 1
@ -132,6 +137,16 @@ invalid token near '0'
1 1
invalid token near '-0' invalid token near '-0'
======== ========
[troo
====
1
invalid token near 'troo'
========
["\a <-- invalid escape"]
====
1
invalid escape near '"\'
========
[" <-- tab character"] [" <-- tab character"]
==== ====
1 1
@ -156,3 +171,8 @@ invalid Unicode '\uD888\u3210'
==== ====
1 1
invalid Unicode '\uDFAA' invalid Unicode '\uDFAA'
========
å
====
1
'[' or '{' expected near 'å'

89
test/testdata/invalid-unicode vendored Normal file
View File

@ -0,0 +1,89 @@
å
====
-1
unable to decode byte 0xe5 at position 0
========
["å <-- invalid UTF-8"]
====
-1
unable to decode byte 0xe5 at position 2
========
[å]
====
-1
unable to decode byte 0xe5 at position 1
========
[aå]
====
-1
unable to decode byte 0xe5 at position 2
========
["\uå"]
====
-1
unable to decode byte 0xe5 at position 4
========
["\å"]
====
-1
unable to decode byte 0xe5 at position 3
========
[0å]
====
-1
unable to decode byte 0xe5 at position 2
========
[123å]
====
-1
unable to decode byte 0xe5 at position 4
========
[1eå]
====
-1
unable to decode byte 0xe5 at position 3
========
[1e1å]
====
-1
unable to decode byte 0xe5 at position 4
========
["<22>"]
====
-1
unable to decode byte 0x81 at position 2
========
["Á"]
====
-1
unable to decode byte 0xc1 at position 2
========
["ý"]
====
-1
unable to decode byte 0xfd at position 2
========
["ô¿¿¿"]
====
-1
unable to decode byte 0xf4 at position 2
========
["à€¢ <-- overlong encoding"]
====
-1
unable to decode byte 0xe0 at position 2
========
["ð€€¢ <-- overlong encoding"]
====
-1
unable to decode byte 0xf0 at position 2
========
["àÿ <-- truncated UTF-8"]
====
-1
unable to decode byte 0xe0 at position 2
========
["í¢« <-- encoded surrogate half"]
====
-1
unable to decode byte 0xed at position 2

2
test/testdata/valid vendored
View File

@ -4,7 +4,7 @@
======== ========
["abcdefghijklmnopqrstuvwxyz1234567890 "] ["abcdefghijklmnopqrstuvwxyz1234567890 "]
======== ========
["€þıœəßð some utf-8 ĸʒ×ŋµåäö"] ["€þıœəßð some utf-8 ĸʒ×ŋµåäö𝄞"]
======== ========
["\"\\\/\b\f\n\r\t"] ["\"\\\/\b\f\n\r\t"]
======== ========