Bumped version number for release.
[ocaml-csv.git] / test.ml
1 (* $Id: test.ml,v 1.1 2003-12-17 16:05:08 rich Exp $ *)
2
3 open Printf
4 open Csv
5
6 let do_testcsv filename expected =
7   let csv = load filename in
8   if csv <> expected then (
9     printf "input file: %s\n" filename;
10     printf "Csv library produced:\n";
11     print csv;
12     printf "Expected:\n";
13     print expected;
14     failwith "failed"
15   )
16
17 let testcsv1 =
18   do_testcsv
19     "testcsv1.csv"
20     [ [ "This is a test\nwith commas,,,,,\n\nand carriage returns." ] ]
21 let testcsv2 =
22   do_testcsv
23     "testcsv2.csv"
24     [ [ "Normal field"; "Quoted field"; "Quoted field with \"\" quotes" ] ]
25 let testcsv3 =
26   do_testcsv
27     "testcsv3.csv"
28     [ [ "" ];
29       [ ""; "" ];
30       [ ""; ""; "" ];
31       [ ""; ""; ""; "" ];
32       [ ""; ""; ""; ""; "" ] ]
33 let testcsv4 =
34   do_testcsv
35     "testcsv4.csv"
36     []
37 let testcsv5 =
38   do_testcsv
39     "testcsv5.csv"
40     [ [ "This is a test\nwith commas,,,,,\n\nand carriage returns.";
41         "a second field"; "a third field" ];
42       [ "a fourth field on a new line" ] ]
43 let testcsv6 =
44   do_testcsv
45     "testcsv6.csv"
46     [ [ "This is a test\nwith commas,,,,,\n\nand carriage returns\nand \000";
47         "a second field"; "a third field" ];
48       [ "a fourth field on a new line" ] ]
49
50 ;;
51
52 print_endline "All tests succeeded."