Implement ActionList::Entry#clear.
[kaya.git] / test / test_animator_helper.rb
blobbc14880b3421c138363337a26c0bcbd4cba146c6
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 'animator_helper'
10 require 'helpers/animation_test_helper'
12 class TestAnimatorHelper < Test::Unit::TestCase
13   include AnimationAssertions
14   
15   def setup
16     @items = { }
17     board = FakeBoard.new(@items)
18     @animator = Object.new
19     @animator.metaclass_eval do
20       include AnimatorHelper
21       include StubbedAnimations
22       define_method(:board) { board }
23     end
24   end
25   
26   def test_disappear
27     @items[Point.new(3, 3)] = "white knight"
28     anim = @animator.disappear_on!(Point.new(3, 3))
29     assert_animation(:disappear, anim) do |args|
30       assert_equal "white knight", args.first
31     end
32   end
33   
34   def test_appear
35     anim = @animator.appear_on!(Point.new(3, 3), "black king")
36     assert_animation(:appear, anim) do |args|
37       assert_equal "black king", args.first
38     end
39   end
40   
41   def test_instant_disappear
42     @items[Point.new(3, 3)] = "white knight"
43     anim = @animator.disappear_on!(Point.new(3, 3), :instant => true)
44     assert_animation(:disappear, anim)
45   end
46   
47   def test_instant_appear
48     anim = @animator.appear_on!(Point.new(3, 3), "black king", :instant => true)
49     assert_animation(:appear, anim)
50   end
51   
52   def test_move
53     @items[Point.new(3, 3)] = "white knight"
54     anim = @animator.move!(Point.new(3, 3), Point.new(5, 4), Path::Linear)
55     assert_animation(:movement, anim) do |args|
56       piece, src, dst = args
57       assert_equal "white knight", piece
58       assert_equal Point.new(3, 3), src
59       assert_equal Point.new(5, 4), dst
60     end
61   end
62   
63   def test_morph
64     @items[Point.new(3, 3)] = "white knight"
65     anim = @animator.morph_on!(Point.new(3, 3), "black knight")
66     assert_animation(:group, anim) do |args|
67       appear, disappear = args.sort
68       assert_animation(:appear, appear) do |args|
69         assert_equal "black knight", args.first
70       end
71       assert_animation(:disappear, disappear) do |args|
72         assert_equal "white knight", args.first
73       end
74     end
75   end
76 end