hash-utils 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -5
- data/CHANGES.txt +13 -3
- data/Gemfile.lock +13 -13
- data/README.md +5 -4
- data/Rakefile +1 -2
- data/TODO.txt +0 -1
- data/VERSION +1 -1
- data/hash-utils.gemspec +17 -4
- data/lib/hash-utils/array.rb +276 -2
- data/lib/hash-utils/hash.rb +43 -9
- data/lib/hash-utils/object.rb +6 -2
- data/lib/hash-utils/string.rb +32 -11
- data/lib/hash-utils/symbol.rb +15 -0
- data/spec/modules/array_spec.rb +177 -0
- data/spec/modules/false_spec.rb +23 -0
- data/spec/modules/file_spec.rb +22 -0
- data/spec/modules/hash_spec.rb +223 -0
- data/spec/modules/io_spec.rb +17 -0
- data/spec/modules/module_spec.rb +12 -0
- data/spec/modules/nil_spec.rb +11 -0
- data/spec/modules/numeric_spec.rb +32 -0
- data/spec/modules/object_spec.rb +78 -0
- data/spec/modules/string_spec.rb +245 -0
- data/spec/modules/stringio_spec.rb +11 -0
- data/spec/modules/symbol_spec.rb +40 -0
- data/spec/modules/true_spec.rb +23 -0
- data/spec/spec_helper.rb +15 -0
- metadata +18 -5
- data/tests.rb +0 -556
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# (c) 2011-2012 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
+
|
5
|
+
require "spec_helper"
|
6
|
+
|
7
|
+
describe "TrueClass" do
|
8
|
+
specify("#boolean?") do
|
9
|
+
true.boolean?.should be_true
|
10
|
+
end
|
11
|
+
specify("#convert") do
|
12
|
+
true.convert(:a, :b).should eq(:a)
|
13
|
+
end
|
14
|
+
specify("#false?") do
|
15
|
+
true.false?.should be_false
|
16
|
+
end
|
17
|
+
specify("#to_i") do
|
18
|
+
true.to_i.should eq(1)
|
19
|
+
end
|
20
|
+
specify("#true?") do
|
21
|
+
true.true?.should be_true
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# (c) 2011-2012 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
+
|
5
|
+
$:.push("./lib")
|
6
|
+
$:.unshift("./lib")
|
7
|
+
|
8
|
+
require "rspec"
|
9
|
+
require "stringio"
|
10
|
+
|
11
|
+
require "simplecov"
|
12
|
+
SimpleCov.start
|
13
|
+
|
14
|
+
require "hash-utils"
|
15
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-version
|
@@ -141,7 +141,20 @@ files:
|
|
141
141
|
- lib/hash-utils/string.rb
|
142
142
|
- lib/hash-utils/stringio.rb
|
143
143
|
- lib/hash-utils/symbol.rb
|
144
|
-
-
|
144
|
+
- spec/modules/array_spec.rb
|
145
|
+
- spec/modules/false_spec.rb
|
146
|
+
- spec/modules/file_spec.rb
|
147
|
+
- spec/modules/hash_spec.rb
|
148
|
+
- spec/modules/io_spec.rb
|
149
|
+
- spec/modules/module_spec.rb
|
150
|
+
- spec/modules/nil_spec.rb
|
151
|
+
- spec/modules/numeric_spec.rb
|
152
|
+
- spec/modules/object_spec.rb
|
153
|
+
- spec/modules/string_spec.rb
|
154
|
+
- spec/modules/stringio_spec.rb
|
155
|
+
- spec/modules/symbol_spec.rb
|
156
|
+
- spec/modules/true_spec.rb
|
157
|
+
- spec/spec_helper.rb
|
145
158
|
homepage: http://github.com/martinkozak/hash-utils
|
146
159
|
licenses:
|
147
160
|
- MIT
|
@@ -157,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
170
|
version: '0'
|
158
171
|
segments:
|
159
172
|
- 0
|
160
|
-
hash:
|
173
|
+
hash: 647094284992017234
|
161
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
175
|
none: false
|
163
176
|
requirements:
|
@@ -169,7 +182,7 @@ rubyforge_project:
|
|
169
182
|
rubygems_version: 1.8.24
|
170
183
|
signing_key:
|
171
184
|
specification_version: 3
|
172
|
-
summary: Adds more than
|
185
|
+
summary: Adds more than 155 useful and frequently rather fundamental methods which
|
173
186
|
are missing in Ruby programming language, to Array, File, Hash, Module, Object,
|
174
187
|
String and Symbol classes. It tries to be similar project to Ruby Facets on principle,
|
175
188
|
but less complex, more practical, non-atomic and organized by better way. Thanks
|
data/tests.rb
DELETED
@@ -1,556 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
# (c) 2011-2012 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
-
|
5
|
-
$:.push("./lib")
|
6
|
-
$:.unshift("./lib")
|
7
|
-
|
8
|
-
require "rspec"
|
9
|
-
require "stringio"
|
10
|
-
|
11
|
-
require "simplecov"
|
12
|
-
SimpleCov.start
|
13
|
-
|
14
|
-
require "hash-utils"
|
15
|
-
|
16
|
-
|
17
|
-
## ARRAY
|
18
|
-
|
19
|
-
# Filozofové mají Kanta rádi. Matematici mají Kanta také rádi, jen si
|
20
|
-
# myslí, že většina z toho, co vymyslel, je blbost.
|
21
|
-
#
|
22
|
-
# doc. Jiří Souček
|
23
|
-
|
24
|
-
describe "Array" do
|
25
|
-
specify("#second") do
|
26
|
-
[1, 2, 3, 4, 5, 6, 7, 8].second == 2
|
27
|
-
end
|
28
|
-
specify("#third") do
|
29
|
-
[1, 2, 3, 4, 5, 6, 7, 8].third == 3
|
30
|
-
end
|
31
|
-
specify("#fourth") do
|
32
|
-
[1, 2, 3, 4, 5, 6, 7, 8].fourth == 4
|
33
|
-
end
|
34
|
-
specify("#fifth") do
|
35
|
-
[1, 2, 3, 4, 5, 6, 7, 8].fifth == 5
|
36
|
-
end
|
37
|
-
specify("#sixth") do
|
38
|
-
[1, 2, 3, 4, 5, 6, 7, 8].sixth == 6
|
39
|
-
end
|
40
|
-
specify("#seventh") do
|
41
|
-
[1, 2, 3, 4, 5, 6, 7, 8].seventh == 7
|
42
|
-
end
|
43
|
-
specify("#eighth") do
|
44
|
-
[1, 2, 3, 4, 5, 6, 7, 8].eighth == 8
|
45
|
-
end
|
46
|
-
specify("#array?") do
|
47
|
-
[1, 2, 3].array?
|
48
|
-
end
|
49
|
-
specify("#avg") do
|
50
|
-
[1, 2, 3].avg == 2
|
51
|
-
end
|
52
|
-
specify("#clean") do
|
53
|
-
t = [1, nil]
|
54
|
-
t = t.clean(1)
|
55
|
-
t == [nil]
|
56
|
-
end
|
57
|
-
specify("#clean!") do
|
58
|
-
t = [1, nil]
|
59
|
-
t.clean!(1)
|
60
|
-
t == [nil]
|
61
|
-
end
|
62
|
-
specify("#sum") do
|
63
|
-
[1, 2, 3].sum == 6
|
64
|
-
end
|
65
|
-
specify("#to_set") do
|
66
|
-
[1, 2, 3].to_set == Set::new([1, 2, 3])
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
## FALSECLASS
|
71
|
-
|
72
|
-
describe "FalseClass" do
|
73
|
-
specify("#boolean?") do
|
74
|
-
false.boolean?
|
75
|
-
end
|
76
|
-
specify("#convert") do
|
77
|
-
false.convert(:a, :b) == :b
|
78
|
-
end
|
79
|
-
specify("#false?") do
|
80
|
-
false.false?
|
81
|
-
end
|
82
|
-
specify("#to_i") do
|
83
|
-
false.to_i == 0
|
84
|
-
end
|
85
|
-
specify("#true?") do
|
86
|
-
not false.true?
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
## FILE
|
91
|
-
|
92
|
-
describe "File" do
|
93
|
-
specify("#touch") do
|
94
|
-
File.touch("./~test1")
|
95
|
-
File.exists? "./~test1"
|
96
|
-
end
|
97
|
-
specify("#write") do
|
98
|
-
File.write("./~test2", "some string")
|
99
|
-
File.read("./~test2") == "some string"
|
100
|
-
end
|
101
|
-
|
102
|
-
after(:all) do
|
103
|
-
File.unlink("./~test1")
|
104
|
-
File.unlink("./~test2")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
## HASH
|
109
|
-
|
110
|
-
describe "Hash" do
|
111
|
-
specify("#avg") do
|
112
|
-
{ :a => 1, :b => 2 }.avg == 1.5
|
113
|
-
end
|
114
|
-
specify("#clean") do
|
115
|
-
t = { :a => 1, :b => nil }
|
116
|
-
t = t.clean(1)
|
117
|
-
t == { :b => nil }
|
118
|
-
end
|
119
|
-
specify("#clean!") do
|
120
|
-
t = { :a => 1, :b => nil }
|
121
|
-
t.clean!(1)
|
122
|
-
t == { :b => nil }
|
123
|
-
end
|
124
|
-
specify("#compact") do
|
125
|
-
t = { :a => 1, :b => nil }
|
126
|
-
t = t.compact
|
127
|
-
t == { :a => 1 }
|
128
|
-
end
|
129
|
-
specify("#compact!") do
|
130
|
-
t = { :a => 1, :b => nil }
|
131
|
-
t.compact!
|
132
|
-
t == { :a => 1 }
|
133
|
-
end
|
134
|
-
specify("#flip") do
|
135
|
-
t = { :a => 1, :b => 2, :c => 2 }
|
136
|
-
result = t.flip
|
137
|
-
result == { 1 => :a, 2 => :c }
|
138
|
-
end
|
139
|
-
specify("#flip!") do
|
140
|
-
t = { :a => 1, :b => 2, :c => 2 }
|
141
|
-
t.flip!
|
142
|
-
t == { 1 => :a, 2 => :c }
|
143
|
-
end
|
144
|
-
specify("#get_pairs") do
|
145
|
-
h = { :a => 1, :b => 2, :c => 3 }
|
146
|
-
result = [ ]
|
147
|
-
h.get_pairs(:a, :c, :d) { |i| result << i }
|
148
|
-
result == [[:a, 1], [:c, 3]]
|
149
|
-
end
|
150
|
-
specify("#get_items") do
|
151
|
-
h = { :a => 1, :b => 2, :c => 3 }
|
152
|
-
h.get_items(:a, :c, :d) == { :a => 1, :c => 3 }
|
153
|
-
end
|
154
|
-
specify("#get_values") do
|
155
|
-
h = { :a => 1, :b => 2, :c => 3 }
|
156
|
-
h.get_values(:a, :c, :d) == [1, 3]
|
157
|
-
end
|
158
|
-
specify("#get_values") do
|
159
|
-
{ :a => 1, :b => 2, :c => 3 }.hash?
|
160
|
-
end
|
161
|
-
specify("#map_values") do
|
162
|
-
{ :a => 1, :b => 2 }.map_values { |i| i + 1 } == { :a => 2, :b => 3 }
|
163
|
-
end
|
164
|
-
specify("#map_values!") do
|
165
|
-
t = { :a => 1, :b => 2 }
|
166
|
-
t.map_values! { |i| i + 1 }
|
167
|
-
t == { :a => 2, :b => 3 }
|
168
|
-
end
|
169
|
-
specify("#deep_merge") do
|
170
|
-
h1 = {:a => {:b => :c, :d => :e}}
|
171
|
-
h2 = {:a => {:d => :f, :h => :i}}
|
172
|
-
h = h1.deep_merge(h2)
|
173
|
-
(h == {:a => {:b => :c, :d => :f, :h => :i}}) and (h1 == {:a => {:b => :c, :d => :e}})
|
174
|
-
end
|
175
|
-
specify("#deep_merge!") do
|
176
|
-
h = {:a => {:b => :c, :d => :e}}
|
177
|
-
h.deep_merge!({:a => {:d => :f, :h => :i}})
|
178
|
-
h == {:a => {:b => :c, :d => :f, :h => :i}}
|
179
|
-
end
|
180
|
-
specify("#keys_to_sym") do
|
181
|
-
h = {"a" => "b", 2 => "c", "d" => "e"}
|
182
|
-
h.keys_to_sym == {:a => "b", 2 => "c", :d => "e"}
|
183
|
-
end
|
184
|
-
specify("#keys_to_sym!") do
|
185
|
-
h = {"a" => "b", 2 => "c", "d" => "e"}
|
186
|
-
h.keys_to_sym!
|
187
|
-
h == {:a => "b", 2 => "c", :d => "e"}
|
188
|
-
end
|
189
|
-
specify("#sum") do
|
190
|
-
{ :a => 1, :b => 2 }.sum == 3
|
191
|
-
end
|
192
|
-
specify("#take_pairs") do
|
193
|
-
h = { :a => 1, :b => 2, :c => 3 }
|
194
|
-
result = [ ]
|
195
|
-
h.take_pairs(:a, :c, :d) { |i| result << i }
|
196
|
-
result == [[:a, 1], [:c, 3], [:d, nil]]
|
197
|
-
end
|
198
|
-
specify("#take_items") do
|
199
|
-
h = { :a => 1, :b => 2, :c => 3 }
|
200
|
-
h.take_items(:a, :c, :d) == { :a => 1, :c => 3, :d => nil }
|
201
|
-
end
|
202
|
-
specify("#take_values") do
|
203
|
-
h = { :a => 1, :b => 2, :c => 3 }
|
204
|
-
h.take_values(:a, :c, :d) == [1, 3, nil]
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
## IO
|
210
|
-
|
211
|
-
describe "IO" do
|
212
|
-
specify("#io?") do
|
213
|
-
io = File::open("./~test", "w")
|
214
|
-
result = io.io?
|
215
|
-
io.close()
|
216
|
-
result
|
217
|
-
end
|
218
|
-
after(:all) do
|
219
|
-
File.unlink("./~test")
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
## MODULE
|
224
|
-
|
225
|
-
describe "Module" do
|
226
|
-
specify("#get_module") do
|
227
|
-
require "zlib"
|
228
|
-
Kernel.get_module("Zlib::Inflate") == Zlib::Inflate
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
## NILCLASS
|
233
|
-
|
234
|
-
describe "NilClass" do
|
235
|
-
specify("#to_boolean") do
|
236
|
-
nil.to_boolean("xyz") === false
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
## NUMERIC
|
241
|
-
|
242
|
-
describe "Numeric" do
|
243
|
-
specify("#compare") do
|
244
|
-
5.compare(1) == 1 and 5.compare(5) == 0 and 5.compare(7) == -1
|
245
|
-
end
|
246
|
-
specify("#negative?") do
|
247
|
-
not 5.negative? and -2.negative?
|
248
|
-
end
|
249
|
-
specify("#negative!") do
|
250
|
-
5.negative! == -5 and -5.negative! == -5
|
251
|
-
end
|
252
|
-
specify("#number?") do
|
253
|
-
5.number?
|
254
|
-
end
|
255
|
-
specify("#positive?") do
|
256
|
-
5.positive? and not -2.positive?
|
257
|
-
end
|
258
|
-
specify("#positive!") do
|
259
|
-
5.positive! == 5 and -5.positive! == 5
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
## OBJECT
|
264
|
-
|
265
|
-
describe "Object" do
|
266
|
-
specify("#**") do
|
267
|
-
"ab" ** 5 == ["ab", "ab", "ab", "ab", "ab"]
|
268
|
-
end
|
269
|
-
specify("#array?") do
|
270
|
-
not "".array? and [].array?
|
271
|
-
end
|
272
|
-
specify("#boolean?") do
|
273
|
-
true.boolean? and false.boolean? and not "".boolean?
|
274
|
-
end
|
275
|
-
specify("#enumerable?") do
|
276
|
-
[].enumerable? and not 5.enumerable?
|
277
|
-
end
|
278
|
-
specify("#false?") do
|
279
|
-
(false.false? == true) and ("string".false? == false)
|
280
|
-
end
|
281
|
-
specify("#hash?") do
|
282
|
-
not "".hash? and {}.hash?
|
283
|
-
end
|
284
|
-
specify("#in?") do
|
285
|
-
5.in? 1..7 and not 9.in? 1..7
|
286
|
-
end
|
287
|
-
specify("#instance_of_any?") do
|
288
|
-
"".instance_of_any? [String, Symbol] \
|
289
|
-
and not "".instance_of_any? [Integer, Float] \
|
290
|
-
and "".instance_of_any? String, Symbol
|
291
|
-
end
|
292
|
-
specify("#io?") do
|
293
|
-
not "".io?
|
294
|
-
end
|
295
|
-
specify("#kind_of_any?") do
|
296
|
-
"".kind_of_any? [String, Symbol] \
|
297
|
-
and not "".kind_of_any? [Integer, Float] \
|
298
|
-
and "".kind_of_any? String, Symbol
|
299
|
-
end
|
300
|
-
specify("#number?") do
|
301
|
-
not :abcd.number? and 5.number?
|
302
|
-
end
|
303
|
-
specify("#proc?") do
|
304
|
-
proc = Proc::new { }
|
305
|
-
not :abcd.proc? and proc.proc?
|
306
|
-
end
|
307
|
-
specify("#string?") do
|
308
|
-
"".string? and not 5.string?
|
309
|
-
end
|
310
|
-
specify("#symbol?") do
|
311
|
-
:abcd.symbol? and not 5.symbol?
|
312
|
-
end
|
313
|
-
specify("#to_b") do
|
314
|
-
(nil.to_b === false) and ("ab".to_b === true)
|
315
|
-
end
|
316
|
-
specify("#to_sym") do
|
317
|
-
("ab".to_sym === :ab) and (12.to_sym == :"12")
|
318
|
-
end
|
319
|
-
specify("#true?") do
|
320
|
-
(true.true? == true) and ("string".true? == false)
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
## STRING
|
325
|
-
|
326
|
-
describe "String" do
|
327
|
-
specify("#first") do
|
328
|
-
"abcdefgh".first == ?a
|
329
|
-
end
|
330
|
-
specify("#second") do
|
331
|
-
"abcdefgh".second == ?b
|
332
|
-
end
|
333
|
-
specify("#third") do
|
334
|
-
"abcdefgh".third == ?c
|
335
|
-
end
|
336
|
-
specify("#fourth") do
|
337
|
-
"abcdefgh".fourth == ?d
|
338
|
-
end
|
339
|
-
specify("#fifth") do
|
340
|
-
"abcdefgh".fifth == ?e
|
341
|
-
end
|
342
|
-
specify("#sixth") do
|
343
|
-
"abcdefgh".sixth == ?f
|
344
|
-
end
|
345
|
-
specify("#seventh") do
|
346
|
-
"abcdefgh".seventh == ?g
|
347
|
-
end
|
348
|
-
specify("#eighth") do
|
349
|
-
"abcdefgh".eighth == ?h
|
350
|
-
end
|
351
|
-
specify("#cut!") do
|
352
|
-
foo = "0123456789"
|
353
|
-
foo.cut! 3..5
|
354
|
-
foo == "345"
|
355
|
-
end
|
356
|
-
specify("#first_line") do
|
357
|
-
res = true
|
358
|
-
res &= "a\nb\nc\n".first_line == "a\n"
|
359
|
-
res &= "a".first_line == "a"
|
360
|
-
end
|
361
|
-
specify("#first_lines") do
|
362
|
-
res = true
|
363
|
-
res &= "a\nb".first_lines(2) == ["a\n", "b"]
|
364
|
-
res &= "a\nb\nc\n".first_lines(4) == ["a\n", "b\n", "c\n"]
|
365
|
-
end
|
366
|
-
specify("#interlace") do
|
367
|
-
"abc".interlace("123") == "a123b123c"
|
368
|
-
end
|
369
|
-
specify("#interlace!") do
|
370
|
-
foo = "abc"
|
371
|
-
foo.interlace! "123"
|
372
|
-
foo == "a123b123c"
|
373
|
-
end
|
374
|
-
specify("#last") do
|
375
|
-
"abc".last == ?c
|
376
|
-
end
|
377
|
-
specify("#last_line") do
|
378
|
-
res = true
|
379
|
-
res &= "a\nb\nc\n".last_line == ""
|
380
|
-
res &= "a\nb\nc".last_line == "c"
|
381
|
-
res &= "a".last_line == "a"
|
382
|
-
end
|
383
|
-
specify("#last_lines") do
|
384
|
-
res = true
|
385
|
-
res &= "a\nb".last_lines(2) == ["a\n", "b"]
|
386
|
-
res &= "a\nb\nc\n".last_lines(4) == ["a\n", "b\n", "c\n", ""]
|
387
|
-
end
|
388
|
-
specify("#lcfirst") do
|
389
|
-
str = "ABCD"
|
390
|
-
str.lcfirst == "aBCD" and str == "ABCD"
|
391
|
-
end
|
392
|
-
specify("#lcfirst!") do
|
393
|
-
str = "ABCD"
|
394
|
-
str.lcfirst! == "aBCD" and str == "aBCD"
|
395
|
-
end
|
396
|
-
specify("#pop") do
|
397
|
-
res = true
|
398
|
-
str = "abcd"
|
399
|
-
res &= str.pop == "d"
|
400
|
-
res &= str == "abc"
|
401
|
-
str = "abcd"
|
402
|
-
res &= str.pop(2) == "cd"
|
403
|
-
res &= str == "ab"
|
404
|
-
end
|
405
|
-
specify("#pop_line") do
|
406
|
-
res = true
|
407
|
-
str = "a\nb\nc\nd"
|
408
|
-
res &= str.pop_line == "d"
|
409
|
-
res &= str = "a\nb\nc\n"
|
410
|
-
end
|
411
|
-
specify("#pop_lines") do
|
412
|
-
res = true
|
413
|
-
str = "a\nb\nc\nd\n"
|
414
|
-
res &= str.pop_lines(2) == ["d\n", ""]
|
415
|
-
res &= str = "a\nb\nc\n"
|
416
|
-
end
|
417
|
-
specify("#push_line") do
|
418
|
-
res = true
|
419
|
-
str = "a\nb\nc\nd"
|
420
|
-
res &= str.push_line("1") == "a\nb\nc\nd\n1"
|
421
|
-
res &= str == "a\nb\nc\nd\n1"
|
422
|
-
end
|
423
|
-
specify("#push_lines") do
|
424
|
-
res = true
|
425
|
-
str = "a\nb\nc\nd"
|
426
|
-
res &= str.push_lines("1", "2") == "a\nb\nc\nd\n1\n2"
|
427
|
-
res &= str == "a\nb\nc\nd\n1\n2"
|
428
|
-
end
|
429
|
-
specify("#random") do
|
430
|
-
str1 = String::random(30)
|
431
|
-
str2 = String::random(30)
|
432
|
-
|
433
|
-
str1 != str2
|
434
|
-
end
|
435
|
-
specify("#shift") do
|
436
|
-
res = true
|
437
|
-
str = "abcd"
|
438
|
-
res &= str.shift == "a"
|
439
|
-
res &= str == "bcd"
|
440
|
-
str = "abcd"
|
441
|
-
res &= str.shift(2) == "ab"
|
442
|
-
res &= str == "cd"
|
443
|
-
end
|
444
|
-
specify("#shift_line") do
|
445
|
-
res = true
|
446
|
-
str = "a\nb\nc\nd\n"
|
447
|
-
res &= str.shift_line == "a\n"
|
448
|
-
res &= str = "b\nc\nd\n"
|
449
|
-
end
|
450
|
-
specify("#shift_lines") do
|
451
|
-
res = true
|
452
|
-
str = "a\nb\nc\nd\n"
|
453
|
-
res &= str.shift_lines(2) == ["a\n", "b\n"]
|
454
|
-
res &= str = "c\nd\n"
|
455
|
-
end
|
456
|
-
specify("#string?") do
|
457
|
-
"abcd".string?
|
458
|
-
end
|
459
|
-
specify("#swap_with") do
|
460
|
-
foo = "abc"
|
461
|
-
bar = "123"
|
462
|
-
foo.swap_with(bar)
|
463
|
-
foo = "123" and bar = "abc"
|
464
|
-
end
|
465
|
-
specify("#to_boolean") do
|
466
|
-
"alfa".to_boolean("alfa") == true
|
467
|
-
end
|
468
|
-
specify("#ucfirst") do
|
469
|
-
str = "abcd"
|
470
|
-
str.ucfirst == "Abcd" and str == "abcd"
|
471
|
-
end
|
472
|
-
specify("#ucfirst!") do
|
473
|
-
str = "abcd"
|
474
|
-
str.ucfirst! == "Abcd" and str == "Abcd"
|
475
|
-
end
|
476
|
-
specify("#unshift") do
|
477
|
-
res = true
|
478
|
-
str = "abcd"
|
479
|
-
res &= str.unshift("123") == "123abcd"
|
480
|
-
res &= str == "123abcd"
|
481
|
-
end
|
482
|
-
specify("#unshift_line") do
|
483
|
-
res = true
|
484
|
-
str = "a\nb\nc\nd\n"
|
485
|
-
res &= str.unshift_line("1") == "1\na\nb\nc\nd\n"
|
486
|
-
res &= str == "1\na\nb\nc\nd\n"
|
487
|
-
end
|
488
|
-
specify("#unshift_lines") do
|
489
|
-
res = true
|
490
|
-
str = "a\nb\nc\nd\n"
|
491
|
-
res &= str.unshift_lines("1", "2") == "1\n2\na\nb\nc\nd\n"
|
492
|
-
res &= str == "1\n2\na\nb\nc\nd\n"
|
493
|
-
end
|
494
|
-
|
495
|
-
end
|
496
|
-
|
497
|
-
## STRINGIO
|
498
|
-
|
499
|
-
describe "StringIO" do
|
500
|
-
specify("#io?") do
|
501
|
-
StringIO::new.io?
|
502
|
-
end
|
503
|
-
end
|
504
|
-
|
505
|
-
## SYMBOL
|
506
|
-
|
507
|
-
describe "Symbol" do
|
508
|
-
specify("#*") do
|
509
|
-
:a * 5 == :aaaaa
|
510
|
-
end
|
511
|
-
specify("#+") do
|
512
|
-
:a + :b == :ab
|
513
|
-
end
|
514
|
-
specify("#[]") do
|
515
|
-
:abcde[0...3] == "abc"
|
516
|
-
end
|
517
|
-
specify("#append") do
|
518
|
-
:abcd.append("efg") == :abcdefg
|
519
|
-
end
|
520
|
-
specify("#end_with?") do
|
521
|
-
:abcde.end_with? "ghi", "cde"
|
522
|
-
end
|
523
|
-
specify("#prepend") do
|
524
|
-
:abcd.prepend("012") == :"012abcd"
|
525
|
-
end
|
526
|
-
specify("#split") do
|
527
|
-
:ab_cd_ef.split("_", 2) == [:ab, :cd_ef]
|
528
|
-
end
|
529
|
-
specify("#start_with?") do
|
530
|
-
:abcde.start_with? "ghi", "abc"
|
531
|
-
end
|
532
|
-
specify("#strip") do
|
533
|
-
:" a ".strip == :a
|
534
|
-
end
|
535
|
-
end
|
536
|
-
|
537
|
-
## TRUECLASS
|
538
|
-
|
539
|
-
describe "TrueClass" do
|
540
|
-
specify("#boolean?") do
|
541
|
-
true.boolean?
|
542
|
-
end
|
543
|
-
specify("#convert") do
|
544
|
-
true.convert(:a, :b) == :a
|
545
|
-
end
|
546
|
-
specify("#false?") do
|
547
|
-
not true.false?
|
548
|
-
end
|
549
|
-
specify("#to_i") do
|
550
|
-
true.to_i == 1
|
551
|
-
end
|
552
|
-
specify("#true?") do
|
553
|
-
true.true?
|
554
|
-
end
|
555
|
-
end
|
556
|
-
|