Add licence and installation instructions.
[kaya.git] / test / board / test_square_tag.rb
blobdeada920190d4820ffedb4f85e6dbec8dc7943d0
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
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   end
43   
44   def test_tag_methods
45     assert @board.respond_to?(:selection)
46     assert @board.respond_to?(:selection=)
47   end
48   
49   def test_empty_initial_tag
50     assert_nil @board.selection
51   end
52   
53   def test_set_retrieve_tag
54     @board.expects(:add_item).with do |name, pix, args|
55       name == :selection and args[:pos] == Point.new(30.0, 20.0)
56     end
57     @board.selection = Point.new(3, 2)
58     assert_equal Point.new(3, 2), @board.selection
59   end
60   
61   def test_set_cancel_tag
62     @board.expects(:add_item).with do |name, pix, args|
63       name == :selection and args[:pos] == Point.new(50.0, 30.0)
64     end
65     @board.expects(:remove_item).with(:selection)
66     
67     @board.selection = Point.new(5, 3)
68     @board.selection = nil
69     assert_nil @board.selection
70   end
71 end