test_tsv.lua

Sat, 31 Oct 2009 16:28:42 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 31 Oct 2009 16:28:42 +0000
changeset 1
29e532c213f7
permissions
-rw-r--r--

Add tests

1
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 dofile "test_data.lua"
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local tsv = require "tsv"
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local row = 0;
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 for line in io.lines("test_data.tsv") do
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 row = row + 1;
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local col = 0;
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 tsv.read_record(line, function (v)
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 col = col + 1;
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 if data[row][col] ~= v then
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 print(("MISMATCH at row %d, column %d: %s is not %s")
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 :format(row, col, v, tostring(data[row][col])))
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 bad = true;
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 end
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end);
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 end
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
29e532c213f7 Add tests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 os.exit(bad and 1 or 0);

mercurial