fidgit 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -7
- data/.rspec +2 -2
- data/CHANGELOG.md +30 -30
- data/Gemfile +3 -3
- data/LICENSE.txt +19 -19
- data/README.textile +139 -139
- data/Rakefile +37 -37
- data/config/default_schema.yml +216 -216
- data/examples/_all_examples.rb +9 -9
- data/examples/align_example.rb +55 -55
- data/examples/button_and_toggle_button_example.rb +37 -37
- data/examples/color_picker_example.rb +16 -16
- data/examples/color_well_example.rb +24 -24
- data/examples/combo_box_example.rb +23 -23
- data/examples/file_dialog_example.rb +41 -41
- data/examples/grid_packer_example.rb +28 -28
- data/examples/helpers/example_window.rb +16 -16
- data/examples/label_example.rb +22 -22
- data/examples/list_example.rb +22 -22
- data/examples/menu_pane_example.rb +26 -26
- data/examples/message_dialog_example.rb +64 -64
- data/examples/radio_button_example.rb +36 -36
- data/examples/readme_example.rb +31 -31
- data/examples/scroll_window_example.rb +48 -48
- data/examples/slider_example.rb +33 -33
- data/examples/splash_example.rb +41 -41
- data/examples/text_area_example.rb +32 -32
- data/fidgit.gemspec +35 -35
- data/lib/fidgit.rb +50 -50
- data/lib/fidgit/chingu_ext/window.rb +5 -5
- data/lib/fidgit/cursor.rb +37 -37
- data/lib/fidgit/elements/button.rb +112 -112
- data/lib/fidgit/elements/color_picker.rb +62 -62
- data/lib/fidgit/elements/color_well.rb +38 -38
- data/lib/fidgit/elements/combo_box.rb +113 -113
- data/lib/fidgit/elements/composite.rb +16 -16
- data/lib/fidgit/elements/container.rb +208 -208
- data/lib/fidgit/elements/element.rb +297 -297
- data/lib/fidgit/elements/file_browser.rb +151 -151
- data/lib/fidgit/elements/grid.rb +226 -226
- data/lib/fidgit/elements/group.rb +64 -64
- data/lib/fidgit/elements/horizontal.rb +11 -11
- data/lib/fidgit/elements/image_frame.rb +64 -64
- data/lib/fidgit/elements/label.rb +84 -84
- data/lib/fidgit/elements/list.rb +46 -46
- data/lib/fidgit/elements/main_packer.rb +24 -24
- data/lib/fidgit/elements/menu_pane.rb +160 -160
- data/lib/fidgit/elements/packer.rb +41 -41
- data/lib/fidgit/elements/radio_button.rb +85 -85
- data/lib/fidgit/elements/scroll_area.rb +67 -67
- data/lib/fidgit/elements/scroll_bar.rb +127 -127
- data/lib/fidgit/elements/scroll_window.rb +82 -82
- data/lib/fidgit/elements/slider.rb +124 -124
- data/lib/fidgit/elements/text_area.rb +493 -493
- data/lib/fidgit/elements/text_line.rb +91 -91
- data/lib/fidgit/elements/toggle_button.rb +66 -66
- data/lib/fidgit/elements/tool_tip.rb +34 -34
- data/lib/fidgit/elements/vertical.rb +11 -11
- data/lib/fidgit/event.rb +158 -158
- data/lib/fidgit/gosu_ext/color.rb +135 -135
- data/lib/fidgit/gosu_ext/gosu_module.rb +24 -24
- data/lib/fidgit/history.rb +90 -90
- data/lib/fidgit/redirector.rb +82 -82
- data/lib/fidgit/schema.rb +123 -123
- data/lib/fidgit/selection.rb +105 -105
- data/lib/fidgit/standard_ext/hash.rb +20 -20
- data/lib/fidgit/states/dialog_state.rb +51 -51
- data/lib/fidgit/states/file_dialog.rb +24 -24
- data/lib/fidgit/states/gui_state.rb +329 -329
- data/lib/fidgit/states/message_dialog.rb +60 -60
- data/lib/fidgit/version.rb +4 -4
- data/lib/fidgit/window.rb +19 -19
- data/spec/fidgit/elements/helpers/helper.rb +2 -2
- data/spec/fidgit/elements/helpers/tex_play_helper.rb +8 -8
- data/spec/fidgit/elements/image_frame_spec.rb +68 -68
- data/spec/fidgit/elements/label_spec.rb +36 -36
- data/spec/fidgit/event_spec.rb +209 -209
- data/spec/fidgit/gosu_ext/color_spec.rb +129 -129
- data/spec/fidgit/gosu_ext/helpers/helper.rb +2 -2
- data/spec/fidgit/helpers/helper.rb +3 -3
- data/spec/fidgit/history_spec.rb +153 -153
- data/spec/fidgit/redirector_spec.rb +77 -77
- data/spec/fidgit/schema_spec.rb +66 -66
- data/spec/fidgit/schema_test.yml +32 -32
- metadata +67 -22
@@ -1,130 +1,130 @@
|
|
1
|
-
require_relative "helpers/helper"
|
2
|
-
|
3
|
-
include Gosu
|
4
|
-
|
5
|
-
describe Color do
|
6
|
-
describe "rgb" do
|
7
|
-
it "should create a color with the correct values from channel values" do
|
8
|
-
color = Color.rgb(1, 2, 3)
|
9
|
-
color.red.should equal 1
|
10
|
-
color.green.should equal 2
|
11
|
-
color.blue.should equal 3
|
12
|
-
color.alpha.should equal 255
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "rgba" do
|
17
|
-
it "should create a color with the correct value from channel valuess" do
|
18
|
-
color = Color.rgba(1, 2, 3, 4)
|
19
|
-
color.red.should equal 1
|
20
|
-
color.green.should equal 2
|
21
|
-
color.blue.should equal 3
|
22
|
-
color.alpha.should equal 4
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "argb" do
|
27
|
-
it "should create a color with the correct values from channel values" do
|
28
|
-
color = Color.argb(1, 2, 3, 4)
|
29
|
-
color.red.should equal 2
|
30
|
-
color.green.should equal 3
|
31
|
-
color.blue.should equal 4
|
32
|
-
color.alpha.should equal 1
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "ahsv" do
|
37
|
-
it "should create a color with the correct values from channel values" do
|
38
|
-
color = Color.ahsv(1, 180.0, 0.5, 0.7)
|
39
|
-
color.hue.should be_within(0.001).of(180.0)
|
40
|
-
color.saturation.should be_within(0.01).of(0.5)
|
41
|
-
color.value.should be_within(0.01).of(0.7)
|
42
|
-
color.alpha.should equal 1
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "hsva" do
|
47
|
-
it "should create a color with the correct values from channel values" do
|
48
|
-
color = Color.hsva(180.0, 0.5, 0.7, 4)
|
49
|
-
color.hue.should be_within(0.001).of(180.0)
|
50
|
-
color.saturation.should be_within(0.01).of(0.5)
|
51
|
-
color.value.should be_within(0.01).of(0.7)
|
52
|
-
color.alpha.should equal 4
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "from_tex_play" do
|
57
|
-
it "should create a color with the correct values" do
|
58
|
-
color = Color.from_tex_play([1 / 255.0, 2 / 255.0, 3 / 255.0, 4 / 255.0])
|
59
|
-
color.red.should equal 1
|
60
|
-
color.green.should equal 2
|
61
|
-
color.blue.should equal 3
|
62
|
-
color.alpha.should equal 4
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#to_tex_play" do
|
67
|
-
it "should create an array with the correct values" do
|
68
|
-
array = Color.rgba(1, 2, 3, 4).to_tex_play
|
69
|
-
array.should eq [1 / 255.0, 2 / 255.0, 3 / 255.0, 4 / 255.0]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#==" do
|
74
|
-
it "should return true for colours that are identical" do
|
75
|
-
(Color.rgb(1, 2, 3) == Color.rgb(1, 2, 3)).should be_true
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should return false for colours that are not the same" do
|
79
|
-
(Color.rgb(1, 2, 3) == Color.rgb(4, 2, 3)).should be_false
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "#transparent?" do
|
84
|
-
it "should be true if alpha is 0" do
|
85
|
-
Color.rgba(1, 1, 1, 0).should be_transparent
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should be false if 0 > alpha > 255" do
|
89
|
-
Color.rgba(1, 1, 1, 2).should_not be_transparent
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should be false if alpha == 255" do
|
93
|
-
Color.rgba(1, 1, 1, 255).should_not be_transparent
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "#opaque?" do
|
98
|
-
it "should be true if alpha is 0" do
|
99
|
-
Color.rgba(1, 1, 1, 0).should_not be_opaque
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should be false if 0 > alpha > 255" do
|
103
|
-
Color.rgba(1, 1, 1, 2).should_not be_opaque
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should be false if alpha == 255" do
|
107
|
-
Color.rgba(1, 1, 1, 255).should be_opaque
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "#+" do
|
112
|
-
it "should add two colours together" do
|
113
|
-
(Color.rgba(1, 2, 3, 4) + Color.rgba(10, 20, 30, 40)).should == Color.rgba(11, 22, 33, 44)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should cap values at 255" do
|
117
|
-
(Color.rgba(56, 56, 56, 56) + Color.rgba(200, 200, 200, 200)).should == Color.rgba(255, 255, 255, 255)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "#-" do
|
122
|
-
it "should subtract one color from another two colours together" do
|
123
|
-
(Color.rgba(10, 20, 30, 40) - Color.rgba(1, 2, 3, 4)).should == Color.rgba(9, 18, 27, 36)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should cap values at 0" do
|
127
|
-
(Color.rgba(56, 56, 56, 56) - Color.rgba(57, 57, 57, 57)).should == Color.rgba(0, 0, 0, 0)
|
128
|
-
end
|
129
|
-
end
|
1
|
+
require_relative "helpers/helper"
|
2
|
+
|
3
|
+
include Gosu
|
4
|
+
|
5
|
+
describe Color do
|
6
|
+
describe "rgb" do
|
7
|
+
it "should create a color with the correct values from channel values" do
|
8
|
+
color = Color.rgb(1, 2, 3)
|
9
|
+
color.red.should equal 1
|
10
|
+
color.green.should equal 2
|
11
|
+
color.blue.should equal 3
|
12
|
+
color.alpha.should equal 255
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "rgba" do
|
17
|
+
it "should create a color with the correct value from channel valuess" do
|
18
|
+
color = Color.rgba(1, 2, 3, 4)
|
19
|
+
color.red.should equal 1
|
20
|
+
color.green.should equal 2
|
21
|
+
color.blue.should equal 3
|
22
|
+
color.alpha.should equal 4
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "argb" do
|
27
|
+
it "should create a color with the correct values from channel values" do
|
28
|
+
color = Color.argb(1, 2, 3, 4)
|
29
|
+
color.red.should equal 2
|
30
|
+
color.green.should equal 3
|
31
|
+
color.blue.should equal 4
|
32
|
+
color.alpha.should equal 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "ahsv" do
|
37
|
+
it "should create a color with the correct values from channel values" do
|
38
|
+
color = Color.ahsv(1, 180.0, 0.5, 0.7)
|
39
|
+
color.hue.should be_within(0.001).of(180.0)
|
40
|
+
color.saturation.should be_within(0.01).of(0.5)
|
41
|
+
color.value.should be_within(0.01).of(0.7)
|
42
|
+
color.alpha.should equal 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "hsva" do
|
47
|
+
it "should create a color with the correct values from channel values" do
|
48
|
+
color = Color.hsva(180.0, 0.5, 0.7, 4)
|
49
|
+
color.hue.should be_within(0.001).of(180.0)
|
50
|
+
color.saturation.should be_within(0.01).of(0.5)
|
51
|
+
color.value.should be_within(0.01).of(0.7)
|
52
|
+
color.alpha.should equal 4
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "from_tex_play" do
|
57
|
+
it "should create a color with the correct values" do
|
58
|
+
color = Color.from_tex_play([1 / 255.0, 2 / 255.0, 3 / 255.0, 4 / 255.0])
|
59
|
+
color.red.should equal 1
|
60
|
+
color.green.should equal 2
|
61
|
+
color.blue.should equal 3
|
62
|
+
color.alpha.should equal 4
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#to_tex_play" do
|
67
|
+
it "should create an array with the correct values" do
|
68
|
+
array = Color.rgba(1, 2, 3, 4).to_tex_play
|
69
|
+
array.should eq [1 / 255.0, 2 / 255.0, 3 / 255.0, 4 / 255.0]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#==" do
|
74
|
+
it "should return true for colours that are identical" do
|
75
|
+
(Color.rgb(1, 2, 3) == Color.rgb(1, 2, 3)).should be_true
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return false for colours that are not the same" do
|
79
|
+
(Color.rgb(1, 2, 3) == Color.rgb(4, 2, 3)).should be_false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#transparent?" do
|
84
|
+
it "should be true if alpha is 0" do
|
85
|
+
Color.rgba(1, 1, 1, 0).should be_transparent
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should be false if 0 > alpha > 255" do
|
89
|
+
Color.rgba(1, 1, 1, 2).should_not be_transparent
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be false if alpha == 255" do
|
93
|
+
Color.rgba(1, 1, 1, 255).should_not be_transparent
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#opaque?" do
|
98
|
+
it "should be true if alpha is 0" do
|
99
|
+
Color.rgba(1, 1, 1, 0).should_not be_opaque
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be false if 0 > alpha > 255" do
|
103
|
+
Color.rgba(1, 1, 1, 2).should_not be_opaque
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should be false if alpha == 255" do
|
107
|
+
Color.rgba(1, 1, 1, 255).should be_opaque
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#+" do
|
112
|
+
it "should add two colours together" do
|
113
|
+
(Color.rgba(1, 2, 3, 4) + Color.rgba(10, 20, 30, 40)).should == Color.rgba(11, 22, 33, 44)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should cap values at 255" do
|
117
|
+
(Color.rgba(56, 56, 56, 56) + Color.rgba(200, 200, 200, 200)).should == Color.rgba(255, 255, 255, 255)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#-" do
|
122
|
+
it "should subtract one color from another two colours together" do
|
123
|
+
(Color.rgba(10, 20, 30, 40) - Color.rgba(1, 2, 3, 4)).should == Color.rgba(9, 18, 27, 36)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should cap values at 0" do
|
127
|
+
(Color.rgba(56, 56, 56, 56) - Color.rgba(57, 57, 57, 57)).should == Color.rgba(0, 0, 0, 0)
|
128
|
+
end
|
129
|
+
end
|
130
130
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
require "rspec"
|
2
|
-
|
1
|
+
require "rspec"
|
2
|
+
|
3
3
|
require_relative File.join(File.dirname(__FILE__), "..", "..", "..", "..", "lib", "fidgit")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "rspec"
|
2
|
-
require "fileutils"
|
3
|
-
|
1
|
+
require "rspec"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
4
|
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "fidgit"))
|
data/spec/fidgit/history_spec.rb
CHANGED
@@ -1,153 +1,153 @@
|
|
1
|
-
require_relative 'helpers/helper'
|
2
|
-
|
3
|
-
require 'history'
|
4
|
-
|
5
|
-
module Fidgit
|
6
|
-
class History
|
7
|
-
class Maths < Action
|
8
|
-
def initialize(value)
|
9
|
-
@value = value
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Add < Maths
|
14
|
-
def do
|
15
|
-
$x += @value
|
16
|
-
end
|
17
|
-
|
18
|
-
def undo
|
19
|
-
$x -= @value
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Sub < Maths
|
24
|
-
def do
|
25
|
-
$x -= @value
|
26
|
-
end
|
27
|
-
|
28
|
-
def undo
|
29
|
-
$x += @value
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe History do
|
35
|
-
before :each do
|
36
|
-
$x = 0 # Used as target of test action.
|
37
|
-
@object = described_class.new
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "initialize()" do
|
41
|
-
it "should produce an object that is not undoable or redoable" do
|
42
|
-
@object.can_undo?.should be_false
|
43
|
-
@object.can_redo?.should be_false
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "do()" do
|
48
|
-
it "should raise an error if the parameter is incorrect" do
|
49
|
-
lambda { @object.do(12) }.should raise_error ArgumentError
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should perform the action's do() method correctly" do
|
53
|
-
@object.do(History::Add.new(2))
|
54
|
-
|
55
|
-
$x.should == 2
|
56
|
-
@object.can_undo?.should be_true
|
57
|
-
@object.can_redo?.should be_false
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should correctly delete any re-doable actions, even if there is only one" do
|
61
|
-
@object.do(History::Add.new(2))
|
62
|
-
@object.undo
|
63
|
-
@object.do(History::Add.new(3))
|
64
|
-
@object.undo
|
65
|
-
|
66
|
-
@object.can_undo?.should be_false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "undo()" do
|
71
|
-
it "should raise an error if there is nothing to undo" do
|
72
|
-
lambda { @object.undo }.should raise_error
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should perform the undo method on the action" do
|
76
|
-
@object.do(History::Add.new(2))
|
77
|
-
@object.undo
|
78
|
-
|
79
|
-
$x.should == 0
|
80
|
-
@object.can_undo?.should be_false
|
81
|
-
@object.can_redo?.should be_true
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "redo()" do
|
86
|
-
it "should raise an error if there is nothing to redo" do
|
87
|
-
lambda { @object.redo }.should raise_error
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should perform the undo method on the action" do
|
91
|
-
@object.do(History::Add.new(2))
|
92
|
-
@object.undo
|
93
|
-
@object.redo
|
94
|
-
|
95
|
-
$x.should == 2
|
96
|
-
@object.can_undo?.should be_true
|
97
|
-
@object.can_redo?.should be_false
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "replace_last()" do
|
102
|
-
it "should raise an error if there is nothing to redo" do
|
103
|
-
lambda { @object.replace_last(12) }.should raise_error ArgumentError
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should raise an error if there is nothing to replace" do
|
107
|
-
lambda { @object.replace_last(History::Add2.new) }.should raise_error
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should correctly replace the last action" do
|
111
|
-
@object.do(History::Add.new(2))
|
112
|
-
@object.replace_last(History::Sub.new(1))
|
113
|
-
|
114
|
-
$x.should == -1
|
115
|
-
@object.can_redo?.should be_false
|
116
|
-
@object.can_undo?.should be_true
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should not remove redoable actions" do
|
120
|
-
@object.do(History::Add.new(2))
|
121
|
-
@object.do(History::Add.new(8))
|
122
|
-
@object.undo
|
123
|
-
@object.replace_last(History::Sub.new(1))
|
124
|
-
|
125
|
-
$x.should == -1
|
126
|
-
@object.can_redo?.should be_true
|
127
|
-
@object.can_undo?.should be_true
|
128
|
-
|
129
|
-
@object.redo
|
130
|
-
$x.should == 7
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# Abstract class, so doesn't really do anything.
|
136
|
-
describe History::Action do
|
137
|
-
before :each do
|
138
|
-
@object = described_class.new
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "do()" do
|
142
|
-
it "should raise an error" do
|
143
|
-
lambda { @object.do }.should raise_error NotImplementedError
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "undo()" do
|
148
|
-
it "should raise an error" do
|
149
|
-
lambda { @object.undo }.should raise_error NotImplementedError
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
1
|
+
require_relative 'helpers/helper'
|
2
|
+
|
3
|
+
require 'history'
|
4
|
+
|
5
|
+
module Fidgit
|
6
|
+
class History
|
7
|
+
class Maths < Action
|
8
|
+
def initialize(value)
|
9
|
+
@value = value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Add < Maths
|
14
|
+
def do
|
15
|
+
$x += @value
|
16
|
+
end
|
17
|
+
|
18
|
+
def undo
|
19
|
+
$x -= @value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Sub < Maths
|
24
|
+
def do
|
25
|
+
$x -= @value
|
26
|
+
end
|
27
|
+
|
28
|
+
def undo
|
29
|
+
$x += @value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe History do
|
35
|
+
before :each do
|
36
|
+
$x = 0 # Used as target of test action.
|
37
|
+
@object = described_class.new
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "initialize()" do
|
41
|
+
it "should produce an object that is not undoable or redoable" do
|
42
|
+
@object.can_undo?.should be_false
|
43
|
+
@object.can_redo?.should be_false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "do()" do
|
48
|
+
it "should raise an error if the parameter is incorrect" do
|
49
|
+
lambda { @object.do(12) }.should raise_error ArgumentError
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should perform the action's do() method correctly" do
|
53
|
+
@object.do(History::Add.new(2))
|
54
|
+
|
55
|
+
$x.should == 2
|
56
|
+
@object.can_undo?.should be_true
|
57
|
+
@object.can_redo?.should be_false
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should correctly delete any re-doable actions, even if there is only one" do
|
61
|
+
@object.do(History::Add.new(2))
|
62
|
+
@object.undo
|
63
|
+
@object.do(History::Add.new(3))
|
64
|
+
@object.undo
|
65
|
+
|
66
|
+
@object.can_undo?.should be_false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "undo()" do
|
71
|
+
it "should raise an error if there is nothing to undo" do
|
72
|
+
lambda { @object.undo }.should raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should perform the undo method on the action" do
|
76
|
+
@object.do(History::Add.new(2))
|
77
|
+
@object.undo
|
78
|
+
|
79
|
+
$x.should == 0
|
80
|
+
@object.can_undo?.should be_false
|
81
|
+
@object.can_redo?.should be_true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "redo()" do
|
86
|
+
it "should raise an error if there is nothing to redo" do
|
87
|
+
lambda { @object.redo }.should raise_error
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should perform the undo method on the action" do
|
91
|
+
@object.do(History::Add.new(2))
|
92
|
+
@object.undo
|
93
|
+
@object.redo
|
94
|
+
|
95
|
+
$x.should == 2
|
96
|
+
@object.can_undo?.should be_true
|
97
|
+
@object.can_redo?.should be_false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "replace_last()" do
|
102
|
+
it "should raise an error if there is nothing to redo" do
|
103
|
+
lambda { @object.replace_last(12) }.should raise_error ArgumentError
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should raise an error if there is nothing to replace" do
|
107
|
+
lambda { @object.replace_last(History::Add2.new) }.should raise_error
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should correctly replace the last action" do
|
111
|
+
@object.do(History::Add.new(2))
|
112
|
+
@object.replace_last(History::Sub.new(1))
|
113
|
+
|
114
|
+
$x.should == -1
|
115
|
+
@object.can_redo?.should be_false
|
116
|
+
@object.can_undo?.should be_true
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should not remove redoable actions" do
|
120
|
+
@object.do(History::Add.new(2))
|
121
|
+
@object.do(History::Add.new(8))
|
122
|
+
@object.undo
|
123
|
+
@object.replace_last(History::Sub.new(1))
|
124
|
+
|
125
|
+
$x.should == -1
|
126
|
+
@object.can_redo?.should be_true
|
127
|
+
@object.can_undo?.should be_true
|
128
|
+
|
129
|
+
@object.redo
|
130
|
+
$x.should == 7
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Abstract class, so doesn't really do anything.
|
136
|
+
describe History::Action do
|
137
|
+
before :each do
|
138
|
+
@object = described_class.new
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "do()" do
|
142
|
+
it "should raise an error" do
|
143
|
+
lambda { @object.do }.should raise_error NotImplementedError
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "undo()" do
|
148
|
+
it "should raise an error" do
|
149
|
+
lambda { @object.undo }.should raise_error NotImplementedError
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|