nayutaya-kagemusha 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +33 -0
- data/HISTORY.ja +43 -0
- data/LICENSE +54 -0
- data/README +57 -0
- data/README.ja +59 -0
- data/Rakefile +29 -0
- data/examples/date.rb +22 -0
- data/examples/datetime.rb +32 -0
- data/examples/first.rb +23 -0
- data/examples/rand.rb +32 -0
- data/examples/style.rb +39 -0
- data/examples/time.rb +22 -0
- data/kagemusha.gemspec +67 -0
- data/kagemusha.gemspec.erb +33 -0
- data/lib/kagemusha/composite.rb +42 -0
- data/lib/kagemusha/core.rb +160 -0
- data/lib/kagemusha/date.rb +35 -0
- data/lib/kagemusha/datetime.rb +41 -0
- data/lib/kagemusha/rand.rb +27 -0
- data/lib/kagemusha/time.rb +34 -0
- data/lib/kagemusha/version.rb +12 -0
- data/lib/kagemusha.rb +11 -0
- data/test/test_bugs.rb +116 -0
- data/test/test_complex_cases.rb +783 -0
- data/test/test_composite.rb +107 -0
- data/test/test_date.rb +44 -0
- data/test/test_datetime.rb +54 -0
- data/test/test_helper.rb +11 -0
- data/test/test_kagemusha.rb +257 -0
- data/test/test_rand.rb +48 -0
- data/test/test_time.rb +44 -0
- metadata +91 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#==============================================================================#
|
4
|
+
# $Id: test_composite.rb 108 2009-02-09 06:04:39Z yuyakato $
|
5
|
+
#==============================================================================#
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
8
|
+
require "date"
|
9
|
+
|
10
|
+
#==============================================================================#
|
11
|
+
|
12
|
+
class TestComposite < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@com = Kagemusha::Composite.new
|
15
|
+
@musha1 = Kagemusha.new(Time)
|
16
|
+
@musha2 = Kagemusha.new(Date)
|
17
|
+
@musha3 = Kagemusha.new(Regexp)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize
|
21
|
+
com1 = Kagemusha::Composite.new
|
22
|
+
assert_equal([], com1.mocks)
|
23
|
+
|
24
|
+
com2 = Kagemusha::Composite.new(@musha1)
|
25
|
+
assert_equal([@musha1], com2.mocks)
|
26
|
+
|
27
|
+
com3 = Kagemusha::Composite.new(@musha1, @musha2)
|
28
|
+
assert_equal([@musha1, @musha2], com3.mocks)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_size
|
32
|
+
assert_equal(0, @com.size)
|
33
|
+
|
34
|
+
@com << @musha1
|
35
|
+
assert_equal(1, @com.size)
|
36
|
+
|
37
|
+
@com << @musha2
|
38
|
+
assert_equal(2, @com.size)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_add
|
42
|
+
assert_equal([], @com.mocks)
|
43
|
+
|
44
|
+
assert_equal(@com, @com.add(@musha1))
|
45
|
+
assert_equal([@musha1], @com.mocks)
|
46
|
+
|
47
|
+
assert_equal(@com, @com << @musha2)
|
48
|
+
assert_equal([@musha1, @musha2], @com.mocks)
|
49
|
+
|
50
|
+
assert_raise(ArgumentError) {
|
51
|
+
@com << 1
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_concat
|
56
|
+
com1 = @com
|
57
|
+
assert_equal([], com1.mocks)
|
58
|
+
|
59
|
+
com2 = com1.concat(@musha1)
|
60
|
+
assert_equal([], com1.mocks)
|
61
|
+
assert_equal([@musha1], com2.mocks)
|
62
|
+
|
63
|
+
com3 = com2 + @musha2
|
64
|
+
assert_equal([], com1.mocks)
|
65
|
+
assert_equal([@musha1], com2.mocks)
|
66
|
+
assert_equal([@musha1, @musha2], com3.mocks)
|
67
|
+
|
68
|
+
com4 = Kagemusha::Composite.new(@musha3)
|
69
|
+
|
70
|
+
com5 = com3 + com4
|
71
|
+
assert_equal([], com1.mocks)
|
72
|
+
assert_equal([@musha1], com2.mocks)
|
73
|
+
assert_equal([@musha1, @musha2], com3.mocks)
|
74
|
+
assert_equal([@musha1, @musha2, com4], com5.mocks)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_swap
|
78
|
+
@musha1.defs(:now) { :now }
|
79
|
+
@musha2.defs(:today) { :today }
|
80
|
+
|
81
|
+
assert_not_equal(:now, Time.now)
|
82
|
+
assert_not_equal(:today, Date.today)
|
83
|
+
|
84
|
+
@musha1.swap {
|
85
|
+
@musha2.swap {
|
86
|
+
assert_equal(:now, Time.now)
|
87
|
+
assert_equal(:today, Date.today)
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
assert_not_equal(:now, Time.now)
|
92
|
+
assert_not_equal(:today, Date.today)
|
93
|
+
|
94
|
+
ret = (@musha1 + @musha2).swap {
|
95
|
+
assert_equal(:now, Time.now)
|
96
|
+
assert_equal(:today, Date.today)
|
97
|
+
1
|
98
|
+
}
|
99
|
+
assert_equal(1, ret)
|
100
|
+
|
101
|
+
assert_not_equal(:now, Time.now)
|
102
|
+
assert_not_equal(:today, Date.today)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
#==============================================================================#
|
107
|
+
#==============================================================================#
|
data/test/test_date.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#==============================================================================#
|
4
|
+
# $Id: test_date.rb 108 2009-02-09 06:04:39Z yuyakato $
|
5
|
+
#==============================================================================#
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
8
|
+
require File.dirname(__FILE__) + "/../lib/kagemusha/date"
|
9
|
+
|
10
|
+
#==============================================================================#
|
11
|
+
|
12
|
+
class TestKagemushaDate < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_on
|
17
|
+
musha1 = Kagemusha::Date.on(2007, 1, 2)
|
18
|
+
assert_equal(Date, musha1.instance_eval { @klass })
|
19
|
+
musha1.swap {
|
20
|
+
assert_equal(Date.new(2007, 1, 2), Date.today)
|
21
|
+
}
|
22
|
+
|
23
|
+
musha2 = Kagemusha::Date.on(Date.new(1984, 5, 11))
|
24
|
+
musha2.swap {
|
25
|
+
assert_equal(Date.new(1984, 5, 11), Date.today)
|
26
|
+
}
|
27
|
+
|
28
|
+
assert_raise(ArgumentError) {
|
29
|
+
Kagemusha::Date.on(:symbol)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_on_with_block
|
34
|
+
ret = Kagemusha::Date.on(2007, 1, 2) {
|
35
|
+
assert_equal(Date.new(2007, 1, 2), Date.today)
|
36
|
+
1
|
37
|
+
}
|
38
|
+
|
39
|
+
assert_equal(1, ret)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#==============================================================================#
|
44
|
+
#==============================================================================#
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#==============================================================================#
|
4
|
+
# $Id: test_datetime.rb 108 2009-02-09 06:04:39Z yuyakato $
|
5
|
+
#==============================================================================#
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
8
|
+
require File.dirname(__FILE__) + "/../lib/kagemusha/date"
|
9
|
+
require File.dirname(__FILE__) + "/../lib/kagemusha/time"
|
10
|
+
require File.dirname(__FILE__) + "/../lib/kagemusha/datetime"
|
11
|
+
|
12
|
+
#==============================================================================#
|
13
|
+
|
14
|
+
class TestKagemushaDateTime < Test::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_at
|
19
|
+
musha1 = Kagemusha::DateTime.at(2007, 1, 2, 3, 4, 5)
|
20
|
+
musha1.swap {
|
21
|
+
assert_equal(Date.new(2007, 1, 2), Date.today)
|
22
|
+
assert_equal(Time.local(2007, 1, 2, 3, 4, 5), Time.now)
|
23
|
+
}
|
24
|
+
|
25
|
+
musha2 = Kagemusha::DateTime.at(Date.new(1984, 5, 11))
|
26
|
+
musha2.swap {
|
27
|
+
assert_equal(Date.new(1984, 5, 11), Date.today)
|
28
|
+
assert_equal(Time.local(1984, 5, 11), Time.now)
|
29
|
+
}
|
30
|
+
|
31
|
+
musha3 = Kagemusha::DateTime.at(Time.local(1984, 5, 11))
|
32
|
+
musha3.swap {
|
33
|
+
assert_equal(Date.new(1984, 5, 11), Date.today)
|
34
|
+
assert_equal(Time.local(1984, 5, 11), Time.now)
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_raise(ArgumentError) {
|
38
|
+
Kagemusha::DateTime.at(:symbol)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_at_with_block
|
43
|
+
ret = Kagemusha::DateTime.at(2007, 1, 2, 3, 4, 5) {
|
44
|
+
assert_equal(Date.new(2007, 1, 2), Date.today)
|
45
|
+
assert_equal(Time.local(2007, 1, 2, 3, 4, 5), Time.now)
|
46
|
+
1
|
47
|
+
}
|
48
|
+
|
49
|
+
assert_equal(1, ret)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#==============================================================================#
|
54
|
+
#==============================================================================#
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#==============================================================================#
|
4
|
+
# $Id: test_helper.rb 110 2009-02-09 07:20:20Z yuyakato $
|
5
|
+
#==============================================================================#
|
6
|
+
|
7
|
+
require "test/unit"
|
8
|
+
require File.dirname(__FILE__) + "/../lib/kagemusha"
|
9
|
+
|
10
|
+
#==============================================================================#
|
11
|
+
#==============================================================================#
|
@@ -0,0 +1,257 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#==============================================================================#
|
4
|
+
# $Id: test_kagemusha.rb 108 2009-02-09 06:04:39Z yuyakato $
|
5
|
+
#==============================================================================#
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
8
|
+
|
9
|
+
#==============================================================================#
|
10
|
+
|
11
|
+
class TestKagemusha < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@musha = Kagemusha.new(String)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize
|
17
|
+
klass = String
|
18
|
+
meta = class << klass; self; end
|
19
|
+
|
20
|
+
assert_kind_of(Kagemusha, @musha)
|
21
|
+
assert_equal(klass, @musha.instance_eval { @klass })
|
22
|
+
assert_equal(meta, @musha.instance_eval { @meta })
|
23
|
+
assert_equal({}, @musha.instance_eval { @class_methods })
|
24
|
+
assert_equal({}, @musha.instance_eval { @instance_methods })
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_initialize_with_block
|
28
|
+
arg = nil
|
29
|
+
|
30
|
+
ret = Kagemusha.new(String) { |x|
|
31
|
+
arg = x
|
32
|
+
}
|
33
|
+
|
34
|
+
assert_kind_of(Kagemusha, ret)
|
35
|
+
assert_same(ret, arg)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_define_class_method_and_undefine
|
39
|
+
block1 = proc { 1 }
|
40
|
+
block2 = proc { 2 }
|
41
|
+
|
42
|
+
assert_equal(nil, @musha.instance_eval { @class_methods[:foo] })
|
43
|
+
assert_equal(nil, @musha.instance_eval { @class_methods[:bar] })
|
44
|
+
|
45
|
+
ret = @musha.define_class_method(:foo, &block1)
|
46
|
+
|
47
|
+
assert_same(ret, @musha)
|
48
|
+
assert_equal(block1, @musha.instance_eval { @class_methods[:foo] })
|
49
|
+
assert_equal(nil, @musha.instance_eval { @class_methods[:bar] })
|
50
|
+
|
51
|
+
ret = @musha.define_class_method("bar", &block2)
|
52
|
+
|
53
|
+
assert_same(ret, @musha)
|
54
|
+
assert_equal(block1, @musha.instance_eval { @class_methods[:foo] })
|
55
|
+
assert_equal(block2, @musha.instance_eval { @class_methods[:bar] })
|
56
|
+
|
57
|
+
ret = @musha.undefine_class_method("foo")
|
58
|
+
|
59
|
+
assert_same(ret, @musha)
|
60
|
+
assert_equal(false, @musha.instance_eval { @class_methods[:foo] })
|
61
|
+
assert_equal(block2, @musha.instance_eval { @class_methods[:bar] })
|
62
|
+
|
63
|
+
ret = @musha.undefine_class_method(:bar)
|
64
|
+
|
65
|
+
assert_same(ret, @musha)
|
66
|
+
assert_equal(false, @musha.instance_eval { @class_methods[:foo] })
|
67
|
+
assert_equal(false, @musha.instance_eval { @class_methods[:bar] })
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_defs_and_undefs
|
71
|
+
block = proc { 1 }
|
72
|
+
|
73
|
+
assert_equal(nil, @musha.instance_eval { @class_methods[:foo] })
|
74
|
+
|
75
|
+
ret = @musha.defs(:foo, &block)
|
76
|
+
|
77
|
+
assert_same(ret, @musha)
|
78
|
+
assert_equal(block, @musha.instance_eval { @class_methods[:foo] })
|
79
|
+
|
80
|
+
ret = @musha.undefs(:foo)
|
81
|
+
|
82
|
+
assert_same(ret, @musha)
|
83
|
+
assert_equal(false, @musha.instance_eval { @class_methods[:foo] })
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_define_instance_method_and_undefine
|
87
|
+
block1 = proc { 1 }
|
88
|
+
block2 = proc { 2 }
|
89
|
+
|
90
|
+
assert_equal(nil, @musha.instance_eval { @instance_methods[:foo] })
|
91
|
+
assert_equal(nil, @musha.instance_eval { @instance_methods[:bar] })
|
92
|
+
|
93
|
+
ret = @musha.define_instance_method(:foo, &block1)
|
94
|
+
|
95
|
+
assert_same(ret, @musha)
|
96
|
+
assert_equal(block1, @musha.instance_eval { @instance_methods[:foo] })
|
97
|
+
assert_equal(nil, @musha.instance_eval { @instance_methods[:bar] })
|
98
|
+
|
99
|
+
ret = @musha.define_instance_method("bar", &block2)
|
100
|
+
|
101
|
+
assert_same(ret, @musha)
|
102
|
+
assert_equal(block1, @musha.instance_eval { @instance_methods[:foo] })
|
103
|
+
assert_equal(block2, @musha.instance_eval { @instance_methods[:bar] })
|
104
|
+
|
105
|
+
ret = @musha.undefine_instance_method("foo")
|
106
|
+
|
107
|
+
assert_same(ret, @musha)
|
108
|
+
assert_equal(false, @musha.instance_eval { @instance_methods[:foo] })
|
109
|
+
assert_equal(block2, @musha.instance_eval { @instance_methods[:bar] })
|
110
|
+
|
111
|
+
ret = @musha.undefine_instance_method(:bar)
|
112
|
+
|
113
|
+
assert_same(ret, @musha)
|
114
|
+
assert_equal(false, @musha.instance_eval { @instance_methods[:foo] })
|
115
|
+
assert_equal(false, @musha.instance_eval { @instance_methods[:bar] })
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_def_and_undef
|
119
|
+
block = proc { 1 }
|
120
|
+
|
121
|
+
assert_equal(nil, @musha.instance_eval { @instance_methods[:foo] })
|
122
|
+
|
123
|
+
ret = @musha.def(:foo, &block)
|
124
|
+
|
125
|
+
assert_same(ret, @musha)
|
126
|
+
assert_equal(block, @musha.instance_eval { @instance_methods[:foo] })
|
127
|
+
|
128
|
+
ret = @musha.undef(:foo)
|
129
|
+
|
130
|
+
assert_same(ret, @musha)
|
131
|
+
assert_equal(false, @musha.instance_eval { @instance_methods[:foo] })
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_swap_class_method
|
135
|
+
@musha = Kagemusha.new(Regexp)
|
136
|
+
@musha.defs(:compile) { |string| /bar/ }
|
137
|
+
|
138
|
+
assert_equal(/foo/, Regexp.compile("foo"))
|
139
|
+
|
140
|
+
ret = @musha.swap {
|
141
|
+
assert_equal(/bar/, Regexp.compile("foo"))
|
142
|
+
1
|
143
|
+
}
|
144
|
+
|
145
|
+
assert_equal(1, ret)
|
146
|
+
assert_equal(/foo/, Regexp.compile("foo"))
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_swap_instance_method
|
150
|
+
target = "foo"
|
151
|
+
@musha.def(:to_s) { "bar" }
|
152
|
+
|
153
|
+
assert_equal("foo", target.to_s)
|
154
|
+
|
155
|
+
ret = @musha.swap {
|
156
|
+
assert_equal("bar", target.to_s)
|
157
|
+
1
|
158
|
+
}
|
159
|
+
|
160
|
+
assert_equal(1, ret)
|
161
|
+
assert_equal("foo", target.to_s)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_insert_new_class_method
|
165
|
+
assert_raise(NoMethodError) {
|
166
|
+
String.foo
|
167
|
+
}
|
168
|
+
|
169
|
+
@musha.defs(:foo) { :ok }
|
170
|
+
|
171
|
+
assert_raise(NoMethodError) {
|
172
|
+
String.foo
|
173
|
+
}
|
174
|
+
assert_nothing_raised {
|
175
|
+
@musha.swap {
|
176
|
+
assert_equal(:ok, String.foo)
|
177
|
+
}
|
178
|
+
}
|
179
|
+
assert_raise(NoMethodError) {
|
180
|
+
String.foo
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_remove_exist_class_method
|
185
|
+
assert_nothing_raised {
|
186
|
+
String.clone
|
187
|
+
}
|
188
|
+
|
189
|
+
@musha.undefs(:clone)
|
190
|
+
|
191
|
+
assert_nothing_raised {
|
192
|
+
String.clone
|
193
|
+
}
|
194
|
+
assert_raise(NoMethodError) {
|
195
|
+
@musha.swap {
|
196
|
+
String.clone
|
197
|
+
}
|
198
|
+
}
|
199
|
+
assert_nothing_raised {
|
200
|
+
String.clone
|
201
|
+
}
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_insert_new_instance_method
|
205
|
+
assert_raise(NoMethodError) {
|
206
|
+
"".foo
|
207
|
+
}
|
208
|
+
|
209
|
+
@musha.def(:foo) { :ok }
|
210
|
+
|
211
|
+
assert_raise(NoMethodError) {
|
212
|
+
"".foo
|
213
|
+
}
|
214
|
+
assert_nothing_raised {
|
215
|
+
@musha.swap {
|
216
|
+
assert_equal(:ok, "".foo)
|
217
|
+
}
|
218
|
+
}
|
219
|
+
assert_raise(NoMethodError) {
|
220
|
+
"".foo
|
221
|
+
}
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_remove_exist_instance_method
|
225
|
+
assert_nothing_raised {
|
226
|
+
"".clone
|
227
|
+
}
|
228
|
+
|
229
|
+
@musha.undef(:clone)
|
230
|
+
|
231
|
+
assert_nothing_raised {
|
232
|
+
"".clone
|
233
|
+
}
|
234
|
+
assert_raise(NoMethodError) {
|
235
|
+
@musha.swap {
|
236
|
+
"".clone
|
237
|
+
}
|
238
|
+
}
|
239
|
+
assert_nothing_raised {
|
240
|
+
"".clone
|
241
|
+
}
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_concat
|
245
|
+
musha2 = Kagemusha.new(Time)
|
246
|
+
musha3 = Kagemusha.new(Regexp)
|
247
|
+
|
248
|
+
com1 = @musha.concat(musha2)
|
249
|
+
assert_equal([@musha, musha2], com1.mocks)
|
250
|
+
|
251
|
+
com2 = musha3 + com1
|
252
|
+
assert_equal([musha3, com1], com2.mocks)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
#==============================================================================#
|
257
|
+
#==============================================================================#
|
data/test/test_rand.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#==============================================================================#
|
4
|
+
# $Id: test_rand.rb 108 2009-02-09 06:04:39Z yuyakato $
|
5
|
+
#==============================================================================#
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
8
|
+
require File.dirname(__FILE__) + "/../lib/kagemusha/rand"
|
9
|
+
|
10
|
+
#==============================================================================#
|
11
|
+
|
12
|
+
class TestKagemushaRand < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_always
|
17
|
+
musha = Kagemusha::Rand.always(1)
|
18
|
+
assert_equal(Kernel, musha.instance_eval { @klass })
|
19
|
+
|
20
|
+
assert_equal([0, 1, 2], (1..100).map { rand(3) }.sort.uniq)
|
21
|
+
|
22
|
+
musha.swap {
|
23
|
+
assert_equal(1, rand)
|
24
|
+
assert_equal(1, rand(2))
|
25
|
+
assert_equal(1, rand(3))
|
26
|
+
assert_equal(1, rand(4))
|
27
|
+
assert_equal(1, rand(5))
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_equal([0, 1, 2], (1..100).map { rand(3) }.sort.uniq)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_always_with_block
|
34
|
+
ret = Kagemusha::Rand.always(1) {
|
35
|
+
assert_equal(1, rand)
|
36
|
+
assert_equal(1, rand(2))
|
37
|
+
assert_equal(1, rand(3))
|
38
|
+
assert_equal(1, rand(4))
|
39
|
+
assert_equal(1, rand(5))
|
40
|
+
1
|
41
|
+
}
|
42
|
+
|
43
|
+
assert_equal(1, ret)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#==============================================================================#
|
48
|
+
#==============================================================================#
|
data/test/test_time.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#==============================================================================#
|
4
|
+
# $Id: test_time.rb 108 2009-02-09 06:04:39Z yuyakato $
|
5
|
+
#==============================================================================#
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
8
|
+
require File.dirname(__FILE__) + "/../lib/kagemusha/time"
|
9
|
+
|
10
|
+
#==============================================================================#
|
11
|
+
|
12
|
+
class TestKagemushaTime < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_at
|
17
|
+
musha1 = Kagemusha::Time.at(2007, 1, 2, 3, 4, 5)
|
18
|
+
assert_equal(Time, musha1.instance_eval { @klass })
|
19
|
+
musha1.swap {
|
20
|
+
assert_equal(Time.local(2007, 1, 2, 3, 4, 5), Time.now)
|
21
|
+
}
|
22
|
+
|
23
|
+
musha2 = Kagemusha::Time.at(Time.local(1984, 5, 11))
|
24
|
+
musha2.swap {
|
25
|
+
assert_equal(Time.local(1984, 5, 11), Time.now)
|
26
|
+
}
|
27
|
+
|
28
|
+
assert_raise(ArgumentError) {
|
29
|
+
Kagemusha::Time.at(:symbol)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_at_with_block
|
34
|
+
ret = Kagemusha::Time.at(2007, 1, 2, 3, 4, 5) {
|
35
|
+
assert_equal(Time.local(2007, 1, 2, 3, 4, 5), Time.now)
|
36
|
+
1
|
37
|
+
}
|
38
|
+
|
39
|
+
assert_equal(1, ret)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#==============================================================================#
|
44
|
+
#==============================================================================#
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nayutaya-kagemusha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuya Kato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-29 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: kagemusha
|
17
|
+
email: yuyakato@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- examples/date.rb
|
26
|
+
- examples/datetime.rb
|
27
|
+
- examples/first.rb
|
28
|
+
- examples/rand.rb
|
29
|
+
- examples/style.rb
|
30
|
+
- examples/time.rb
|
31
|
+
- HISTORY
|
32
|
+
- HISTORY.ja
|
33
|
+
- kagemusha.gemspec
|
34
|
+
- kagemusha.gemspec.erb
|
35
|
+
- lib/kagemusha/composite.rb
|
36
|
+
- lib/kagemusha/core.rb
|
37
|
+
- lib/kagemusha/date.rb
|
38
|
+
- lib/kagemusha/datetime.rb
|
39
|
+
- lib/kagemusha/rand.rb
|
40
|
+
- lib/kagemusha/time.rb
|
41
|
+
- lib/kagemusha/version.rb
|
42
|
+
- lib/kagemusha.rb
|
43
|
+
- LICENSE
|
44
|
+
- Rakefile
|
45
|
+
- README
|
46
|
+
- README.ja
|
47
|
+
- test/test_bugs.rb
|
48
|
+
- test/test_complex_cases.rb
|
49
|
+
- test/test_composite.rb
|
50
|
+
- test/test_date.rb
|
51
|
+
- test/test_datetime.rb
|
52
|
+
- test/test_helper.rb
|
53
|
+
- test/test_kagemusha.rb
|
54
|
+
- test/test_rand.rb
|
55
|
+
- test/test_time.rb
|
56
|
+
has_rdoc: false
|
57
|
+
homepage: http://github.com/nayutaya/kagemusha/
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.8.6
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.2.0
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: kagemusha
|
82
|
+
test_files:
|
83
|
+
- test/test_bugs.rb
|
84
|
+
- test/test_complex_cases.rb
|
85
|
+
- test/test_composite.rb
|
86
|
+
- test/test_date.rb
|
87
|
+
- test/test_datetime.rb
|
88
|
+
- test/test_helper.rb
|
89
|
+
- test/test_kagemusha.rb
|
90
|
+
- test/test_rand.rb
|
91
|
+
- test/test_time.rb
|