Fixed parsing of queen-side castling.
[kaya.git] / test / games / chess / test_pgn.rb
blob785b68104d17ea87f18935066fe46330bf637870
1 require 'test/unit'
2 require 'games/all'
3 require 'history'
4 require 'helpers/validation_helper'
6 class TestPGN < Test::Unit::TestCase
7   include ValidationHelper
8   
9   def setup
10     @game = Game.get(:chess)
11     @state = @game.state.new
12     @state.setup
13     @history = History.new(@state)
14     @writer = @game.game_writer.new
15   end
16   
17   def test_pgn_black_wins
18     add_move 4, 6, 4, 4
19     add_move 4, 1, 4, 3
20     info = { :result => :black }
21     
22     expected = <<-END_OF_PGN
23 [Result "0-1"]
24 1.e4 e5 0-1
25     END_OF_PGN
26     
27     assert_equal expected, @writer.write(info, @history)
28   end
29   
30   def test_pgn_white_wins
31     add_move 6, 7, 5, 5
32     info = { :result => :white,
33              :event => 'Oktoberfest',
34              :players => { :white => 'Doe, John',
35                            :black => 'Smith, Bob' } }
36     
37     expected = <<-END_OF_PGN
38 [Event "Oktoberfest"]
39 [White "Doe, John"]
40 [Black "Smith, Bob"]
41 [Result "1-0"]
42 1.Nf3 1-0
43 END_OF_PGN
44     
45     assert_equal expected, @writer.write(info, @history)
46   end
47   
48   private
49   
50   def add_move(*args)
51     move = unpack_move(*args)
52     validate = @game.validator.new(@history.state)
53     assert validate[move]
54     state = @history.state.dup
55     state.perform! move
56     @history.add_move(state, move)
57   end
58 end