New redrawing logic.
[kaya.git] / test / board / test_square_tag.rb
blob24503e5218e0318242888c0af684c273fcffc3b0
1 require 'test/unit'
2 require 'board/square_tag'
3 require 'board/point_converter'
4 require 'rubygems'
5 require 'mocha'
7 class FakeTaggableBoard
8   include PointConverter
9   include TaggableSquares
10   
11   square_tag :selection
12   
13   class FakeTheme
14     def method_missing(m, *args)
15       self
16     end
17   end
18   
19   def theme
20     FakeTheme.new
21   end
22   
23   def unit
24     Point.new(10, 10)
25   end
26   
27   def flipped?
28     false
29   end
30 end
32 class TestSquareTag < Test::Unit::TestCase
33   def setup
34     @board = FakeTaggableBoard.new
35   end
36   
37   def test_tag_methods
38     assert @board.respond_to?(:selection)
39     assert @board.respond_to?(:selection=)
40   end
41   
42   def test_empty_initial_tag
43     assert_nil @board.selection
44   end
45   
46   def test_set_retrieve_tag
47     @board.expects(:add_item).with do |name, pix, args|
48       name == :selection and args[:pos] == Point.new(30.0, 20.0)
49     end
50     @board.selection = Point.new(3, 2)
51     assert_equal Point.new(3, 2), @board.selection
52   end
53   
54   def test_set_cancel_tag
55     @board.expects(:add_item).with do |name, pix, args|
56       name == :selection and args[:pos] == Point.new(50.0, 30.0)
57     end
58     @board.expects(:remove_item).with(:selection)
59     
60     @board.selection = Point.new(5, 3)
61     @board.selection = nil
62     assert_nil @board.selection
63   end
64 end