corefoundation 0.1.4 → 0.3.13
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 +7 -0
- data/lib/corefoundation/array.rb +4 -5
- data/lib/corefoundation/base.rb +40 -143
- data/lib/corefoundation/data.rb +1 -1
- data/lib/corefoundation/date.rb +1 -1
- data/lib/corefoundation/dictionary.rb +3 -4
- data/lib/corefoundation/exceptions.rb +16 -0
- data/lib/corefoundation/memory.rb +47 -0
- data/lib/corefoundation/number.rb +2 -2
- data/lib/corefoundation/preferences.rb +134 -0
- data/lib/corefoundation/range.rb +10 -0
- data/lib/corefoundation/refinements.rb +121 -0
- data/lib/corefoundation/register.rb +24 -0
- data/lib/corefoundation/string.rb +6 -15
- data/lib/corefoundation/version.rb +1 -1
- data/lib/corefoundation.rb +38 -11
- metadata +41 -58
- data/README.md +0 -39
- data/lib/corefoundation/extensions.rb +0 -81
- data/spec/array_spec.rb +0 -92
- data/spec/boolean_spec.rb +0 -24
- data/spec/data_spec.rb +0 -26
- data/spec/date_spec.rb +0 -25
- data/spec/dictionary_spec.rb +0 -81
- data/spec/extensions_spec.rb +0 -63
- data/spec/null_spec.rb +0 -7
- data/spec/number_spec.rb +0 -52
- data/spec/spec_helper.rb +0 -10
- data/spec/string_spec.rb +0 -39
data/spec/dictionary_spec.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe CF::Dictionary do
|
5
|
-
describe 'mutable' do
|
6
|
-
it 'should return a cf dictionary' do
|
7
|
-
CF::Dictionary.mutable.should be_a(CF::Dictionary)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'hash access' do
|
12
|
-
subject {CF::Dictionary.mutable}
|
13
|
-
|
14
|
-
it 'should return nil when the key does not exist' do
|
15
|
-
subject['doesnotexist'].should be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should raise when trying to store a non cf value' do
|
19
|
-
expect {subject[CF::String.from_string('key')]=1}.to raise_error(TypeError)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should raise when trying to store a non cf key' do
|
23
|
-
expect {subject[1]=CF::String.from_string('value')}.to raise_error(TypeError)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should allow storing and retrieving a cf key pair' do
|
27
|
-
subject[CF::String.from_string('key')] = CF::String.from_string('value')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should instantiate the correct type on retrieval' do
|
31
|
-
subject[CF::String.from_string('key')] = CF::String.from_string('value')
|
32
|
-
subject[CF::String.from_string('key')].should be_a(CF::String)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should coerce string keys' do
|
36
|
-
subject['key'] = CF::String.from_string('value')
|
37
|
-
subject['key'].to_s.should == 'value'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'merge!' do
|
42
|
-
subject { CF::Dictionary.mutable.tap {|dict| dict['1'] = CF::Boolean::TRUE; dict['2'] = CF::Boolean::FALSE}}
|
43
|
-
it 'should merge the argument into the receiver' do
|
44
|
-
argument = {'1' => false, 'foo' => 'bar'}.to_cf
|
45
|
-
subject.merge! argument
|
46
|
-
subject.to_ruby.should == {'1' => false, '2' => false, 'foo' => 'bar'}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe 'length' do
|
51
|
-
it 'should return the count of items in the dictionary' do
|
52
|
-
dict = CF::Dictionary.mutable
|
53
|
-
dict['one'] = CF::Boolean::TRUE
|
54
|
-
dict['two'] = CF::Boolean::TRUE
|
55
|
-
|
56
|
-
dict.length.should == 2
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'enumeration' do
|
61
|
-
subject { CF::Dictionary.mutable.tap {|dict| dict['1'] = CF::Boolean::TRUE; dict['2'] = CF::Boolean::FALSE}}
|
62
|
-
|
63
|
-
it 'should yield each key value pair in the dictionary' do
|
64
|
-
hash = {}
|
65
|
-
subject.each do |k,v|
|
66
|
-
hash[k] = v
|
67
|
-
end
|
68
|
-
hash.should == {CF::String.from_string('1') => CF::Boolean::TRUE,
|
69
|
-
CF::String.from_string('2') => CF::Boolean::FALSE}
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'to_ruby' do
|
74
|
-
subject { CF::Dictionary.mutable.tap {|dict| dict['1'] = CF::Boolean::TRUE; dict['2'] = CF::Array.immutable([CF::Boolean::FALSE])}}
|
75
|
-
|
76
|
-
it 'should return a ruby hash where keys and values have been converted to ruby types' do
|
77
|
-
subject.to_ruby.should == {'1' => true, '2' => [false]}
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
data/spec/extensions_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'extensions' do
|
4
|
-
context 'with an integer' do
|
5
|
-
it 'should return a cfnumber' do
|
6
|
-
1.to_cf.should be_a(CF::Number)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'with a float' do
|
11
|
-
it 'should return a cfnumber' do
|
12
|
-
(1.0).to_cf.should be_a(CF::Number)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'with a 8bit string' do
|
17
|
-
it 'should return a cf data' do
|
18
|
-
'123'.encode(Encoding::ASCII_8BIT).to_cf.should be_a(CF::Data)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with an asciistring' do
|
23
|
-
it 'should return a cf string' do
|
24
|
-
'123'.to_cf.should be_a(CF::String)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'with true' do
|
29
|
-
it 'should return CF::Boolean::TRUE' do
|
30
|
-
true.to_cf.should == CF::Boolean::TRUE
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'with false' do
|
35
|
-
it 'should return CF::Boolean::FALSE' do
|
36
|
-
false.to_cf.should == CF::Boolean::FALSE
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'with a time' do
|
41
|
-
it 'should return a CFDate' do
|
42
|
-
Time.now.to_cf.should be_a(CF::Date)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'with an array' do
|
47
|
-
it 'should return a cfarray containing cf objects' do
|
48
|
-
cf_array = [true, 1, 'hello'].to_cf
|
49
|
-
cf_array.should be_a(CF::Array)
|
50
|
-
cf_array[0].should == CF::Boolean::TRUE
|
51
|
-
cf_array[1].should be_a(CF::Number)
|
52
|
-
cf_array[2].should == CF::String.from_string('hello')
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'with a dictionary' do
|
57
|
-
it 'should return a cfdictionary containing cf objects' do
|
58
|
-
cf_hash = {'key_1' => true, 'key_2' => false}.to_cf
|
59
|
-
cf_hash['key_1'].should == CF::Boolean::TRUE
|
60
|
-
cf_hash['key_2'].should == CF::Boolean::FALSE
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/spec/null_spec.rb
DELETED
data/spec/number_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CF::Number do
|
4
|
-
|
5
|
-
describe 'to_ruby' do
|
6
|
-
context 'with a number created from a float' do
|
7
|
-
subject {CF::Number.from_f('3.1415')}
|
8
|
-
it 'should return a float' do
|
9
|
-
subject.to_ruby.should be_within(0.0000001).of(3.14150)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
context 'with a number created from a int' do
|
13
|
-
subject {CF::Number.from_i('31415')}
|
14
|
-
it 'should return a int' do
|
15
|
-
subject.to_ruby.should == 31415
|
16
|
-
subject.to_ruby.should be_a(Integer)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should be comparable' do
|
22
|
-
(CF::Number.from_f('3.1415') <= CF::Number.from_i(4)).should be_true
|
23
|
-
end
|
24
|
-
|
25
|
-
describe('from_f') do
|
26
|
-
it 'should create a cf number from a float' do
|
27
|
-
CF::Number.from_f('3.1415').should be_a(CF::Number)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe('from_i') do
|
32
|
-
it 'should create a cf number from a 32 bit sized int' do
|
33
|
-
CF::Number.from_i(2**30).should be_a(CF::Number)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should create a cf number from a 64 bit sized int' do
|
37
|
-
CF::Number.from_i(2**60).should be_a(CF::Number)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe('to_i') do
|
42
|
-
it 'should return a ruby integer representing the cfnumber' do
|
43
|
-
CF::Number.from_i(2**60).to_i.should == 2**60
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe('to_f') do
|
48
|
-
it 'should return a ruby float representing the cfnumber' do
|
49
|
-
CF::Number.from_f(3.1415).to_f.should be_within(0.0000001).of(3.14150)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/spec/string_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CF::String do
|
4
|
-
|
5
|
-
describe 'from_string' do
|
6
|
-
it 'should return a CF::String' do
|
7
|
-
CF::String.from_string('A CF string').should be_a(CF::String)
|
8
|
-
end
|
9
|
-
|
10
|
-
# The intent is to force feed CF::String with an invalid utf-8 string
|
11
|
-
# but jruby doesn't seem to allow this to be constructed
|
12
|
-
unless RUBY_ENGINE == 'jruby'
|
13
|
-
context 'with invalid data' do
|
14
|
-
it 'returns nil' do
|
15
|
-
CF::String.from_string("\xff\xff\xff".force_encoding('UTF-8')).should be_nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#to_s' do
|
22
|
-
it 'should return a utf ruby string' do
|
23
|
-
ruby_string = CF::String.from_string('A CF string').to_s
|
24
|
-
ruby_string.should == 'A CF string'
|
25
|
-
ruby_string.encoding.should == Encoding::UTF_8
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'to_ruby' do
|
30
|
-
it 'should behave like to_s' do
|
31
|
-
CF::String.from_string('A CF string').to_ruby.should == 'A CF string'
|
32
|
-
CF::String.from_string('A CF string').to_ruby.encoding.should == Encoding::UTF_8
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should be comparable' do
|
37
|
-
CF::String.from_string('aaa').should <= CF::String.from_string('zzz')
|
38
|
-
end
|
39
|
-
end
|