Sat, 31 Oct 2009 16:28:42 +0000
Add tests
test_data.lua | file | annotate | diff | comparison | revisions | |
test_data.tsv | file | annotate | diff | comparison | revisions | |
test_tsv.lua | file | annotate | diff | comparison | revisions |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test_data.lua Sat Oct 31 16:28:42 2009 +0000 @@ -0,0 +1,7 @@ +data = { + { "one", "two", "three", "four", "five" }; + { "one", "", "three", "four", "five" }; + { "one\t", "two", "three", "four", "five" }; + { "one\t", "two", "three", "four", "five" }; + { "one\\", "two", "three", "four", "five" }; + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test_data.tsv Sat Oct 31 16:28:42 2009 +0000 @@ -0,0 +1,5 @@ +one two three four five +one three four five +one\t two three four five +one\ two three four five +one\\ two three four five
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test_tsv.lua Sat Oct 31 16:28:42 2009 +0000 @@ -0,0 +1,19 @@ +dofile "test_data.lua" + +local tsv = require "tsv" + +local row = 0; +for line in io.lines("test_data.tsv") do + row = row + 1; + local col = 0; + tsv.read_record(line, function (v) + col = col + 1; + if data[row][col] ~= v then + print(("MISMATCH at row %d, column %d: %s is not %s") + :format(row, col, v, tostring(data[row][col]))) + bad = true; + end + end); +end + +os.exit(bad and 1 or 0);