vigilem-support 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/vigilem/ffi.rb +19 -0
- data/lib/vigilem/ffi/array_pointer_sync.rb +382 -0
- data/lib/vigilem/ffi/struct.rb +54 -0
- data/lib/vigilem/ffi/utils.rb +240 -0
- data/lib/vigilem/ffi/utils/struct.rb +93 -0
- data/lib/vigilem/support.rb +31 -0
- data/lib/vigilem/support/core_ext.rb +13 -0
- data/lib/vigilem/support/core_ext/debug_puts.rb +5 -0
- data/lib/vigilem/support/core_ext/enumerable.rb +25 -0
- data/lib/vigilem/support/key_map.rb +323 -0
- data/lib/vigilem/support/key_map_info.rb +85 -0
- data/lib/vigilem/support/lazy_simple_delegator.rb +81 -0
- data/lib/vigilem/support/max_size_error.rb +17 -0
- data/lib/vigilem/support/metadata.rb +13 -0
- data/lib/vigilem/support/obj_space.rb +28 -0
- data/lib/vigilem/support/patch/cucumber/c_lexer.rb +30 -0
- data/lib/vigilem/support/patch/ffi/pointer.rb +19 -0
- data/lib/vigilem/support/size_error.rb +6 -0
- data/lib/vigilem/support/sys.rb +5 -0
- data/lib/vigilem/support/system.rb +92 -0
- data/lib/vigilem/support/transmutable_hash.rb +206 -0
- data/lib/vigilem/support/utils.rb +224 -0
- data/lib/vigilem/support/version.rb +5 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/vigilem/ffi/array_pointer_sync_spec.rb +728 -0
- data/spec/vigilem/ffi/struct_spec.rb +22 -0
- data/spec/vigilem/ffi/utils/struct_spec.rb +79 -0
- data/spec/vigilem/ffi/utils_spec.rb +240 -0
- data/spec/vigilem/support/core_ext/enumerable_spec.rb +38 -0
- data/spec/vigilem/support/data/cached.kmap +130 -0
- data/spec/vigilem/support/data/cached_UTF-8_del.kmap +142 -0
- data/spec/vigilem/support/data/cached_short.kmap +38 -0
- data/spec/vigilem/support/data/dump_keys_short.kmap +128 -0
- data/spec/vigilem/support/key_map_spec.rb +767 -0
- data/spec/vigilem/support/lazy_simple_delegator_spec.rb +77 -0
- data/spec/vigilem/support/obj_space_spec.rb +47 -0
- data/spec/vigilem/support/sys_spec.rb +21 -0
- data/spec/vigilem/support/system_spec.rb +31 -0
- data/spec/vigilem/support/transmutable_hash_spec.rb +175 -0
- data/spec/vigilem/support/utils_spec.rb +214 -0
- metadata +240 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'vigilem/support/lazy_simple_delegator'
|
2
|
+
|
3
|
+
describe Vigilem::Support::LazySimpleDelegator do
|
4
|
+
|
5
|
+
class Dino
|
6
|
+
def rawr!
|
7
|
+
puts 'rawr!'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'before __setobj__' do
|
12
|
+
it %q<won't error with nil argument on instantiation> do
|
13
|
+
expect { described_class.new() }.to_not raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { described_class.new() }
|
18
|
+
|
19
|
+
let(:before___setobj___to_s) { subject.to_s }
|
20
|
+
|
21
|
+
context 'after __setobj__' do
|
22
|
+
|
23
|
+
let(:dino) { Dino.new }
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
subject.__setobj__(dino)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'will not allow delegation to self' do
|
30
|
+
expect { subject.__setobj__(subject) }.to raise_error(ArgumentError, 'cannot delegate to self')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'will have its own to_s unlike built in ruby delegate' do
|
34
|
+
expect(subject.to_s).to eql before___setobj___to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'will have its own inspect unlike built in ruby delegate' do
|
38
|
+
expect(subject.inspect).not_to eql dino.inspect
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'delegation' do
|
42
|
+
it 'will take on object methods' do
|
43
|
+
expect(subject).to respond_to :rawr!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#strict_eql=, #strict_eql?, #use_strict_eql' do
|
48
|
+
|
49
|
+
context 'default behavior' do
|
50
|
+
it '#strict_eql?, defaults to false' do
|
51
|
+
expect(subject.strict_eql?).to be_falsey
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#strict_eql=' do
|
56
|
+
it %q<#strict_eql?, is true compares a delegator's __getobj__.object_id's> do
|
57
|
+
subject.strict_eql = true
|
58
|
+
expect(subject.eql?(SimpleDelegator.new(dino))).to be_truthy
|
59
|
+
end
|
60
|
+
|
61
|
+
it %q<#strict_eql?, is true compares a non Delegators object_id to this __getobj__.object_id> do
|
62
|
+
subject.strict_eql = true
|
63
|
+
expect(subject.eql?(dino)).to be_truthy
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#use_strict_eql' do
|
68
|
+
it %q<#use_strict_eql, sets strict_eql? to true and returns self> do
|
69
|
+
expect(subject.use_strict_eql).to eql(subject) and
|
70
|
+
an_object_having_attributes(:strict_eql? => true)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'vigilem/support/obj_space'
|
2
|
+
|
3
|
+
describe Vigilem::Support::ObjSpace do
|
4
|
+
|
5
|
+
class ObjSpaceHost
|
6
|
+
extend Vigilem::Support::ObjSpace
|
7
|
+
end
|
8
|
+
|
9
|
+
class SubObjSpaceHost < ObjSpaceHost
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
ObjSpaceHost.all.replace([])
|
14
|
+
SubObjSpaceHost.all.replace([])
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#all' do
|
18
|
+
it 'defaults to []' do
|
19
|
+
expect(ObjSpaceHost.all).to eql([])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#obj_register' do
|
24
|
+
it 'returns the obj registered' do
|
25
|
+
expect(ObjSpaceHost.obj_register('asdf')).to eql('asdf')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'adds the obj to #all' do
|
29
|
+
ObjSpaceHost.obj_register('asdf')
|
30
|
+
expect(ObjSpaceHost.all).to include('asdf')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'subclass' do
|
35
|
+
it %q<will add to the parent class #all> do
|
36
|
+
SubObjSpaceHost.obj_register('test')
|
37
|
+
expect(ObjSpaceHost.all).to include('test')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'will not list the parent class objects' do
|
41
|
+
ObjSpaceHost.obj_register('asdf')
|
42
|
+
expect(SubObjSpaceHost.all).not_to include('asdf')
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'vigilem/support/sys'
|
4
|
+
|
5
|
+
describe Vigilem::Support::Sys do
|
6
|
+
describe '::sizeof' do
|
7
|
+
describe 'returns the size of a string variable format' do
|
8
|
+
Given 'ii' do
|
9
|
+
Then { expect(described_class.sizeof(given_value)).to eql(8) }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'with number repeats' do
|
13
|
+
expect(described_class.sizeof('CCSI32C')).to eql(133)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'with !' do
|
17
|
+
expect(described_class.sizeof('CCS!I32C')).to eql(133)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
require 'vigilem/support/system'
|
3
|
+
|
4
|
+
describe Vigilem::Support::System do
|
5
|
+
|
6
|
+
describe '::`mask_name`' do
|
7
|
+
it 'will respond_to? :mac?' do
|
8
|
+
expect(described_class).to respond_to(:mac?)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'will respond_to? :linux?' do
|
12
|
+
expect(described_class).to respond_to(:linux?)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'will respond_to? :windows?' do
|
16
|
+
expect(described_class).to respond_to(:windows?)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'will respond_to? :bsd?' do
|
20
|
+
expect(described_class).to respond_to(:bsd?)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'will respond_to? :nix?' do
|
24
|
+
expect(described_class).to respond_to(:nix?)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'will respond_to? :aix?' do
|
28
|
+
expect(described_class).to respond_to(:aix?)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'vigilem/support/transmutable_hash'
|
4
|
+
|
5
|
+
# {:key1=>["a", "b", "c"], :key2=>["e", "f"], :key => "d" }
|
6
|
+
# {:key1=>["a", "b", "c"], :key2=>["d", "e", "f"]} becomes
|
7
|
+
# {"a"=>:key1, "b"=>:key1, "c"=>:key1, "d"=>:key2, "e"=>:key2, "f"=>:key2 }
|
8
|
+
# it will have a different object_id, because technically its a different hash
|
9
|
+
describe Vigilem::Support::TransmutableHash do
|
10
|
+
Given(:hash_map) { described_class.new({:key1 => %w(a b c), :key2 => %w(e f), :key => 'd' }, 'default') }
|
11
|
+
|
12
|
+
Given(:dump_key_hash) {
|
13
|
+
{"keycode1"=>"Escape", ["shift", "keycode1"]=>"Escape", ["altgr", "keycode1"]=>"Escape",
|
14
|
+
["shift", "altgr", "keycode1"]=>"Escape", ["control", "keycode1"]=>"Escape",
|
15
|
+
["shift", "control", "keycode1"]=>"Escape", ["altgr", "control", "keycode1"]=>"Escape",
|
16
|
+
["shift", "altgr", "control", "keycode1"]=>"Escape", ["alt", "keycode1"]=>"Meta_Escape",
|
17
|
+
["shift","alt", "keycode1"]=>"Meta_Escape", ["altgr", "alt", "keycode1"]=>"Meta_Escape",
|
18
|
+
["shift", "altgr", "alt", "keycode1"]=>"Meta_Escape",
|
19
|
+
["control", "alt", "keycode1"]=>"Meta_Escape", ["shift", "control", "alt", "keycode1"]=>"Meta_Escape"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
describe '#invert' do
|
25
|
+
When(:result) { hash_map.invert }
|
26
|
+
|
27
|
+
Then { result == { "a" => :key1, "b" => :key1, "c" => :key1, "d" => :key, "e" => :key2, "f" => :key2 } }
|
28
|
+
|
29
|
+
Then { hash_map.send(:_invert_cache_) == result }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#invert!' do
|
34
|
+
Given(:original) { described_class.new({%w(this is a key) => :value, :key2=>["e", "f"], :key => "d"}) }
|
35
|
+
Given(:hsh) { described_class.new({%w(this is a key) => :value, :key2=>["e", "f"], :key => "d"}) }
|
36
|
+
|
37
|
+
it 'updates inplace the inversion' do
|
38
|
+
hsh.invert!
|
39
|
+
expect(hsh).to eql(original.invert)
|
40
|
+
expect(hsh).not_to eql(original)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '::fuse_vaue' do
|
46
|
+
|
47
|
+
it 'concats values to when keys match' do
|
48
|
+
hsh = {%w(this is a key) => :value, :key2=>["e", "f"], :key => "d"}
|
49
|
+
expect(described_class.fuse_value(hsh, :key, 'my_value')).to eql(
|
50
|
+
{["this", "is", "a", "key"]=>:value, :key2=>["e", "f"], :key=>["d", "my_value"]}
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'inserts arrays when keys match' do
|
55
|
+
hsh = {%w(this is a key) => :value, :key2=>["e", "f"], :key => "d"}
|
56
|
+
expect(described_class.fuse_value(hsh, :key2, ['my_value'])).to eql(
|
57
|
+
{["this", "is", "a", "key"]=>:value, :key2=>["e", "f", ['my_value']], :key=>"d"}
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'acts like merge' do
|
62
|
+
hsh = {%w(this is a key) => :value, :key2=>["e", "f"], :key => "d"}
|
63
|
+
expect(described_class.fuse_value(hsh, %w(my new key), 'my_value')).to eql(
|
64
|
+
{["this", "is", "a", "key"]=>:value, :key2=>["e", "f"], :key=>"d", ["my", "new", "key"]=>"my_value"}
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'acts like merge and wraps an array value' do
|
69
|
+
hsh = {%w(this is a key) => :value, :key2=>["e", "f"], :key => "d"}
|
70
|
+
expect(described_class.fuse_value(hsh, %w(my new key), ['my_value'])).to eql(
|
71
|
+
{["this", "is", "a", "key"]=>:value, :key2=>["e", "f"], :key=>"d", ["my", "new", "key"]=>[["my_value"]]}
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '::transmute' do
|
78
|
+
|
79
|
+
it 'inverts the hash and splits up array values into keys' do
|
80
|
+
hsh = described_class.transmute({:key => [1,2,3] })
|
81
|
+
expect(hsh).to eql({1 => :key, 2 => :key, 3 => :key })
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'inverts the hash and wraps Array keys to prevent split up' do
|
85
|
+
hsh = described_class.transmute(
|
86
|
+
{["this", "is", "a", "key"]=>:value, :key2=>["e", "f"], :key=>"d"}
|
87
|
+
)
|
88
|
+
|
89
|
+
expect(hsh).to eql(
|
90
|
+
{:value=>[["this", "is", "a", "key"]], "e"=>:key2, "f"=>:key2, "d"=>:key}
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'prevent invert!.invert from breaking down the hash' do
|
95
|
+
it 'prevents Array keys from being split up on invert' do
|
96
|
+
hsh = described_class.new(
|
97
|
+
{["this", "is", "a", "key"]=>:value, :key2=>["e", "f"], :key=>"d"}
|
98
|
+
)
|
99
|
+
expect(hsh.invert!.invert).to eql(
|
100
|
+
{["this", "is", "a", "key"]=>:value, :key2=>["e", "f"], :key=>"d"}
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'setting default' do
|
107
|
+
|
108
|
+
describe 'values' do
|
109
|
+
Given(:default_value) { 'default' }
|
110
|
+
|
111
|
+
describe 'with #new(default_value),' do
|
112
|
+
When(:instantiated) { described_class.new(default_value) }
|
113
|
+
|
114
|
+
Then { expect(instantiated.default).to eql default_value }
|
115
|
+
Then { expect(instantiated.invert_default).to eql default_value }
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'with #default=,' do
|
119
|
+
When(:assigned_default) do
|
120
|
+
sbj = described_class.new
|
121
|
+
sbj.default = default_value
|
122
|
+
sbj
|
123
|
+
end
|
124
|
+
|
125
|
+
Then { expect(assigned_default.default).to eql default_value }
|
126
|
+
Then { expect(assigned_default.invert_default).to eql nil }
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'with #defaults=,' do
|
130
|
+
When(:assigned_defaults) do
|
131
|
+
sbj = described_class.new
|
132
|
+
sbj.defaults = default_value
|
133
|
+
sbj
|
134
|
+
end
|
135
|
+
|
136
|
+
Then { expect(assigned_defaults.defaults).to eql [default_value, default_value] }
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'procs' do
|
142
|
+
let(:proc) { lambda {|h,k| h[k] = Hash.new() } }
|
143
|
+
|
144
|
+
describe 'with #new(&proc),' do
|
145
|
+
|
146
|
+
When(:instantiated) { described_class.new(&proc) }
|
147
|
+
|
148
|
+
Then { expect(instantiated.default_proc).to eql proc }
|
149
|
+
Then { expect(instantiated.invert_default_proc).to eql proc }
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'with #default_proc=,' do
|
153
|
+
|
154
|
+
When(:assigned_default_proc) do
|
155
|
+
sbj = described_class.new
|
156
|
+
sbj.default_proc = proc
|
157
|
+
sbj
|
158
|
+
end
|
159
|
+
|
160
|
+
Then { expect(assigned_default_proc.default_proc).to eql proc }
|
161
|
+
Then { expect(assigned_default_proc.invert_default_proc).to eql nil }
|
162
|
+
end
|
163
|
+
|
164
|
+
describe 'with #default_procs=,' do
|
165
|
+
When(:assigned_default_procs) do
|
166
|
+
sbj = described_class.new
|
167
|
+
sbj.default_procs = proc
|
168
|
+
sbj
|
169
|
+
end
|
170
|
+
|
171
|
+
Then { expect(assigned_default_procs.default_procs).to eql [proc, proc] }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'vigilem/support/utils'
|
4
|
+
|
5
|
+
describe Vigilem::Support::Utils do
|
6
|
+
|
7
|
+
describe '::_offset_from_length' do
|
8
|
+
it 'returns the amount that len is over the size of object' do
|
9
|
+
expect(subject._offset_from_length('tests', 7)).to eql(2)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns 0 if the len passed in is lower than obj.size' do
|
13
|
+
expect(subject._offset_from_length('tests', 3)).to eql(0)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'ArrayAndStringUtils' do
|
18
|
+
|
19
|
+
describe '#split_at' do
|
20
|
+
Given(:str) { 'asdfqwer' }
|
21
|
+
|
22
|
+
When(:result) { subject.split_at(str, 3) }
|
23
|
+
|
24
|
+
Then { result == ['asd', 'fqwer'] }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#split_on' do
|
28
|
+
|
29
|
+
let(:str) { ['keycode 2', '=', 'U+0031', 'U+0021', 'U+0031', 'U+0031', 'VoidSymbol'] }
|
30
|
+
|
31
|
+
it 'acts like String#split in which it removes the item split on' do
|
32
|
+
expect(subject.split_on(str, 1)).to eql([['keycode 2'], ['U+0031', 'U+0021', 'U+0031', 'U+0031', 'VoidSymbol']])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#offset!, #offset' do
|
37
|
+
|
38
|
+
context 'String param' do
|
39
|
+
|
40
|
+
Given(:str) { 'tests' }
|
41
|
+
Given(:orig_str) { str }
|
42
|
+
|
43
|
+
context 'len < str' do
|
44
|
+
|
45
|
+
describe '#offset!' do
|
46
|
+
When(:result) { subject.offset!(str, 2) }
|
47
|
+
|
48
|
+
Then { result == ['te', 0] }
|
49
|
+
Then { str == 'sts' }
|
50
|
+
end
|
51
|
+
describe '#offset' do
|
52
|
+
When(:result) { subject.offset(str, 2) }
|
53
|
+
|
54
|
+
Then { result == ['te', 0] }
|
55
|
+
Then { result.object_id != str.object_id }
|
56
|
+
Then { str == orig_str }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'len > str' do
|
61
|
+
describe '#offset' do
|
62
|
+
When(:result) { subject.offset!(str, 7) }
|
63
|
+
|
64
|
+
Then { result == ['tests', 2] }
|
65
|
+
end
|
66
|
+
describe '#offset' do
|
67
|
+
When(:result) { subject.offset(str, 7) }
|
68
|
+
|
69
|
+
Then { result == ['tests', 2] }
|
70
|
+
Then { str == orig_str }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'Array param' do
|
77
|
+
|
78
|
+
Given(:ary) { ['a', 'b', 'c', 'd'] }
|
79
|
+
Given(:orig_ary) { ary }
|
80
|
+
|
81
|
+
context 'len < ary' do
|
82
|
+
describe '#offset!' do
|
83
|
+
When(:result) { subject.offset!(ary, 2) }
|
84
|
+
|
85
|
+
Then { result == [['a', 'b'], 0] }
|
86
|
+
end
|
87
|
+
describe '#offset' do
|
88
|
+
When(:result) { subject.offset(ary, 2) }
|
89
|
+
|
90
|
+
Then { result == [['a', 'b'], 0] }
|
91
|
+
Then { ary == orig_ary }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'len > ary' do
|
96
|
+
describe '#offset!' do
|
97
|
+
When(:result) { subject.offset!(ary, 7) }
|
98
|
+
|
99
|
+
Then { result == [['a', 'b', 'c', 'd'], 3] }
|
100
|
+
end
|
101
|
+
describe '#offset' do
|
102
|
+
When(:result) { subject.offset(ary, 7) }
|
103
|
+
|
104
|
+
Then { result == [['a', 'b', 'c', 'd'], 3] }
|
105
|
+
Then { ary == orig_ary }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#unwrap_ary' do
|
113
|
+
it 'pops the item off the array when there is only one item in it' do
|
114
|
+
expect(described_class.unwrap_ary([1])).to eql(1)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'leaves the array as is if there is more than one item in it' do
|
118
|
+
expect(described_class.unwrap_ary([1,2,3])).to eql([1,2,3])
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#in_ranged_array?' do
|
123
|
+
it 'is the number included in an array of ranged items' do
|
124
|
+
expect(described_class.in_ranged_array?([0..12, 17..21], 18)).to be_truthy
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'handles a mixed array of Integer and ranges' do
|
128
|
+
expect(described_class.in_ranged_array?([0..12, 17, 19, 21], 19)).to be_truthy
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'NumericUtils' do
|
135
|
+
|
136
|
+
describe '#clamp' do
|
137
|
+
it 'returns the lower bounds if lower than it' do
|
138
|
+
expect(subject.clamp(-12, min: 0)).to eql(0)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'returns the upper bounds if greater than it' do
|
142
|
+
expect(subject.clamp(15, max: 12)).to eql(12)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'returns the variable given in if between the limits' do
|
146
|
+
expect(subject.clamp(5, min: 3, max: 12)).to eql(5)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#ceil_div' do
|
151
|
+
Given(:num) { 10 }
|
152
|
+
Given(:denom) { 7 }
|
153
|
+
|
154
|
+
When(:result) { subject.ceil_div(num, denom) }
|
155
|
+
|
156
|
+
Then { result == 2 }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# @todo
|
161
|
+
describe 'GemUtils' do
|
162
|
+
|
163
|
+
describe '::data_dir' do
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '::gem_path' do
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'KernelUtils' do
|
174
|
+
|
175
|
+
describe '#get_class' do
|
176
|
+
|
177
|
+
before(:all) { TempClass = Class.new }
|
178
|
+
|
179
|
+
it 'will return the objects class' do
|
180
|
+
expect(described_class.get_class(TempClass.new)).to eql(TempClass)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'will the Class if given one' do
|
184
|
+
expect(described_class.get_class(TempClass)).to eql(TempClass)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#send_all_or_no_args' do
|
189
|
+
it %q<won't send any arguments if the arity == 0> do
|
190
|
+
str = 'test'
|
191
|
+
expect(described_class.send_all_or_no_args(str.method(:to_s), 'hmm', 'this shouldn\'t do anything')).to eql(str)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe 'ObjectUtils' do
|
197
|
+
describe '#_deep_dup' do
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
describe '#deep_dup' do
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
describe '#inspect_id' do
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '#inspect_shell' do
|
210
|
+
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|