3
static int test_count = 0;
4
static int failure_count = 0;
6
private static void test_pgn_file (string data, string moves)
13
file = new PGN.from_string (data);
17
stderr.printf ("%d. FAIL %s\n", test_count, e.message);
22
var game = file.games.nth_data (0);
24
foreach (var move in game.moves)
25
move_string += "%s ".printf (move);
26
move_string = move_string.strip ();
28
if (move_string == moves)
29
stderr.printf ("%d. PASS\n", test_count);
33
stderr.printf ("%d. FAIL got moves '%s', expected '%s'\n", test_count, move_string, moves);
37
public static int main (string[] args)
39
/* Simple file in export format */
40
test_pgn_file ("[Event \"?\"]\n" +
42
"[Date \"????.??.??\"]\n" +
52
test_pgn_file ("1. e1 *\n", "e1");
55
test_pgn_file ("e1 *\n", "e1");
58
test_pgn_file ("e1\n", "e1");
60
/* No trailing newline */
61
test_pgn_file ("e1", "e1");
63
/* Carriage returns instead of newlines */
64
test_pgn_file ("[Event \"?\"]\r" +
70
test_pgn_file ("; Line comment 1\n" +
72
"; Line comment 2\n" +
74
"1. e4 {First Move} e5 {Multi\n" +
76
"comment} 2. Nc3 {More comments} * {Comment about game end}\n",
79
/* Format used by Yahoo Chess */
80
test_pgn_file (";Title: Yahoo! Chess Game\n" +
82
";Black: ladyjones96\n" +
83
";Date: Fri Oct 19 12:51:54 GMT 2007\n" +
88
/* Recursive Annotation Variation */
89
test_pgn_file ("1.Ra8+ (1.Bxd6+ Kb7 2.Rc7+ Kb8 (2...Kb6 3.Ra6#) 3.Rd7+ Kc8 4.Rc1# (4.Ra8#))",
92
/* Numeric Annotation Glyph */
93
test_pgn_file ("e4 e5 $1 Nc3 $2",
96
stdout.printf ("%d/%d tests successful\n", test_count - failure_count, test_count);