bugfix: safety against breaking the AI if you press undo while it's thinking
[kaya.git] / test / board / test_square_tag.rb
blob0ad6a4454456309201aacc86e3afac9608b6a2cc
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'test/unit'
9 require 'board/square_tag'
10 require 'board/point_converter'
11 require 'rubygems'
12 require 'mocha'
14 class FakeTaggableBoard
15   include PointConverter
16   include TaggableSquares
17   
18   square_tag :selection, :selection
19   
20   class FakeTheme
21     def method_missing(m, *args)
22       self
23     end
24   end
25   
26   def theme
27     FakeTheme.new
28   end
29   
30   def unit
31     Point.new(10, 10)
32   end
33   
34   def flipped?
35     false
36   end
37 end
39 class TestSquareTag < Test::Unit::TestCase
40   def setup
41     @board = FakeTaggableBoard.new
42     @stubbed_item = Object.new
43     class << @stubbed_item
44       def reload(key)
45       end
46     end
47   end
48   
49   def test_tag_methods
50     assert @board.respond_to?(:selection)
51     assert @board.respond_to?(:selection=)
52   end
53   
54   def test_empty_initial_tag
55     assert_nil @board.selection
56   end
57   
58   def test_set_retrieve_tag
59     @board.expects(:add_item).with do |name, args|
60       name == :selection and args[:pos] == Point.new(30.0, 20.0)
61     end.returns(@stubbed_item)
62     @board.selection = Point.new(3, 2)
63     assert_equal Point.new(3, 2), @board.selection
64   end
65   
66   def test_set_cancel_tag
67     @board.expects(:add_item).with do |name, args|
68       name == :selection and args[:pos] == Point.new(50.0, 30.0)
69     end.returns(@stubbed_item)
70     @board.expects(:remove_item).with(:selection)
71     
72     @board.selection = Point.new(5, 3)
73     @board.selection = nil
74     assert_nil @board.selection
75   end
76 end