y_support 2.1.5 → 2.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +675 -0
- data/Rakefile +1 -1
- data/lib/y_support/abstract_algebra.rb +1 -0
- data/lib/y_support/all.rb +1 -0
- data/lib/y_support/core_ext/array.rb +2 -2
- data/lib/y_support/core_ext/class/misc.rb +2 -3
- data/lib/y_support/core_ext/class.rb +2 -2
- data/lib/y_support/core_ext/enumerable/misc.rb +1 -1
- data/lib/y_support/core_ext/enumerable.rb +2 -2
- data/lib/y_support/core_ext/hash/misc.rb +26 -39
- data/lib/y_support/core_ext/hash.rb +2 -2
- data/lib/y_support/core_ext/module/misc.rb +39 -1
- data/lib/y_support/core_ext/module.rb +2 -2
- data/lib/y_support/core_ext/numeric/misc.rb +0 -2
- data/lib/y_support/core_ext/numeric.rb +2 -2
- data/lib/y_support/core_ext/object/inspection.rb +0 -2
- data/lib/y_support/core_ext/object/misc.rb +31 -16
- data/lib/y_support/core_ext/object.rb +3 -3
- data/lib/y_support/core_ext/string/misc.rb +7 -7
- data/lib/y_support/core_ext/string.rb +2 -2
- data/lib/y_support/core_ext/symbol/misc.rb +2 -3
- data/lib/y_support/core_ext/symbol.rb +2 -2
- data/lib/y_support/core_ext.rb +0 -2
- data/lib/y_support/inert_recorder.rb +1 -1
- data/lib/y_support/kde.rb +1 -0
- data/lib/y_support/name_magic/array.rb +27 -7
- data/lib/y_support/name_magic/class_methods.rb +52 -58
- data/lib/y_support/name_magic/hash.rb +18 -4
- data/lib/y_support/name_magic/namespace_methods.rb +241 -174
- data/lib/y_support/name_magic.rb +82 -38
- data/lib/y_support/null_object.rb +8 -7
- data/lib/y_support/respond_to.rb +1 -2
- data/lib/y_support/stdlib_ext/matrix/misc.rb +0 -2
- data/lib/y_support/stdlib_ext/matrix.rb +2 -2
- data/lib/y_support/stdlib_ext.rb +1 -0
- data/lib/y_support/try.rb +1 -1
- data/lib/y_support/typing/array/typing.rb +45 -4
- data/lib/y_support/typing/array.rb +1 -1
- data/lib/y_support/typing/enumerable/typing.rb +26 -28
- data/lib/y_support/typing/enumerable.rb +1 -1
- data/lib/y_support/typing/hash/typing.rb +47 -29
- data/lib/y_support/typing/hash.rb +1 -1
- data/lib/y_support/typing/module/typing.rb +4 -6
- data/lib/y_support/typing/module.rb +1 -1
- data/lib/y_support/typing/object/typing.rb +64 -61
- data/lib/y_support/typing/object.rb +1 -1
- data/lib/y_support/typing.rb +4 -26
- data/lib/y_support/unicode.rb +5 -7
- data/lib/y_support/version.rb +1 -1
- data/lib/y_support/x.rb +11 -8
- data/lib/y_support.rb +2 -2
- data/test/abstract_algebra_test.rb +44 -55
- data/test/inert_recorder_test.rb +13 -18
- data/test/local_object_test.rb +13 -18
- data/test/misc_test.rb +15 -10
- data/test/name_magic_test.rb +1 -1
- data/test/null_object_test.rb +19 -26
- data/test/respond_to_test.rb +15 -16
- data/test/typing_test.rb +100 -103
- data/test/x_test.rb +16 -19
- data/y_support.gemspec +21 -17
- metadata +37 -8
- data/LICENSE +0 -22
data/lib/y_support/typing.rb
CHANGED
@@ -1,34 +1,12 @@
|
|
1
|
-
#encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'y_support'
|
4
4
|
|
5
5
|
# Typing library.
|
6
6
|
#
|
7
|
-
# Apart from
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# runtime assertions for <em>duck type</em> examination.
|
11
|
-
#
|
12
|
-
# 1. Using method <b>declare_compliance</b>, a module (class) can explicitly
|
13
|
-
# declare, that it provides an interface compliant with another module (class).
|
14
|
-
# Corresponding inquirer methods are <b>declared_compliance</b> (returns a list
|
15
|
-
# of modules, to which the receiver declares compliance, or implicitly complies
|
16
|
-
# by ancestry), and <b>declares_compliance?( other_module )</b>, which tells,
|
17
|
-
# whether the receiver complies with a specific module. An object always
|
18
|
-
# implicitly complies with its class and ancestry.
|
19
|
-
#
|
20
|
-
# 2. Duck type examination is supported by a collection of runtime assertions.
|
21
|
-
# These start with <b>tE_...</b>, meaning "enforce ... by raising TypeError".
|
22
|
-
#
|
23
|
-
class Object
|
24
|
-
# Alias for ArgumentError
|
25
|
-
#
|
26
|
-
AErr = ArgumentError
|
27
|
-
|
28
|
-
# Alias for TypeError
|
29
|
-
#
|
30
|
-
TErr = TypeError
|
31
|
-
end
|
7
|
+
# Apart from typing objects <em>by class and ancestry</em> (+#kind_of?+),
|
8
|
+
# y_support typing library provides support for typing <em>by declaration</em>,
|
9
|
+
# and for runtime assertions.
|
32
10
|
|
33
11
|
directories_to_look_in = [ :typing ]
|
34
12
|
|
data/lib/y_support/unicode.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'y_support'
|
4
4
|
|
5
|
-
#
|
5
|
+
# +y_support/unicode+ defines a small number of Unicode 1-character aliases to
|
6
|
+
# make code more concise.
|
6
7
|
#
|
7
8
|
# * <b>ç</b> – class (c with cedilla, U00E7)
|
8
9
|
# * <b>ⓒ</b> – singleton class (copyright sign)
|
@@ -35,8 +36,7 @@ class Object
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
-
# Defined aliases:
|
39
|
+
# +y_support/unicode+ also defines the following aliases:
|
40
40
|
#
|
41
41
|
# * <b>★</b> – alias for include
|
42
42
|
# * <b>ç</b> for +class+ in several method names
|
@@ -50,19 +50,18 @@ class Module
|
|
50
50
|
alias remove_ç_variable remove_class_variable
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
53
|
# Defined aliases
|
56
54
|
#
|
57
55
|
# * <b>√</b> – root of arbitrary degree ( x.√( n ) is n ** ( 1 / x ) ).
|
58
56
|
# * <b>sqrt</b> as in +4.sqrt+ for square root (Math#sqrt).
|
59
57
|
#
|
60
58
|
class Numeric
|
59
|
+
# Returns n-th root of the argument, where n is the receiver number.
|
60
|
+
#
|
61
61
|
def √ number
|
62
62
|
number ** ( 1.0 / self )
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
65
|
# Square root (using Math#sqrt).
|
67
66
|
#
|
68
67
|
def sqrt
|
@@ -70,7 +69,6 @@ class Numeric
|
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
73
|
-
|
74
72
|
# Other abbreviations (eg. for local variables) are optionally encouraged:
|
75
73
|
#
|
76
74
|
# * <b>ɱ</b> – module (m with hook, U2C6E, compose seq. [m, j])
|
data/lib/y_support/version.rb
CHANGED
data/lib/y_support/x.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
require 'y_support'
|
2
|
-
require 'gtk2'
|
3
2
|
|
3
|
+
# Assets related to X windows control.
|
4
|
+
#
|
4
5
|
module YSupport::X
|
5
|
-
# Echo a string to the primary X clip
|
6
|
-
#
|
7
|
-
def echo_primary_clipboard
|
8
|
-
|
6
|
+
# Echo a string to the primary X clip; `xsel -b -i`.
|
7
|
+
#
|
8
|
+
def echo_primary_clipboard string
|
9
|
+
s = 'echo -n ' + string.inspect + ' | xsel -b -i'
|
10
|
+
system s
|
9
11
|
end
|
10
12
|
|
11
|
-
# Echo a string to the secondary X clip
|
13
|
+
# Echo a string to the secondary X clip; `xsel -b -i`.
|
12
14
|
#
|
13
|
-
def echo_secondary_clipboard
|
14
|
-
|
15
|
+
def echo_secondary_clipboard string
|
16
|
+
s = 'echo -n ' + string.inspect + ' | xsel -s -i'
|
17
|
+
system s
|
15
18
|
end
|
16
19
|
|
17
20
|
# Dialog box querying for a string.
|
data/lib/y_support.rb
CHANGED
@@ -1,41 +1,38 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# Define the stupidest
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
new # just make up an instance
|
28
|
-
else
|
29
|
-
ꜧ[k[1], k[0]] # swap operands
|
30
|
-
end
|
31
|
-
}
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
describe "Algebra" do
|
7
|
+
before do
|
8
|
+
require './../lib/y_support/abstract_algebra'
|
9
|
+
# Define the stupidest monoid:
|
10
|
+
@monoid = Class.new { include Algebra::Monoid } # make some class
|
11
|
+
zero = @monoid.new # call arbitrary instance zero
|
12
|
+
@monoid.class_exec {
|
13
|
+
# Define the stupidest #add method.
|
14
|
+
define_method :add do |other|
|
15
|
+
if self == zero then other
|
16
|
+
elsif other == zero then self
|
17
|
+
else self.class.addition_table[[self, other]] end
|
18
|
+
end
|
19
|
+
# Define the stupidest addition table.
|
20
|
+
instance_variable_set :@addition_table,
|
21
|
+
Hash.new { |ꜧ, k|
|
22
|
+
ꜧ[k] = if k[0].object_id <= k[1].object_id
|
23
|
+
new # just make up an instance
|
24
|
+
else
|
25
|
+
ꜧ[k[1], k[0]] # swap operands
|
26
|
+
end
|
32
27
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
28
|
+
}
|
29
|
+
# And refine the @monoid's singleton class.
|
30
|
+
@monoid.singleton_class.class_exec { attr_reader :addition_table }
|
31
|
+
@monoid.define_singleton_method :additive_identity do zero end
|
32
|
+
end
|
37
33
|
|
38
|
-
|
34
|
+
describe "Algebra" do
|
35
|
+
it "should have working Monoid" do
|
39
36
|
m = @monoid.random # choose an instance
|
40
37
|
|
41
38
|
# #== method
|
@@ -53,7 +50,7 @@ class AbstractAlgebraTest < Test::Unit::TestCase
|
|
53
50
|
assert @monoid.zero + m == m
|
54
51
|
end
|
55
52
|
|
56
|
-
should
|
53
|
+
it "should have working Group" do
|
57
54
|
g = @group.random
|
58
55
|
|
59
56
|
# (monoid properties not tested)
|
@@ -63,7 +60,7 @@ class AbstractAlgebraTest < Test::Unit::TestCase
|
|
63
60
|
assert (-g) + g == @group.zero
|
64
61
|
end
|
65
62
|
|
66
|
-
should
|
63
|
+
it "should define AbelianGroup" do
|
67
64
|
ag = @abelian_group.random
|
68
65
|
|
69
66
|
# (group properties not tested)
|
@@ -73,7 +70,7 @@ class AbstractAlgebraTest < Test::Unit::TestCase
|
|
73
70
|
assert ag + bh == bh + ag
|
74
71
|
end
|
75
72
|
|
76
|
-
should
|
73
|
+
it "should define Ring" do
|
77
74
|
r = @ring.random
|
78
75
|
|
79
76
|
# (abelian group properties with respect to addition not tested)
|
@@ -93,7 +90,7 @@ class AbstractAlgebraTest < Test::Unit::TestCase
|
|
93
90
|
assert r * ( s + t ) == ( r * s ) + ( s * t )
|
94
91
|
end
|
95
92
|
|
96
|
-
should
|
93
|
+
it "should define Field" do
|
97
94
|
f = @field.random
|
98
95
|
|
99
96
|
# (ring properties not tested)
|
@@ -105,43 +102,35 @@ class AbstractAlgebraTest < Test::Unit::TestCase
|
|
105
102
|
end
|
106
103
|
end
|
107
104
|
|
108
|
-
|
109
|
-
|
110
|
-
require 'y_support/abstract_algebra'
|
111
|
-
end
|
112
|
-
|
113
|
-
should "have patched Integer" do
|
105
|
+
describe "numerics" do
|
106
|
+
it "should have patched Integer" do
|
114
107
|
assert Integer.zero.equal? 0
|
115
108
|
end
|
116
109
|
|
117
|
-
should
|
110
|
+
it "should have patched Float" do
|
118
111
|
assert Float.zero.equal? 0.0
|
119
112
|
end
|
120
113
|
|
121
|
-
should
|
114
|
+
it "should have patched Rational" do
|
122
115
|
assert Rational.zero.equal? Rational( 0, 0 )
|
123
116
|
end
|
124
117
|
|
125
|
-
should
|
118
|
+
it "should have patched Complex" do
|
126
119
|
assert Complex.zero.equal? Complex( 0, 0 )
|
127
120
|
end
|
128
121
|
end
|
129
122
|
|
130
|
-
|
131
|
-
|
132
|
-
require 'y_support/abstract_algebra'
|
133
|
-
end
|
134
|
-
|
135
|
-
should "have Matrix.wildcard_zero public instance method" do
|
123
|
+
describe "Matrix" do
|
124
|
+
it "should have Matrix.wildcard_zero public instance method" do
|
136
125
|
# FIXME
|
137
126
|
end
|
138
127
|
|
139
|
-
should
|
128
|
+
it "should be able to perform #* with nonnumerics in the matrix" do
|
140
129
|
# FIXME
|
141
130
|
end
|
142
131
|
|
143
|
-
should
|
132
|
+
it "should numeric matrix multiplication still be working normally" do
|
144
133
|
# FIXME
|
145
134
|
end
|
146
135
|
end # context Matrix
|
147
|
-
end
|
136
|
+
end
|
data/test/inert_recorder_test.rb
CHANGED
@@ -1,26 +1,21 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
|
-
#encoding: utf-8
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'shoulda'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
describe "InertRecorder" do
|
7
|
+
before do
|
8
|
+
require './../lib/y_support/inert_recorder'
|
9
|
+
end
|
12
10
|
|
13
|
-
|
11
|
+
describe "Object" do
|
12
|
+
it "should have #InertRecorder() constructor" do
|
14
13
|
assert_equal InertRecorder, InertRecorder( :bull ).class
|
15
14
|
end
|
16
|
-
end
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
require 'y_support/inert_recorder'
|
21
|
-
end
|
22
|
-
|
23
|
-
should "InertRecorder exist and comply" do
|
17
|
+
describe "InertRecorder" do
|
18
|
+
it "should InertRecorder exist and comply" do
|
24
19
|
n = InertRecorder.new
|
25
20
|
assert_equal [true, false], [n.present?, n.blank?]
|
26
21
|
assert_respond_to InertRecorder.new, :arbitrary_message
|
@@ -30,5 +25,5 @@ class YSupportTest < Test::Unit::TestCase
|
|
30
25
|
assert_equal [ :arbitrary_message, [:a, :b] ], n.recorded_messages[0][0..1]
|
31
26
|
assert_equal "hello", n.recorded_messages[0][2].call
|
32
27
|
end
|
33
|
-
end
|
34
|
-
end
|
28
|
+
end
|
29
|
+
end
|
data/test/local_object_test.rb
CHANGED
@@ -1,37 +1,32 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'shoulda'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
describe "LocalObject" do
|
7
|
+
before do
|
8
|
+
require './../lib/y_support/local_object'
|
9
|
+
end
|
12
10
|
|
13
|
-
|
11
|
+
describe "Object" do
|
12
|
+
it "should have constructor #LocalObject, alias #L!" do
|
14
13
|
assert_equal LocalObject, LocalObject().class
|
15
14
|
assert_equal LocalObject, L!.class
|
16
15
|
end
|
17
16
|
|
18
|
-
should
|
17
|
+
it "should have #local_object?, alias #ℓ?" do
|
19
18
|
assert_equal false, Object.new.local_object?
|
20
19
|
assert_equal false, Object.new.ℓ?
|
21
20
|
end
|
22
|
-
end
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
require 'y_support/local_object'
|
27
|
-
end
|
28
|
-
|
29
|
-
should "exist and comply" do
|
23
|
+
describe "LocalObject" do
|
24
|
+
it "should exist and comply" do
|
30
25
|
n = LocalObject.new 'whatever'
|
31
26
|
assert ! n.ℓ?
|
32
27
|
assert n.ℓ? 'whatever'
|
33
28
|
assert_equal 'whatever', n.signature
|
34
29
|
assert_equal 'whatever', n.σ
|
35
30
|
end
|
36
|
-
end
|
37
|
-
end
|
31
|
+
end
|
32
|
+
end
|
data/test/misc_test.rb
CHANGED
@@ -5,7 +5,7 @@ require 'minitest/autorun'
|
|
5
5
|
|
6
6
|
describe Object do
|
7
7
|
before do
|
8
|
-
require 'y_support/core_ext/object'
|
8
|
+
require './../lib/y_support/core_ext/object'
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have #param_class" do
|
@@ -20,7 +20,7 @@ end
|
|
20
20
|
|
21
21
|
describe Module do
|
22
22
|
before do
|
23
|
-
require 'y_support/core_ext/module'
|
23
|
+
require './../lib/y_support/core_ext/module'
|
24
24
|
end
|
25
25
|
|
26
26
|
it "has #const_set_if_not_defined and #const_reset!" do
|
@@ -29,13 +29,18 @@ describe Module do
|
|
29
29
|
m::Foo.must_equal 42
|
30
30
|
m.const_reset! :Foo, 43
|
31
31
|
m::Foo.must_equal 43
|
32
|
+
m.module_exec do
|
33
|
+
def a; 42 end
|
34
|
+
chain b: :a, &:to_s
|
35
|
+
end
|
36
|
+
Class.new do include m end.new.b.must_equal "42"
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
35
40
|
|
36
41
|
describe Class do
|
37
42
|
before do
|
38
|
-
require 'y_support/core_ext/class'
|
43
|
+
require './../lib/y_support/core_ext/class'
|
39
44
|
end
|
40
45
|
|
41
46
|
it "has #parametrize method" do
|
@@ -49,7 +54,7 @@ end
|
|
49
54
|
|
50
55
|
describe Enumerable do
|
51
56
|
before do
|
52
|
-
require 'y_support/core_ext/enumerable'
|
57
|
+
require './../lib/y_support/core_ext/enumerable'
|
53
58
|
end
|
54
59
|
|
55
60
|
it "should introduce #all_kind_of? collection qualifier" do
|
@@ -73,7 +78,7 @@ end
|
|
73
78
|
|
74
79
|
describe Array do
|
75
80
|
before do
|
76
|
-
require 'y_support/core_ext/array'
|
81
|
+
require './../lib/y_support/core_ext/array'
|
77
82
|
end
|
78
83
|
|
79
84
|
it "has #arrays_to_hash" do
|
@@ -135,7 +140,7 @@ end
|
|
135
140
|
|
136
141
|
describe Hash do
|
137
142
|
before do
|
138
|
-
require 'y_support/core_ext/hash'
|
143
|
+
require './../lib/y_support/core_ext/hash'
|
139
144
|
end
|
140
145
|
|
141
146
|
it "should have #default! custom defaulter" do
|
@@ -206,7 +211,7 @@ end
|
|
206
211
|
describe "Matrix" do
|
207
212
|
before do
|
208
213
|
require 'matrix'
|
209
|
-
require 'y_support/stdlib_ext/matrix'
|
214
|
+
require './../lib/y_support/stdlib_ext/matrix'
|
210
215
|
end
|
211
216
|
|
212
217
|
it "should have #pp method" do
|
@@ -256,7 +261,7 @@ end
|
|
256
261
|
|
257
262
|
describe String do
|
258
263
|
before do
|
259
|
-
require 'y_support/core_ext/string'
|
264
|
+
require './../lib/y_support/core_ext/string'
|
260
265
|
end
|
261
266
|
|
262
267
|
it "should have #can_be_integer? returning the integer or false if not convertible" do
|
@@ -312,7 +317,7 @@ end
|
|
312
317
|
|
313
318
|
describe Symbol do
|
314
319
|
before do
|
315
|
-
require 'y_support/core_ext/symbol'
|
320
|
+
require './../lib/y_support/core_ext/symbol'
|
316
321
|
end
|
317
322
|
|
318
323
|
it "should have #default! defaulter going through String#default!" do
|
@@ -331,7 +336,7 @@ end
|
|
331
336
|
|
332
337
|
describe Numeric do
|
333
338
|
before do
|
334
|
-
require 'y_support/core_ext/numeric'
|
339
|
+
require './../lib/y_support/core_ext/numeric'
|
335
340
|
end
|
336
341
|
|
337
342
|
it "should have #zero public class methods" do
|
data/test/name_magic_test.rb
CHANGED
data/test/null_object_test.rb
CHANGED
@@ -1,45 +1,38 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'shoulda'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
describe "y_support/null_object" do
|
7
|
+
before do
|
8
|
+
require './../lib/y_support/null_object'
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
assert_equal [false, false], [nil.null_object?, nil.null?]
|
18
|
-
|
19
|
-
|
11
|
+
describe Object do
|
12
|
+
it "should have #null_object? (alias #null?)" do
|
13
|
+
assert ( class Koko < NullObject; self end ).new.null_object?
|
14
|
+
assert ( class Koko < NullObject; self end ).new.null?
|
15
|
+
assert_equal [ false, false ], [ nil.null_object?, nil.null? ]
|
16
|
+
assert NullObject.new( :koko ).null?( :koko )
|
17
|
+
assert ! NullObject.new( :koko ).null?( :pipi )
|
20
18
|
end
|
21
19
|
|
22
|
-
|
20
|
+
it "should have #Maybe() constructor for something / NullObject" do
|
23
21
|
assert_equal NullObject, Maybe(nil).class
|
24
22
|
assert_equal 42, Maybe(42)
|
25
23
|
end
|
26
24
|
|
27
|
-
|
25
|
+
it "should have #Null() constructor always returning NullObject" do
|
28
26
|
assert_equal NullObject, Null().class
|
29
27
|
end
|
30
28
|
end # context Object
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
require 'y_support/null_object'
|
35
|
-
end
|
36
|
-
|
37
|
-
should "NullObject exist and comply" do
|
30
|
+
describe "NullObject" do
|
31
|
+
it "should NullObject exist and comply" do
|
38
32
|
n = NullObject.new
|
39
|
-
|
33
|
+
[n.to_a, n.to_s, n.to_f, n.to_i].must_equal [ [], "#<NullObject>", 0.0, 0 ]
|
40
34
|
assert_equal [false, true], [n.present?, n.empty?]
|
41
|
-
|
42
|
-
must_have_attr_reader( :recorded_messages ) }
|
35
|
+
NullObject.new.must_have_attr_reader( :recorded_messages )
|
43
36
|
assert_respond_to NullObject.new, :arbitrary_message
|
44
37
|
n = NullObject.new :x
|
45
38
|
n.arbitrary_message( :a, :b ) { "hello" }
|
@@ -47,4 +40,4 @@ class NullObjectTest < Test::Unit::TestCase
|
|
47
40
|
assert_equal "#<NullObject kokotina>", NullObject.new( :kokotina ).inspect
|
48
41
|
end
|
49
42
|
end # context NullObject
|
50
|
-
end
|
43
|
+
end
|
data/test/respond_to_test.rb
CHANGED
@@ -1,22 +1,21 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'shoulda'
|
4
|
+
require 'minitest/autorun'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
describe "y_support/typing" do
|
7
|
+
before do
|
8
|
+
require './../lib/y_support/respond_to'
|
9
|
+
end
|
12
10
|
|
13
|
-
|
11
|
+
describe Object do
|
12
|
+
it "should have RespondTo() constructor" do
|
14
13
|
assert_equal RespondTo, RespondTo( :inspect ).class
|
15
14
|
end
|
16
|
-
end
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
should
|
17
|
+
describe "RespondTo" do
|
18
|
+
it "should work" do
|
20
19
|
assert_respond_to( RespondTo.new(:hello), :=== )
|
21
20
|
assert RespondTo.new(:each_char) === "arbitrary string"
|
22
21
|
assert ! ( RespondTo.new(:each_char) === Object.new )
|
@@ -29,10 +28,10 @@ class RespondToTest < Test::Unit::TestCase
|
|
29
28
|
when RespondTo.new(:improbab_method_name) then 1
|
30
29
|
else false end
|
31
30
|
end
|
32
|
-
end
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
should
|
33
|
+
describe Symbol do
|
34
|
+
it "should have Symbol#~@ for .respond_to? case statements" do
|
36
35
|
assert_kind_of RespondTo, ~:hello
|
37
36
|
assert RespondTo(:<<) === "testing"
|
38
37
|
assert case ?x
|
@@ -42,5 +41,5 @@ class RespondToTest < Test::Unit::TestCase
|
|
42
41
|
when ~:improbab_method_name then 1
|
43
42
|
else false end
|
44
43
|
end
|
45
|
-
end
|
46
|
-
end
|
44
|
+
end
|
45
|
+
end
|