more_core_extensions 3.2.0 → 3.3.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.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_local.yml +0 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +54 -0
- data/Gemfile +8 -0
- data/README.md +21 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/more_core_extensions/all.rb +2 -0
- data/lib/more_core_extensions/core_ext/hash/sorting.rb +20 -0
- data/lib/more_core_extensions/core_ext/hash.rb +2 -1
- data/lib/more_core_extensions/core_ext/object/descendants.rb +17 -0
- data/lib/more_core_extensions/core_ext/object.rb +1 -0
- data/lib/more_core_extensions/core_ext/range/step_value.rb +45 -0
- data/lib/more_core_extensions/core_ext/range.rb +1 -0
- data/lib/more_core_extensions/core_ext/string/decimal_suffix.rb +17 -0
- data/lib/more_core_extensions/core_ext/string.rb +1 -0
- data/lib/more_core_extensions/core_ext/symbol/to_i.rb +9 -0
- data/lib/more_core_extensions/core_ext/symbol.rb +1 -0
- data/lib/more_core_extensions/version.rb +1 -1
- data/more_core_extensions.gemspec +32 -0
- metadata +36 -44
- data/spec/core_ext/array/deletes_spec.rb +0 -15
- data/spec/core_ext/array/duplicates_spec.rb +0 -9
- data/spec/core_ext/array/element_counts_spec.rb +0 -16
- data/spec/core_ext/array/inclusions_spec.rb +0 -51
- data/spec/core_ext/array/math_spec.rb +0 -16
- data/spec/core_ext/array/nested_spec.rb +0 -183
- data/spec/core_ext/array/random_spec.rb +0 -21
- data/spec/core_ext/array/stretch_spec.rb +0 -94
- data/spec/core_ext/array/tableize_spec.rb +0 -156
- data/spec/core_ext/hash/deletes_spec.rb +0 -15
- data/spec/core_ext/hash/nested_spec.rb +0 -232
- data/spec/core_ext/numeric/clamp_spec.rb +0 -17
- data/spec/core_ext/numeric/math_spec.rb +0 -6
- data/spec/core_ext/numeric/rounding_spec.rb +0 -19
- data/spec/core_ext/object/namespace_spec.rb +0 -30
- data/spec/core_ext/string/formats_spec.rb +0 -77
- data/spec/core_ext/string/hex_dump_spec.rb +0 -84
- data/spec/core_ext/string/iec60027_2_spec.rb +0 -13
- data/spec/spec_helper.rb +0 -85
@@ -1,232 +0,0 @@
|
|
1
|
-
shared_examples_for "core_ext/hash/nested will not modify arguments" do |meth|
|
2
|
-
it "will not modify arguments" do
|
3
|
-
args = (meth == :store_path ? [1] : [])
|
4
|
-
|
5
|
-
key = ["d", "d1", "d2", "d3"]
|
6
|
-
key2 = key.dup
|
7
|
-
hash.send(meth, key2, *args)
|
8
|
-
expect(key2).to eq(key)
|
9
|
-
|
10
|
-
key = ["e", "e1", "e2"]
|
11
|
-
key2 = key.dup
|
12
|
-
hash.send(meth, key2, *args)
|
13
|
-
expect(key2).to eq(key)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
shared_examples_for "core_ext/hash/nested" do
|
18
|
-
context '#fetch_path' do
|
19
|
-
it "with various values" do
|
20
|
-
expect(hash.fetch_path("a")).to eq(1)
|
21
|
-
expect(hash.fetch_path("b")).to eq({})
|
22
|
-
expect(hash.fetch_path("b", "b1")).to be_nil
|
23
|
-
expect(hash.fetch_path("b", "b1", "b2")).to be_nil
|
24
|
-
expect(hash.fetch_path("c")).to eq({"c1" => 2})
|
25
|
-
expect(hash.fetch_path("c", "c1")).to eq(2)
|
26
|
-
expect(hash.fetch_path("c", "c1", "c2")).to be_nil
|
27
|
-
expect(hash.fetch_path("d", "d1", "d2", "d3")).to eq(3)
|
28
|
-
expect(hash.fetch_path("d", "d1", "d2", "dx")).to be_nil
|
29
|
-
expect(hash.fetch_path("d", "d1", "d2", "d3", "d4")).to be_nil
|
30
|
-
expect(hash.fetch_path("e")).to eq({})
|
31
|
-
expect(hash.fetch_path("e", "e1")).to eq(4)
|
32
|
-
expect(hash.fetch_path("e", "e1", "e2")).to be_nil
|
33
|
-
expect(hash.fetch_path("f")).to eq({})
|
34
|
-
expect(hash.fetch_path("f", "f1")).to eq({})
|
35
|
-
expect(hash.fetch_path("f", "f1", "f2")).to be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it "with a nil value" do
|
39
|
-
expect(hash.fetch_path(nil)).to eq({nil => 7})
|
40
|
-
expect(hash.fetch_path("d", nil, "d1")).to be_nil
|
41
|
-
expect(hash.fetch_path("e", nil)).to eq(4)
|
42
|
-
expect(hash.fetch_path("e", nil, "e1")).to be_nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it "with array key" do
|
46
|
-
expect(hash.fetch_path([["h", "i"]])).to eq(8)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "with invalid values" do
|
50
|
-
expect { hash.fetch_path }.to raise_error(ArgumentError)
|
51
|
-
end
|
52
|
-
|
53
|
-
include_examples "core_ext/hash/nested will not modify arguments", :fetch_path
|
54
|
-
end
|
55
|
-
|
56
|
-
context "#store_path" do
|
57
|
-
it "on an empty hash" do
|
58
|
-
h = described_class.new
|
59
|
-
h.store_path("a", 1)
|
60
|
-
expect(h).to eq({"a" => 1})
|
61
|
-
|
62
|
-
h = described_class.new
|
63
|
-
h.store_path("b", "b1", 2)
|
64
|
-
expect(h).to eq({"b" => {"b1" => 2}})
|
65
|
-
end
|
66
|
-
|
67
|
-
it "on an existing hash" do
|
68
|
-
hash.store_path("b", "b1", 2)
|
69
|
-
expect(hash["b"]).to eq({"b1" => 2})
|
70
|
-
hash.store_path("c", "c1", 3)
|
71
|
-
expect(hash["c"]).to eq({"c1" => 3})
|
72
|
-
end
|
73
|
-
|
74
|
-
it "on an existing item that is not a hash" do
|
75
|
-
hash.store_path("a", 2)
|
76
|
-
expect(hash["a"]).to eq(2)
|
77
|
-
hash.store_path("a", "a1", 3)
|
78
|
-
expect(hash["a"]).to eq({"a1" => 3})
|
79
|
-
end
|
80
|
-
|
81
|
-
it "with an array key" do
|
82
|
-
h = described_class.new
|
83
|
-
h.store_path([["d", "d1"], ["d2", "d3"]], 3)
|
84
|
-
expect(h).to eq({["d", "d1"] => {["d2", "d3"] => 3}})
|
85
|
-
end
|
86
|
-
|
87
|
-
it "with a nil value" do
|
88
|
-
h = described_class.new
|
89
|
-
h.store_path("a", "b", nil)
|
90
|
-
expect(h).to eq({"a" => {"b" => nil}})
|
91
|
-
end
|
92
|
-
|
93
|
-
it "with an Array value" do
|
94
|
-
h = described_class.new
|
95
|
-
h.store_path("a", "b", ["c", "d"])
|
96
|
-
expect(h).to eq({"a" => {"b" => ["c", "d"]}})
|
97
|
-
end
|
98
|
-
|
99
|
-
it "with a Hash value" do
|
100
|
-
h = described_class.new
|
101
|
-
h.store_path("a", "b", {"c" => "d"})
|
102
|
-
expect(h).to eq({"a" => {"b" => {"c" => "d"}}})
|
103
|
-
end
|
104
|
-
|
105
|
-
it "with invalid values" do
|
106
|
-
expect { described_class.new.store_path }.to raise_error(ArgumentError)
|
107
|
-
expect { described_class.new.store_path(1) }.to raise_error(ArgumentError)
|
108
|
-
end
|
109
|
-
|
110
|
-
include_examples "core_ext/hash/nested will not modify arguments", :store_path
|
111
|
-
end
|
112
|
-
|
113
|
-
context '#has_key_path?' do
|
114
|
-
it "with various values" do
|
115
|
-
expect(hash.has_key_path?("a")).to be_truthy
|
116
|
-
expect(hash.has_key_path?("b")).to be_truthy
|
117
|
-
expect(hash.has_key_path?("b", "b1")).to be_falsey
|
118
|
-
expect(hash.has_key_path?("b", "b1", "b2")).to be_falsey
|
119
|
-
expect(hash.has_key_path?("c")).to be_truthy
|
120
|
-
expect(hash.has_key_path?("c", "c1")).to be_truthy
|
121
|
-
expect(hash.has_key_path?("c", "c1", "c2")).to be_falsey
|
122
|
-
expect(hash.has_key_path?("d", "d1", "d2", "d3")).to be_truthy
|
123
|
-
expect(hash.has_key_path?("d", "d1", "d2", "dx")).to be_falsey
|
124
|
-
expect(hash.has_key_path?("d", "d1", "d2", "d3", "d4")).to be_falsey
|
125
|
-
expect(hash.has_key_path?("e")).to be_truthy
|
126
|
-
expect(hash.has_key_path?("e", "e1")).to be_falsey
|
127
|
-
expect(hash.has_key_path?("e", "e1", "e2")).to be_falsey
|
128
|
-
expect(hash.has_key_path?("f")).to be_truthy
|
129
|
-
expect(hash.has_key_path?("f", "f1")).to be_falsey
|
130
|
-
expect(hash.has_key_path?("f", "f1", "f2")).to be_falsey
|
131
|
-
end
|
132
|
-
|
133
|
-
it "with a nil value" do
|
134
|
-
expect(hash.has_key_path?(nil)).to be_truthy
|
135
|
-
expect(hash.has_key_path?("d", nil, "d1")).to be_falsey
|
136
|
-
expect(hash.has_key_path?("e", nil)).to be_falsey
|
137
|
-
expect(hash.has_key_path?("e", nil, "e1")).to be_falsey
|
138
|
-
end
|
139
|
-
|
140
|
-
it "with invalid values" do
|
141
|
-
expect { hash.has_key_path? }.to raise_error(ArgumentError)
|
142
|
-
end
|
143
|
-
|
144
|
-
include_examples "core_ext/hash/nested will not modify arguments", :has_key_path?
|
145
|
-
end
|
146
|
-
|
147
|
-
context "#delete_path" do
|
148
|
-
it "on a nested hash" do
|
149
|
-
hash.delete_path("d", "d1", "d2", "d3")
|
150
|
-
expect(hash["d"]).to eq({"d1"=>{"d2"=>{}}})
|
151
|
-
end
|
152
|
-
|
153
|
-
it "with an invalid path" do
|
154
|
-
hash.delete_path("d", "d1", :d)
|
155
|
-
expect(hash["d"]).to eq({"d1"=>{"d2"=>{"d3"=>3}}})
|
156
|
-
end
|
157
|
-
|
158
|
-
include_examples "core_ext/hash/nested will not modify arguments", :delete_path
|
159
|
-
end
|
160
|
-
|
161
|
-
it "#delete_blank_paths" do
|
162
|
-
expect(hash.delete_blank_paths).to eq({"a"=>1, "c"=>{"c1"=>2}, "d"=>{"d1"=>{"d2"=>{"d3"=>3}}}, nil=>{nil=>7}, ["h", "i"]=>8})
|
163
|
-
end
|
164
|
-
|
165
|
-
context "#find_path" do
|
166
|
-
it "with a real value" do
|
167
|
-
expect(hash.find_path(3)).to eq(["d", "d1", "d2", "d3"])
|
168
|
-
end
|
169
|
-
|
170
|
-
it "with non-existent value" do
|
171
|
-
expect(hash.find_path(42)).to eq([])
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe Hash do
|
177
|
-
let(:hash) do
|
178
|
-
{
|
179
|
-
"a" => 1,
|
180
|
-
"b" => {},
|
181
|
-
"c" => {"c1" => 2},
|
182
|
-
"d" => {"d1" => {"d2" => {"d3" => 3}}},
|
183
|
-
"e" => Hash.new(4),
|
184
|
-
"f" => Hash.new { |h, k| h[k] = Hash.new },
|
185
|
-
nil => {nil => 7},
|
186
|
-
["h", "i"] => 8
|
187
|
-
}
|
188
|
-
end
|
189
|
-
|
190
|
-
include_examples "core_ext/hash/nested"
|
191
|
-
end
|
192
|
-
|
193
|
-
begin
|
194
|
-
require 'active_support'
|
195
|
-
require 'active_support/core_ext/hash'
|
196
|
-
describe HashWithIndifferentAccess do
|
197
|
-
let(:hash) do
|
198
|
-
described_class.new.merge(
|
199
|
-
"a" => 1,
|
200
|
-
"b" => {},
|
201
|
-
"c" => {"c1" => 2},
|
202
|
-
"d" => {"d1" => {"d2" => {"d3" => 3}}},
|
203
|
-
"e" => Hash.new(4),
|
204
|
-
"f" => described_class.new { |h, k| h[k] = described_class.new },
|
205
|
-
nil => {nil => 7},
|
206
|
-
["h", "i"] => 8
|
207
|
-
)
|
208
|
-
|
209
|
-
# NOTE: "f" has to be initialized in that way due to a bug in
|
210
|
-
# HashWithIndifferentAccess and assigning a Hash with a default proc.
|
211
|
-
#
|
212
|
-
# 1.9.3 :001 > h1 = Hash.new
|
213
|
-
# 1.9.3 :002 > h1[:a] = Hash.new { |h, k| h[k] = Hash.new }
|
214
|
-
# 1.9.3 :003 > h1[:a].class
|
215
|
-
# => Hash
|
216
|
-
# 1.9.3 :004 > h1[:a][:b].class
|
217
|
-
# => Hash
|
218
|
-
#
|
219
|
-
# 1.9.3 :005 > require 'active_support/all'
|
220
|
-
# 1.9.3 :006 > h2 = HashWithIndifferentAccess.new
|
221
|
-
# 1.9.3 :007 > h2[:a] = Hash.new { |h, k| h[k] = Hash.new }
|
222
|
-
# 1.9.3 :008 > h2[:a].class
|
223
|
-
# => ActiveSupport::HashWithIndifferentAccess
|
224
|
-
# 1.9.3 :009 > h2[:a][:b].class
|
225
|
-
# => NilClass
|
226
|
-
end
|
227
|
-
|
228
|
-
include_examples "core_ext/hash/nested"
|
229
|
-
end
|
230
|
-
rescue LoadError
|
231
|
-
# ActiveSupport v5.0.0 requires ruby '>=2.2.2', skip these tests on older rubies.
|
232
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
describe Numeric do
|
2
|
-
it "#clamp" do
|
3
|
-
expect(8.clamp(nil, nil)).to eq(8)
|
4
|
-
expect(8.clamp(3, nil)).to eq(8)
|
5
|
-
expect(8.clamp(13, nil)).to eq(13)
|
6
|
-
expect(8.clamp(nil, 6)).to eq(6)
|
7
|
-
expect(8.clamp(13, 16)).to eq(13)
|
8
|
-
expect(20.clamp(13, 16)).to eq(16)
|
9
|
-
|
10
|
-
expect(8.0.clamp(nil, nil)).to eq(8.0)
|
11
|
-
expect(8.0.clamp(3.0, nil)).to eq(8.0)
|
12
|
-
expect(8.0.clamp(13.0, nil)).to eq(13.0)
|
13
|
-
expect(8.0.clamp(nil, 6.0)).to eq(6.0)
|
14
|
-
expect(8.0.clamp(13.0, 16.0)).to eq(13.0)
|
15
|
-
expect(20.0.clamp(13.0, 16.0)).to eq(16.0)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
describe Numeric do
|
2
|
-
context "#round_up" do
|
3
|
-
it("Fixnum") { expect(1.round_up).to eq(1) }
|
4
|
-
it("Float") { expect(1.1.round_up).to eq(2.0) }
|
5
|
-
context "with a 'nearest' param" do
|
6
|
-
it("Fixnum") { expect(1.round_up(10)).to eq(10) }
|
7
|
-
it("Float") { expect(1.1.round_up(0.5)).to eq(1.5) }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context "#round_down" do
|
12
|
-
it("Fixnum") { expect(1.round_down).to eq(1) }
|
13
|
-
it("Float") { expect(1.1.round_down).to eq(1.0) }
|
14
|
-
context "with a 'nearest' param" do
|
15
|
-
it("Fixnum") { expect(11.round_down(10)).to eq(10) }
|
16
|
-
it("Float") { expect(1.6.round_down(0.5)).to eq(1.5) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
describe Class do
|
2
|
-
before do
|
3
|
-
module Aaa
|
4
|
-
module Bbb
|
5
|
-
module Ccc
|
6
|
-
class Ddd; end
|
7
|
-
module Eee; end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "in_namespace?" do
|
14
|
-
it "Class in Module" do
|
15
|
-
expect(Aaa::Bbb::Ccc::Ddd.in_namespace?(Aaa::Bbb)).to be_truthy
|
16
|
-
end
|
17
|
-
|
18
|
-
it "Module in Module" do
|
19
|
-
expect(Aaa::Bbb::Ccc::Eee.in_namespace?("Aaa::Bbb")).to be_truthy
|
20
|
-
end
|
21
|
-
|
22
|
-
it "Instance of Class" do
|
23
|
-
expect(Aaa::Bbb::Ccc::Ddd.new.in_namespace?(Aaa::Bbb)).to be_truthy
|
24
|
-
end
|
25
|
-
|
26
|
-
it "Not in namespace" do
|
27
|
-
expect(Aaa::Bbb::Ccc::Eee.in_namespace?(Aaa::Bbb::Ccc::Ddd)).to be_falsey
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
describe String do
|
2
|
-
it '#email?' do
|
3
|
-
expect("john@example.com").to be_email
|
4
|
-
expect("john.doe@example.com").to be_email
|
5
|
-
expect("john.doe@my-company.prestidigitation").to be_email
|
6
|
-
expect("john.o'doe@example.com").to be_email
|
7
|
-
expect("john.doe@EXAMPLE.COM").to be_email
|
8
|
-
expect("John.Doe@example.com").to be_email
|
9
|
-
|
10
|
-
expect("john\ndoe@example.com").not_to be_email
|
11
|
-
expect("").not_to be_email
|
12
|
-
expect("foo").not_to be_email
|
13
|
-
end
|
14
|
-
|
15
|
-
it '#domain_name?' do
|
16
|
-
expect("example.com").to be_domain_name
|
17
|
-
|
18
|
-
expect("example..com").not_to be_domain_name
|
19
|
-
expect("john.doe@example.com").not_to be_domain_name
|
20
|
-
expect("").not_to be_domain_name
|
21
|
-
expect("foo").not_to be_domain_name
|
22
|
-
end
|
23
|
-
|
24
|
-
it '#ipv4?' do
|
25
|
-
expect("192.168.252.15").to be_ipv4
|
26
|
-
|
27
|
-
expect("392.168.252.15").not_to be_ipv4
|
28
|
-
expect("").not_to be_ipv4
|
29
|
-
expect("foo").not_to be_ipv4
|
30
|
-
expect("::1").not_to be_ipv4 # 127.0.0.1 in IPv6
|
31
|
-
expect("1762:0:0:0:0:B03:1:AF18").not_to be_ipv4 # Standard Notation
|
32
|
-
expect("1762:0:0:0:0:B03:127.32.67.15").not_to be_ipv4 # Mixed Notation
|
33
|
-
expect("1762::B03:1:AF18").not_to be_ipv4 # Compressed Notation
|
34
|
-
end
|
35
|
-
|
36
|
-
it '#ipv6?' do
|
37
|
-
expect("::1").to be_ipv6 # 127.0.0.1 in IPv6
|
38
|
-
expect("1762:0:0:0:0:B03:1:AF18").to be_ipv6 # Standard Notation
|
39
|
-
expect("1762:0:0:0:0:B03:127.32.67.15").to be_ipv6 # Mixed Notation
|
40
|
-
expect("1762::B03:1:AF18").to be_ipv6 # Compressed Notation
|
41
|
-
|
42
|
-
expect("192.168.252.15").not_to be_ipv6
|
43
|
-
expect("392.168.252.15").not_to be_ipv6
|
44
|
-
expect("").not_to be_ipv6
|
45
|
-
expect("foo").not_to be_ipv6
|
46
|
-
end
|
47
|
-
|
48
|
-
it "#ipaddress?" do
|
49
|
-
expect("192.168.252.15").to be_ipaddress
|
50
|
-
expect("::1").to be_ipaddress # 127.0.0.1 in IPv6
|
51
|
-
expect("1762:0:0:0:0:B03:1:AF18").to be_ipaddress # Standard Notation
|
52
|
-
expect("1762:0:0:0:0:B03:127.32.67.15").to be_ipaddress # Mixed Notation
|
53
|
-
expect("1762::B03:1:AF18").to be_ipaddress # Compressed Notation
|
54
|
-
|
55
|
-
expect("392.168.252.15").not_to be_ipaddress
|
56
|
-
expect("").not_to be_ipaddress
|
57
|
-
expect("foo").not_to be_ipaddress
|
58
|
-
end
|
59
|
-
|
60
|
-
it "#integer?" do
|
61
|
-
expect("100").to be_integer
|
62
|
-
expect("-100").to be_integer
|
63
|
-
|
64
|
-
expect("").not_to be_integer
|
65
|
-
expect("100.2").not_to be_integer
|
66
|
-
expect("A").not_to be_integer
|
67
|
-
expect("100A").not_to be_integer
|
68
|
-
end
|
69
|
-
|
70
|
-
it '#guid?' do
|
71
|
-
expect('01234567-89ab-cdef-abcd-ef0123456789').to be_guid
|
72
|
-
|
73
|
-
expect('012ZZZ67-89ab-cdef-abcd-ef0123456789').not_to be_guid
|
74
|
-
expect("").not_to be_guid
|
75
|
-
expect("foo").not_to be_guid
|
76
|
-
end
|
77
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
describe String do
|
2
|
-
context '#hex_dump' do
|
3
|
-
let(:str) { "This is a test of the emergency broadcast system. This is only a test." }
|
4
|
-
|
5
|
-
it "will handle exceptions" do
|
6
|
-
expect { "".hex_dump(1, 2) }.to raise_error(ArgumentError)
|
7
|
-
expect { "".hex_dump(:obj => STDOUT) }.to raise_error(ArgumentError)
|
8
|
-
expect { "".hex_dump(:meth => :puts) }.to raise_error(ArgumentError)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'with empty string' do
|
12
|
-
expect("".hex_dump).to eq("")
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'with a short string' do
|
16
|
-
expect("This is a test.".hex_dump).to eq("0x00000000 54 68 69 73 20 69 73 20 61 20 74 65 73 74 2e This is a test.\n")
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'normal dump' do
|
20
|
-
expect(str.hex_dump).to eq <<-EOL
|
21
|
-
0x00000000 54 68 69 73 20 69 73 20 61 20 74 65 73 74 20 6f This is a test o
|
22
|
-
0x00000010 66 20 74 68 65 20 65 6d 65 72 67 65 6e 63 79 20 f the emergency\040
|
23
|
-
0x00000020 62 72 6f 61 64 63 61 73 74 20 73 79 73 74 65 6d broadcast system
|
24
|
-
0x00000030 2e 20 54 68 69 73 20 69 73 20 6f 6e 6c 79 20 61 . This is only a
|
25
|
-
0x00000040 20 74 65 73 74 2e test.
|
26
|
-
EOL
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'passing object and method' do
|
30
|
-
str_out = ''
|
31
|
-
str.hex_dump(:obj => str_out, :meth => :<<)
|
32
|
-
expect(str_out).to eq <<-EOL
|
33
|
-
0x00000000 54 68 69 73 20 69 73 20 61 20 74 65 73 74 20 6f This is a test o
|
34
|
-
0x00000010 66 20 74 68 65 20 65 6d 65 72 67 65 6e 63 79 20 f the emergency\040
|
35
|
-
0x00000020 62 72 6f 61 64 63 61 73 74 20 73 79 73 74 65 6d broadcast system
|
36
|
-
0x00000030 2e 20 54 68 69 73 20 69 73 20 6f 6e 6c 79 20 61 . This is only a
|
37
|
-
0x00000040 20 74 65 73 74 2e test.
|
38
|
-
EOL
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'passing :grouping => 8 option' do
|
42
|
-
expect(str.hex_dump(:grouping => 8)).to eq <<-EOL
|
43
|
-
0x00000000 54 68 69 73 20 69 73 20 This is\040
|
44
|
-
0x00000008 61 20 74 65 73 74 20 6f a test o
|
45
|
-
0x00000010 66 20 74 68 65 20 65 6d f the em
|
46
|
-
0x00000018 65 72 67 65 6e 63 79 20 ergency\040
|
47
|
-
0x00000020 62 72 6f 61 64 63 61 73 broadcas
|
48
|
-
0x00000028 74 20 73 79 73 74 65 6d t system
|
49
|
-
0x00000030 2e 20 54 68 69 73 20 69 . This i
|
50
|
-
0x00000038 73 20 6f 6e 6c 79 20 61 s only a
|
51
|
-
0x00000040 20 74 65 73 74 2e test.
|
52
|
-
EOL
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'passing :newline => false option' do
|
56
|
-
expect(str.hex_dump(:newline => false)).to eq("0x00000000 54 68 69 73 20 69 73 20 61 20 74 65 73 74 20 6f This is a test o0x00000010 66 20 74 68 65 20 65 6d 65 72 67 65 6e 63 79 20 f the emergency 0x00000020 62 72 6f 61 64 63 61 73 74 20 73 79 73 74 65 6d broadcast system0x00000030 2e 20 54 68 69 73 20 69 73 20 6f 6e 6c 79 20 61 . This is only a0x00000040 20 74 65 73 74 2e test.")
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'dumping every possible character' do
|
60
|
-
expected = (<<-EOL).force_encoding("ASCII-8BIT")
|
61
|
-
0x00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................
|
62
|
-
0x00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................
|
63
|
-
0x00000020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"\#$%&'()*+,-./
|
64
|
-
0x00000030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?
|
65
|
-
0x00000040 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
|
66
|
-
0x00000050 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_
|
67
|
-
0x00000060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno
|
68
|
-
0x00000070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.
|
69
|
-
0x00000080 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f ................
|
70
|
-
0x00000090 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f ................
|
71
|
-
0x000000a0 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af \240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257
|
72
|
-
0x000000b0 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf \260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277
|
73
|
-
0x000000c0 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf \300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317
|
74
|
-
0x000000d0 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df \320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337
|
75
|
-
0x000000e0 e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef \340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357
|
76
|
-
0x000000f0 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff \360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377
|
77
|
-
EOL
|
78
|
-
|
79
|
-
str = ''
|
80
|
-
0.upto(255) { |i| str << i.chr }
|
81
|
-
expect(str.hex_dump).to eq(expected)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
describe String do
|
2
|
-
it '#iec60027_2' do
|
3
|
-
expect("1 ".iec_60027_2_to_i).to eq(1)
|
4
|
-
expect("1 Ki".iec_60027_2_to_i).to eq(1_024)
|
5
|
-
expect("1 Mi".iec_60027_2_to_i).to eq(1_048_576)
|
6
|
-
expect("1 Gi".iec_60027_2_to_i).to eq(1_073_741_824)
|
7
|
-
expect("1 Ti".iec_60027_2_to_i).to eq(1_099_511_627_776)
|
8
|
-
expect("1 Pi".iec_60027_2_to_i).to eq(1_125_899_906_842_624)
|
9
|
-
expect("1 Ei".iec_60027_2_to_i).to eq(1_152_921_504_606_846_976)
|
10
|
-
expect("1 Zi".iec_60027_2_to_i).to eq(1_180_591_620_717_411_303_424)
|
11
|
-
expect("1 Yi".iec_60027_2_to_i).to eq(1_208_925_819_614_629_174_706_176)
|
12
|
-
end
|
13
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
-
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
-
#
|
6
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
-
# individual file that may not need all of that loaded. Instead, make a
|
10
|
-
# separate helper file that requires this one and then use it only in the specs
|
11
|
-
# that actually need it.
|
12
|
-
#
|
13
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
-
# users commonly want.
|
15
|
-
#
|
16
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
-
RSpec.configure do |config|
|
18
|
-
# The settings below are suggested to provide a good initial experience
|
19
|
-
# with RSpec, but feel free to customize to your heart's content.
|
20
|
-
|
21
|
-
# These two settings work together to allow you to limit a spec run
|
22
|
-
# to individual examples or groups you care about by tagging them with
|
23
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
24
|
-
# get run.
|
25
|
-
config.filter_run :focus
|
26
|
-
config.run_all_when_everything_filtered = true
|
27
|
-
|
28
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
29
|
-
# file, and it's useful to allow more verbose output when running an
|
30
|
-
# individual spec file.
|
31
|
-
if config.files_to_run.one?
|
32
|
-
# Use the documentation formatter for detailed output,
|
33
|
-
# unless a formatter has already been configured
|
34
|
-
# (e.g. via a command-line flag).
|
35
|
-
config.default_formatter = 'doc'
|
36
|
-
end
|
37
|
-
|
38
|
-
# Print the 10 slowest examples and example groups at the
|
39
|
-
# end of the spec run, to help surface which specs are running
|
40
|
-
# particularly slow.
|
41
|
-
# config.profile_examples = 10
|
42
|
-
|
43
|
-
# Run specs in random order to surface order dependencies. If you find an
|
44
|
-
# order dependency and want to debug it, you can fix the order by providing
|
45
|
-
# the seed, which is printed after each run.
|
46
|
-
# --seed 1234
|
47
|
-
config.order = :random
|
48
|
-
|
49
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
50
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
51
|
-
# test failures related to randomization by passing the same `--seed` value
|
52
|
-
# as the one that triggered the failure.
|
53
|
-
Kernel.srand config.seed
|
54
|
-
|
55
|
-
# rspec-expectations config goes here. You can use an alternate
|
56
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
57
|
-
# assertions if you prefer.
|
58
|
-
config.expect_with :rspec do |expectations|
|
59
|
-
# Enable only the newer, non-monkey-patching expect syntax.
|
60
|
-
# For more details, see:
|
61
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
-
expectations.syntax = :expect
|
63
|
-
end
|
64
|
-
|
65
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
66
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
67
|
-
config.mock_with :rspec do |mocks|
|
68
|
-
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
-
# For more details, see:
|
70
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
71
|
-
mocks.syntax = :expect
|
72
|
-
|
73
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
74
|
-
# a real object. This is generally recommended.
|
75
|
-
mocks.verify_partial_doubles = true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
begin
|
80
|
-
require 'coveralls'
|
81
|
-
Coveralls.wear!
|
82
|
-
rescue LoadError
|
83
|
-
end
|
84
|
-
|
85
|
-
require 'more_core_extensions/all'
|