sundbp-extlib 0.9.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +21 -0
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +47 -0
- data/README.rdoc +17 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/extlib.gemspec +146 -0
- data/lib/extlib.rb +50 -0
- data/lib/extlib/array.rb +36 -0
- data/lib/extlib/assertions.rb +8 -0
- data/lib/extlib/blank.rb +89 -0
- data/lib/extlib/boolean.rb +11 -0
- data/lib/extlib/byte_array.rb +6 -0
- data/lib/extlib/class.rb +177 -0
- data/lib/extlib/datetime.rb +29 -0
- data/lib/extlib/dictionary.rb +433 -0
- data/lib/extlib/hash.rb +442 -0
- data/lib/extlib/hook.rb +403 -0
- data/lib/extlib/inflection.rb +440 -0
- data/lib/extlib/lazy_array.rb +451 -0
- data/lib/extlib/lazy_module.rb +18 -0
- data/lib/extlib/logger.rb +198 -0
- data/lib/extlib/mash.rb +155 -0
- data/lib/extlib/module.rb +47 -0
- data/lib/extlib/nil.rb +5 -0
- data/lib/extlib/numeric.rb +5 -0
- data/lib/extlib/object.rb +175 -0
- data/lib/extlib/object_space.rb +13 -0
- data/lib/extlib/pathname.rb +20 -0
- data/lib/extlib/pooling.rb +235 -0
- data/lib/extlib/rubygems.rb +38 -0
- data/lib/extlib/simple_set.rb +66 -0
- data/lib/extlib/string.rb +176 -0
- data/lib/extlib/struct.rb +17 -0
- data/lib/extlib/symbol.rb +21 -0
- data/lib/extlib/time.rb +43 -0
- data/lib/extlib/virtual_file.rb +10 -0
- data/spec/array_spec.rb +39 -0
- data/spec/blank_spec.rb +85 -0
- data/spec/byte_array_spec.rb +7 -0
- data/spec/class_spec.rb +157 -0
- data/spec/datetime_spec.rb +22 -0
- data/spec/hash_spec.rb +537 -0
- data/spec/hook_spec.rb +1234 -0
- data/spec/inflection/plural_spec.rb +564 -0
- data/spec/inflection/singular_spec.rb +497 -0
- data/spec/inflection_extras_spec.rb +110 -0
- data/spec/lazy_array_spec.rb +1957 -0
- data/spec/lazy_module_spec.rb +38 -0
- data/spec/mash_spec.rb +311 -0
- data/spec/module_spec.rb +70 -0
- data/spec/object_space_spec.rb +9 -0
- data/spec/object_spec.rb +114 -0
- data/spec/pooling_spec.rb +511 -0
- data/spec/rcov.opts +6 -0
- data/spec/simple_set_spec.rb +57 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/string_spec.rb +221 -0
- data/spec/struct_spec.rb +12 -0
- data/spec/symbol_spec.rb +8 -0
- data/spec/time_spec.rb +29 -0
- data/spec/try_call_spec.rb +73 -0
- data/spec/try_dup_spec.rb +45 -0
- data/spec/virtual_file_spec.rb +21 -0
- data/tasks/ci.rake +1 -0
- data/tasks/metrics.rake +36 -0
- data/tasks/spec.rake +25 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +180 -0
data/spec/rcov.opts
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
describe Extlib::SimpleSet do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@s = Extlib::SimpleSet.new("Initial")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#initialize" do
|
10
|
+
it 'adds passed value to the set' do
|
11
|
+
@new_generation_vms = Extlib::SimpleSet.new(["Rubinius", "PyPy", "Parrot"])
|
12
|
+
|
13
|
+
@new_generation_vms.should have_key("Rubinius")
|
14
|
+
@new_generation_vms.should have_key("PyPy")
|
15
|
+
@new_generation_vms.should have_key("Parrot")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#<<" do
|
20
|
+
it "adds value to the set" do
|
21
|
+
@s << "Hello"
|
22
|
+
@s.to_a.should be_include("Hello")
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'sets true mark on the key' do
|
26
|
+
@s << "Fun"
|
27
|
+
@s["Fun"].should be_true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#merge(other)" do
|
32
|
+
it "preserves old values when values do not overlap" do
|
33
|
+
@s.should have_key("Initial")
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'adds new values from merged set' do
|
37
|
+
@t = @s.merge(["Merged value"])
|
38
|
+
@t.should have_key("Merged value")
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns a SimpleSet instance' do
|
42
|
+
@s.merge(["Merged value"]).should be_kind_of(Extlib::SimpleSet)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#inspect" do
|
47
|
+
it "lists set values" do
|
48
|
+
@s.inspect.should == "#<SimpleSet: {\"Initial\"}>"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#keys" do
|
53
|
+
it 'is aliased as to_a' do
|
54
|
+
@s.to_a.should === @s.keys
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
describe String, "#to_const_string" do
|
4
|
+
it "swaps slashes with ::" do
|
5
|
+
"foo/bar".to_const_string.should == "Foo::Bar"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "replaces snake_case with CamelCase" do
|
9
|
+
"foo/bar/baz_bat".to_const_string.should == "Foo::Bar::BazBat"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "leaves constant string as is" do
|
13
|
+
"Merb::Test".to_const_string.should == "Merb::Test"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
describe String, "#to_const_path" do
|
20
|
+
it "swaps :: with slash" do
|
21
|
+
"Foo::Bar".to_const_path.should == "foo/bar"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "snake_cases string" do
|
25
|
+
"Merb::Test::ViewHelper".to_const_path.should == "merb/test/view_helper"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "leaves slash-separated snake case string as is" do
|
29
|
+
"merb/test/view_helper".to_const_path.should == "merb/test/view_helper"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
describe String, "#camel_case" do
|
36
|
+
it "handles lowercase without underscore" do
|
37
|
+
"merb".camel_case.should == "Merb"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "handles lowercase with 1 underscore" do
|
41
|
+
"merb_core".camel_case.should == "MerbCore"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "handles lowercase with more than 1 underscore" do
|
45
|
+
"so_you_want_contribute_to_merb_core".camel_case.should == "SoYouWantContributeToMerbCore"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "handles lowercase with more than 1 underscore in a row" do
|
49
|
+
"__python__is__like__this".camel_case.should == "PythonIsLikeThis"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "handle first capital letter with underscores" do
|
53
|
+
"Python__Is__Like__This".camel_case.should == "PythonIsLikeThis"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "leaves CamelCase as is" do
|
57
|
+
"TestController".camel_case.should == "TestController"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
describe String, "#snake_case" do
|
64
|
+
it "lowercases one word CamelCase" do
|
65
|
+
"Merb".snake_case.should == "merb"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "makes one underscore snake_case two word CamelCase" do
|
69
|
+
"MerbCore".snake_case.should == "merb_core"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "handles CamelCase with more than 2 words" do
|
73
|
+
"SoYouWantContributeToMerbCore".snake_case.should == "so_you_want_contribute_to_merb_core"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "handles CamelCase with more than 2 capital letter in a row" do
|
77
|
+
"CNN".snake_case.should == "cnn"
|
78
|
+
"CNNNews".snake_case.should == "cnn_news"
|
79
|
+
"HeadlineCNNNews".snake_case.should == "headline_cnn_news"
|
80
|
+
"NameACRONYM".snake_case.should == "name_acronym"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "does NOT change one word lowercase" do
|
84
|
+
"merb".snake_case.should == "merb"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "leaves snake_case as is" do
|
88
|
+
"merb_core".snake_case.should == "merb_core"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
describe String, "#escape_regexp" do
|
95
|
+
it "escapes all * in a string" do
|
96
|
+
"*and*".escape_regexp.should == "\\*and\\*"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "escapes all ? in a string" do
|
100
|
+
"?and?".escape_regexp.should == "\\?and\\?"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "escapes all { in a string" do
|
104
|
+
"{and{".escape_regexp.should == "\\{and\\{"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "escapes all } in a string" do
|
108
|
+
"}and}".escape_regexp.should == "\\}and\\}"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "escapes all . in a string" do
|
112
|
+
".and.".escape_regexp.should == "\\.and\\."
|
113
|
+
end
|
114
|
+
|
115
|
+
it "escapes all regexp special characters used in a string" do
|
116
|
+
"*?{}.".escape_regexp.should == "\\*\\?\\{\\}\\."
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
describe String, "#unescape_regexp" do
|
123
|
+
it "unescapes all \\* in a string" do
|
124
|
+
"\\*and\\*".unescape_regexp.should == "*and*"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "unescapes all \\? in a string" do
|
128
|
+
"\\?and\\?".unescape_regexp.should == "?and?"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "unescapes all \\{ in a string" do
|
132
|
+
"\\{and\\{".unescape_regexp.should == "{and{"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "unescapes all \\} in a string" do
|
136
|
+
"\\}and\\}".unescape_regexp.should == "}and}"
|
137
|
+
end
|
138
|
+
|
139
|
+
it "unescapes all \\. in a string" do
|
140
|
+
"\\.and\\.".unescape_regexp.should == ".and."
|
141
|
+
end
|
142
|
+
|
143
|
+
it "unescapes all regexp special characters used in a string" do
|
144
|
+
"\\*\\?\\{\\}\\.".unescape_regexp.should == "*?{}."
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
describe String, "#/" do
|
151
|
+
it "concanates operands with File::SEPARATOR" do
|
152
|
+
("merb" / "core").should == "merb#{File::SEPARATOR}core"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
require 'rbconfig'
|
158
|
+
describe String, "#relative_path_from" do
|
159
|
+
it "uses other operand as base for path calculation" do
|
160
|
+
site_dir = Config::CONFIG["sitedir"]
|
161
|
+
|
162
|
+
two_levels_up = site_dir.split(File::SEPARATOR)
|
163
|
+
2.times { two_levels_up.pop } # remove two deepest directories
|
164
|
+
two_levels_up = two_levels_up.join(File::SEPARATOR)
|
165
|
+
|
166
|
+
two_levels_up.relative_path_from(site_dir).should == "../.."
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
describe String, ".translate" do
|
172
|
+
before(:each) do
|
173
|
+
String.stub!(:translations).and_return({ "on snakes and rubies" => "a serpenti e rubini" })
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'looks up for translation in translations dictionary' do
|
177
|
+
String.translate("on snakes and rubies").should == "a serpenti e rubini"
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'returns string that has no translations as it is' do
|
181
|
+
String.translate("shapes").should == "shapes"
|
182
|
+
String.translate("kalopsia").should == "kalopsia"
|
183
|
+
String.translate("holding on to nothing").should == "holding on to nothing"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe String, ".t" do
|
188
|
+
before(:each) do
|
189
|
+
String.stub!(:translations).and_return({ '%s must not be blank' => "%s moet ingevuld worden",
|
190
|
+
'username' => 'gebruikersnaam',
|
191
|
+
'%s must be between %s and %s characters long' => '%s moet tussen %s en %s tekens lang zijn'})
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'looks up for translation in translations dictionary and translates parameters as well' do
|
195
|
+
"%s must not be blank".t(:username).should == "gebruikersnaam moet ingevuld worden"
|
196
|
+
"%s must not be blank".t('username').should == "gebruikersnaam moet ingevuld worden"
|
197
|
+
"%s must be between %s and %s characters long".t(:password, 5, 9).should == "password moet tussen 5 en 9 tekens lang zijn"
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'returns string that has no translations as it is' do
|
201
|
+
"password".t.should == "password"
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should not translate when freezed' do
|
205
|
+
"%s must not be blank".t('username'.freeze).should == "username moet ingevuld worden"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe String, ".translations" do
|
210
|
+
before(:each) do
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'returns empty hash by default' do
|
215
|
+
String.translations.should == {}
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'returns @translations if set' do
|
219
|
+
pending "is it @translations on metaclass or @@translations? leaving it out for now"
|
220
|
+
end
|
221
|
+
end
|
data/spec/struct_spec.rb
ADDED
data/spec/symbol_spec.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
describe Symbol, "#/" do
|
4
|
+
it "concanates operands with File::SEPARATOR" do
|
5
|
+
(:merb / "core").should == "merb#{File::SEPARATOR}core"
|
6
|
+
(:merb / :core).should == "merb#{File::SEPARATOR}core"
|
7
|
+
end
|
8
|
+
end
|
data/spec/time_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe Time, "#to_json" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@expected = "\"2008-03-28T22:54:20Z\""
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should transform itself into a ISO 8601 compatible string" do
|
11
|
+
Time.utc(2008, 3, 28, 22, 54, 20).to_json.should == @expected
|
12
|
+
Time.xmlschema("2008-03-28T22:54:20Z").to_json.should == @expected
|
13
|
+
Time.xmlschema("2008-03-28T17:54:20-05:00").to_json.should == @expected
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Time, "#to_time" do
|
18
|
+
it "should return a copy of its self" do
|
19
|
+
time = Time.now
|
20
|
+
time.to_time.should == time
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Time, "#to_datetime" do
|
25
|
+
it "should return an equivalent DateTime" do
|
26
|
+
time = Time.now
|
27
|
+
time.to_datetime.should == DateTime.parse(time.to_s)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
describe "#try_call" do
|
4
|
+
describe "with an Object" do
|
5
|
+
before :all do
|
6
|
+
@receiver = Object.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns receiver itself" do
|
10
|
+
@receiver.try_call.should == @receiver
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "with a number" do
|
15
|
+
before :all do
|
16
|
+
@receiver = 42
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns receiver itself" do
|
20
|
+
@receiver.try_call.should == @receiver
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "with a String" do
|
25
|
+
before :all do
|
26
|
+
@receiver = "Ruby, programmer's best friend"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns receiver itself" do
|
30
|
+
@receiver.try_call.should == @receiver
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with a hash" do
|
35
|
+
before :all do
|
36
|
+
@receiver = { :functional_programming => "FTW" }
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns receiver itself" do
|
40
|
+
@receiver.try_call.should == @receiver
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "with a Proc" do
|
45
|
+
before :all do
|
46
|
+
@receiver = Proc.new { 5 * 7 }
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns result of calling of a proc" do
|
50
|
+
@receiver.try_call.should == 35
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "with a Proc that takes 2 arguments" do
|
55
|
+
before :all do
|
56
|
+
@receiver = Proc.new { |one, other| one + other }
|
57
|
+
end
|
58
|
+
|
59
|
+
it "passes arguments to #call, returns result of calling of a proc" do
|
60
|
+
@receiver.try_call(10, 20).should == 30
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "with a Proc that takes 3 arguments" do
|
65
|
+
before :all do
|
66
|
+
@receiver = Proc.new { |a, b, c| (a + b) * c }
|
67
|
+
end
|
68
|
+
|
69
|
+
it "passes arguments to #call, returns result of calling of a proc" do
|
70
|
+
@receiver.try_call(10, 20, 3).should == 90
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
describe "try_dup" do
|
4
|
+
it "returns a duplicate version on regular objects" do
|
5
|
+
obj = Object.new
|
6
|
+
oth = obj.try_dup
|
7
|
+
obj.should_not === oth
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns self on Numerics" do
|
11
|
+
obj = 12
|
12
|
+
oth = obj.try_dup
|
13
|
+
obj.should === oth
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns self on Symbols" do
|
17
|
+
obj = :test
|
18
|
+
oth = obj.try_dup
|
19
|
+
obj.should === oth
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns self on true" do
|
23
|
+
obj = true
|
24
|
+
oth = obj.try_dup
|
25
|
+
obj.should === oth
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns self on false" do
|
29
|
+
obj = false
|
30
|
+
oth = obj.try_dup
|
31
|
+
obj.should === oth
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns self on nil" do
|
35
|
+
obj = nil
|
36
|
+
oth = obj.try_dup
|
37
|
+
obj.should === oth
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns self on modules" do
|
41
|
+
obj = Extlib
|
42
|
+
oth = obj.try_dup
|
43
|
+
obj.object_id.should == oth.object_id
|
44
|
+
end
|
45
|
+
end
|