hash-utils 2.0.2 → 2.1.0

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.
@@ -0,0 +1,17 @@
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 "IO" do
8
+ specify("#io?") do
9
+ io = File::open("./~test", "w")
10
+ result = io.io?
11
+ io.close()
12
+ result.should be_true
13
+ end
14
+ after(:all) do
15
+ File.unlink("./~test")
16
+ end
17
+ end
@@ -0,0 +1,12 @@
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 "Module" do
8
+ specify("#get_module") do
9
+ require "zlib"
10
+ Kernel.get_module("Zlib::Inflate").should eq(Zlib::Inflate)
11
+ end
12
+ end
@@ -0,0 +1,11 @@
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 "NilClass" do
8
+ specify("#to_boolean") do
9
+ nil.to_boolean("xyz").should be_false
10
+ end
11
+ end
@@ -0,0 +1,32 @@
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 "Numeric" do
8
+ specify("#compare") do
9
+ 5.compare(1).should eq(1)
10
+ 5.compare(5).should eq(0)
11
+ 5.compare(7).should eq(-1)
12
+ end
13
+ specify("#negative?") do
14
+ 5.negative?.should be_false
15
+ -2.negative?.should be_true
16
+ end
17
+ specify("#negative!") do
18
+ 5.negative!.should eq(-5)
19
+ -5.negative!.should eq(-5)
20
+ end
21
+ specify("#number?") do
22
+ 5.number?.should be_true
23
+ end
24
+ specify("#positive?") do
25
+ 5.positive?.should be_true
26
+ -2.positive?.should be_false
27
+ end
28
+ specify("#positive!") do
29
+ 5.positive!.should eq(5)
30
+ -5.positive!.should eq(5)
31
+ end
32
+ end
@@ -0,0 +1,78 @@
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 "Object" do
8
+ specify("#**") do
9
+ ("ab" ** 5).should eq(["ab", "ab", "ab", "ab", "ab"])
10
+ end
11
+ specify("#array?") do
12
+ "".array?.should be_false
13
+ [].array?.should be_true
14
+ end
15
+ specify("#boolean?") do
16
+ true.boolean?.should be_true
17
+ false.boolean?.should be_true
18
+ "".boolean?.should be_false
19
+ end
20
+ specify("#enumerable?") do
21
+ [].enumerable?.should be_true
22
+ 5.enumerable?.should be_false
23
+ end
24
+ specify("#false?") do
25
+ false.false?.should be_true
26
+ "string".false?.should be_false
27
+ end
28
+ specify("#hash?") do
29
+ "".hash?.should be_false
30
+ {}.hash?.should be_true
31
+ end
32
+ specify("#in?") do
33
+ (5.in? 1..7).should be_true
34
+ (9.in? 1..7).should be_false
35
+ end
36
+ specify("#instance_of_any?") do
37
+ "".instance_of_any?([String, Symbol]).should be_true
38
+ "".instance_of_any?([Integer, Float]).should be_false
39
+ "".instance_of_any?(String, Symbol).should be_true
40
+ end
41
+ specify("#io?") do
42
+ "".io?.should_not == true
43
+ end
44
+ specify("#kind_of_any?") do
45
+ "".kind_of_any?([String, Symbol]).should be_true
46
+ "".kind_of_any?([Integer, Float]).should be_false
47
+ "".kind_of_any?(String, Symbol).should be_true
48
+ end
49
+ specify("#number?") do
50
+ :abcd.number?.should be_false
51
+ 5.number?.should be_true
52
+ end
53
+ specify("#proc?") do
54
+ proc = Proc::new { }
55
+ :abcd.proc?.should be_false
56
+ proc.proc?.should be_true
57
+ end
58
+ specify("#string?") do
59
+ "".string?.should be_true
60
+ 5.string?.should be_false
61
+ end
62
+ specify("#symbol?") do
63
+ :abcd.symbol?.should be_true
64
+ 5.symbol?.should be_false
65
+ end
66
+ specify("#to_b") do
67
+ nil.to_b.should be_false
68
+ "ab".to_b.should be_true
69
+ end
70
+ specify("#to_symbol") do
71
+ "ab".to_symbol.should eq(:ab)
72
+ 12.to_symbol.should eq(:"12")
73
+ end
74
+ specify("#true?") do
75
+ true.true?.should be_true
76
+ "string".true?.should be_false
77
+ end
78
+ end
@@ -0,0 +1,245 @@
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 "String" do
8
+ specify("#first") do
9
+ "abcdefgh".first.should eq("a")
10
+ end
11
+ specify("#second") do
12
+ "abcdefgh".second.should eq("b")
13
+ end
14
+ specify("#third") do
15
+ "abcdefgh".third.should eq("c")
16
+ end
17
+ specify("#fourth") do
18
+ "abcdefgh".fourth.should eq("d")
19
+ end
20
+ specify("#fifth") do
21
+ "abcdefgh".fifth.should eq("e")
22
+ end
23
+ specify("#sixth") do
24
+ "abcdefgh".sixth.should eq("f")
25
+ end
26
+ specify("#seventh") do
27
+ "abcdefgh".seventh.should eq("g")
28
+ end
29
+ specify("#eighth") do
30
+ "abcdefgh".eighth.should eq("h")
31
+ end
32
+ specify("#cut!") do
33
+ foo = "0123456789"
34
+ foo.cut! 3..5
35
+ foo.should eq("345")
36
+ end
37
+ specify("#first_line") do
38
+ res = true
39
+ res &= "a\nb\nc\n".first_line == "a\n"
40
+ res &= "a".first_line == "a"
41
+ res.should be_true
42
+ end
43
+ specify("#first_lines") do
44
+ res = true
45
+ res &= "a\nb".first_lines(2) == ["a\n", "b"]
46
+ res &= "a\nb\nc\n".first_lines(4) == ["a\n", "b\n", "c\n"]
47
+ res.should be_true
48
+ end
49
+ specify("#interlace") do
50
+ "abc".interlace("123").should eq("a123b123c")
51
+ end
52
+ specify("#interlace!") do
53
+ foo = "abc"
54
+ foo.interlace! "123"
55
+ foo.should eq("a123b123c")
56
+ end
57
+ specify("#last") do
58
+ "abc".last.should eq("c")
59
+ end
60
+ specify("#last_line") do
61
+ res = true
62
+ res &= "a\nb\nc\n".last_line == ""
63
+ res &= "a\nb\nc".last_line == "c"
64
+ res &= "a".last_line == "a"
65
+ res.should be_true
66
+ end
67
+ specify("#last_lines") do
68
+ res = true
69
+ res &= "a\nb".last_lines(2) == ["a\n", "b"]
70
+ res &= "a\nb\nc\n".last_lines(4) == ["a\n", "b\n", "c\n", ""]
71
+ res.should be_true
72
+ end
73
+ specify("#lcfirst") do
74
+ str = "ABCD"
75
+ str.lcfirst.should eq("aBCD")
76
+ str.should eq("ABCD")
77
+ end
78
+ specify("#lcfirst!") do
79
+ str = "ABCD"
80
+ str.lcfirst!.should eq("aBCD")
81
+ str.should eq("aBCD")
82
+ end
83
+ specify("#map") do
84
+ "012".map { |ch| (ch.to_i + 1).to_s }.should eq("123")
85
+ "".map { |ch| (ch.to_i + 1).to_s }.should eq("")
86
+ end
87
+ specify("#map!") do
88
+ t = "012"
89
+ t.map! { |ch| (ch.to_i + 1).to_s }
90
+ t.should eq("123")
91
+
92
+ t = ""
93
+ t.map! { |ch| (ch.to_i + 1).to_s }
94
+ t.should eq("")
95
+ end
96
+ specify("#numeric?") do
97
+ "123".numeric?.should be_true
98
+ "123a".numeric?.should be_false
99
+ "12a3".numeric?.should be_false
100
+ "a123".numeric?.should be_false
101
+ end
102
+ specify("#pop") do
103
+ res = true
104
+ str = "abcd"
105
+ res &= str.pop == "d"
106
+ res &= str == "abc"
107
+ str = "abcd"
108
+ res &= str.pop(2) == "cd"
109
+ res &= str == "ab"
110
+ res.should be_true
111
+ end
112
+ specify("#pop_line") do
113
+ res = true
114
+ str = "a\nb\nc\nd"
115
+ res &= str.pop_line == "d"
116
+ res &= str = "a\nb\nc\n"
117
+ res.should be_true
118
+ end
119
+ specify("#pop_lines") do
120
+ res = true
121
+ str = "a\nb\nc\nd\n"
122
+ res &= str.pop_lines(2) == ["d\n", ""]
123
+ res &= str = "a\nb\nc\n"
124
+ res.should be_true
125
+ end
126
+ specify("#push_line") do
127
+ res = true
128
+ str = "a\nb\nc\nd"
129
+ res &= str.push_line("1") == "a\nb\nc\nd\n1"
130
+ res &= str == "a\nb\nc\nd\n1"
131
+ res.should be_true
132
+ end
133
+ specify("#push_lines") do
134
+ res = true
135
+ str = "a\nb\nc\nd"
136
+ res &= str.push_lines("1", "2") == "a\nb\nc\nd\n1\n2"
137
+ res &= str == "a\nb\nc\nd\n1\n2"
138
+ res.should be_true
139
+ end
140
+ specify("#random") do
141
+ str1 = String::random(30)
142
+ str2 = String::random(30)
143
+ (str1 != str2).should be_true
144
+ end
145
+ specify("#shift") do
146
+ res = true
147
+ str = "abcd"
148
+ res &= str.shift == "a"
149
+ res &= str == "bcd"
150
+ str = "abcd"
151
+ res &= str.shift(2) == "ab"
152
+ res &= str == "cd"
153
+ res.should be_true
154
+ end
155
+ specify("#shift_line") do
156
+ res = true
157
+ str = "a\nb\nc\nd\n"
158
+ res &= str.shift_line == "a\n"
159
+ res &= str = "b\nc\nd\n"
160
+ res.should be_true
161
+ end
162
+ specify("#shift_lines") do
163
+ res = true
164
+ str = "a\nb\nc\nd\n"
165
+ res &= str.shift_lines(2) == ["a\n", "b\n"]
166
+ res &= str = "c\nd\n"
167
+ res.should be_true
168
+ end
169
+ specify("#string?") do
170
+ "abcd".string?.should be_true
171
+ end
172
+ specify("#strtr") do
173
+ "aa bb".strtr("aa" => "bb", "bb" => "aa").should eq("bb aa")
174
+ "aa bb".strtr([["aa", "bb"], ["bb", "aa"]]).should eq("bb aa")
175
+ "aa bb".strtr(["aa", "bb", "bb", "aa"], :flat).should eq("bb aa")
176
+ "aa bb".strtr(:aa => "bb", :bb => "aa") { |s| s.to_sym }.should eq("bb aa")
177
+ end
178
+ specify("#strtr!") do
179
+ t = "aa bb"
180
+ t.strtr!("aa" => "bb", "bb" => "aa")
181
+ t.should eq("bb aa")
182
+
183
+ t = "aa bb"
184
+ t.strtr!([["aa", "bb"], ["bb", "aa"]])
185
+ t.should eq("bb aa")
186
+
187
+ t = "aa bb"
188
+ t.strtr!(["aa", "bb", "bb", "aa"], :flat)
189
+ t.should eq("bb aa")
190
+
191
+ t = "aa bb"
192
+ t.strtr!(:aa => "bb", :bb => "aa") { |s| s.to_sym }
193
+ t.should eq("bb aa")
194
+ end
195
+ specify("#swap_with") do
196
+ foo = "abc"
197
+ bar = "123"
198
+ foo.swap_with(bar)
199
+
200
+ foo.should eq("123")
201
+ bar.should eq("abc")
202
+ end
203
+ specify("#to_a") do
204
+ "abc".to_a.should eq(["a", "b", "c"])
205
+ "abc".to_a('X').should eq(["abc"])
206
+ "aXbXc".to_a('X').should eq(["a", "b", "c"])
207
+ "".to_a.should eq([ ])
208
+ "".to_a('X').should eq([ ])
209
+ end
210
+ specify("#to_boolean") do
211
+ "alfa".to_boolean("alfa").should be_true
212
+ end
213
+ specify("#ucfirst") do
214
+ str = "abcd"
215
+ str.ucfirst.should eq("Abcd")
216
+ str.should eq("abcd")
217
+ end
218
+ specify("#ucfirst!") do
219
+ str = "abcd"
220
+ str.ucfirst!.should eq("Abcd")
221
+ str.should eq("Abcd")
222
+ end
223
+ specify("#unshift") do
224
+ res = true
225
+ str = "abcd"
226
+ res &= str.unshift("123") == "123abcd"
227
+ res &= str == "123abcd"
228
+ res.should be_true
229
+ end
230
+ specify("#unshift_line") do
231
+ res = true
232
+ str = "a\nb\nc\nd\n"
233
+ res &= str.unshift_line("1") == "1\na\nb\nc\nd\n"
234
+ res &= str == "1\na\nb\nc\nd\n"
235
+ res.should be_true
236
+ end
237
+ specify("#unshift_lines") do
238
+ res = true
239
+ str = "a\nb\nc\nd\n"
240
+ res &= str.unshift_lines("1", "2") == "1\n2\na\nb\nc\nd\n"
241
+ res &= str == "1\n2\na\nb\nc\nd\n"
242
+ res.should be_true
243
+ end
244
+
245
+ end
@@ -0,0 +1,11 @@
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 "StringIO" do
8
+ specify("#io?") do
9
+ StringIO::new.io?.should be_true
10
+ end
11
+ end
@@ -0,0 +1,40 @@
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 "Symbol" do
8
+ specify("#<=>") do
9
+ (:aa <=> :aa).should eq(0)
10
+ (:aa <=> :bb).should eq(-1)
11
+ (:bb <=> :aa).should eq(1)
12
+ end
13
+ specify("#*") do
14
+ (:a * 5).should eq(:aaaaa)
15
+ end
16
+ specify("#+") do
17
+ (:a + :b).should eq(:ab)
18
+ end
19
+ specify("#[]") do
20
+ :abcde[0...3].should eq("abc")
21
+ end
22
+ specify("#append") do
23
+ :abcd.append("efg").should eq(:abcdefg)
24
+ end
25
+ specify("#end_with?") do
26
+ :abcde.end_with?("ghi", "cde").should be_true
27
+ end
28
+ specify("#prepend") do
29
+ :abcd.prepend("012").should eq(:"012abcd")
30
+ end
31
+ specify("#split") do
32
+ :ab_cd_ef.split("_", 2).should eq([:ab, :cd_ef])
33
+ end
34
+ specify("#start_with?") do
35
+ :abcde.start_with?("ghi", "abc").should be_true
36
+ end
37
+ specify("#strip") do
38
+ :" a ".strip.should eq(:a)
39
+ end
40
+ end