corefoundation 0.1.4
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.
- data/LICENSE +8 -0
- data/README.md +39 -0
- data/lib/corefoundation.rb +11 -0
- data/lib/corefoundation/array.rb +123 -0
- data/lib/corefoundation/base.rb +197 -0
- data/lib/corefoundation/boolean.rb +25 -0
- data/lib/corefoundation/data.rb +38 -0
- data/lib/corefoundation/date.rb +32 -0
- data/lib/corefoundation/dictionary.rb +114 -0
- data/lib/corefoundation/extensions.rb +81 -0
- data/lib/corefoundation/null.rb +11 -0
- data/lib/corefoundation/number.rb +98 -0
- data/lib/corefoundation/string.rb +77 -0
- data/lib/corefoundation/version.rb +4 -0
- data/spec/array_spec.rb +92 -0
- data/spec/boolean_spec.rb +24 -0
- data/spec/data_spec.rb +26 -0
- data/spec/date_spec.rb +25 -0
- data/spec/dictionary_spec.rb +81 -0
- data/spec/extensions_spec.rb +63 -0
- data/spec/null_spec.rb +7 -0
- data/spec/number_spec.rb +52 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/string_spec.rb +39 -0
- metadata +150 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CF do
|
4
|
+
|
5
|
+
|
6
|
+
describe CF::Boolean do
|
7
|
+
describe 'value' do
|
8
|
+
it 'should return true for CF::Boolean::TRUE' do
|
9
|
+
CF::Boolean::TRUE.value.should == true
|
10
|
+
end
|
11
|
+
it 'should return false for CF::Boolean::FALSE' do
|
12
|
+
CF::Boolean::FALSE.value.should == false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'to_ruby' do
|
17
|
+
it 'should behave like value' do
|
18
|
+
CF::Boolean::FALSE.to_ruby.should == false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/data_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe CF::Data do
|
5
|
+
subject {CF::Data.from_string('A CF string')}
|
6
|
+
describe '#to_s' do
|
7
|
+
it 'should return a binary ruby string' do
|
8
|
+
ruby_string = subject.to_s
|
9
|
+
ruby_string.should == 'A CF string'
|
10
|
+
ruby_string.encoding.should == Encoding::ASCII_8BIT
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#size' do
|
15
|
+
it 'should return the size in bytes of the cfdata' do
|
16
|
+
subject.size.should == 11
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'to_ruby' do
|
21
|
+
it 'should behave like to_s' do
|
22
|
+
subject.to_ruby.should == 'A CF string'
|
23
|
+
subject.to_ruby.encoding.should == Encoding::ASCII_8BIT
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/date_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CF::Date do
|
4
|
+
describe('from_time') do
|
5
|
+
it 'should create a cf date from a time' do
|
6
|
+
CF::Date.from_time(Time.now).should be_a(CF::Date)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe('to_time') do
|
11
|
+
it 'should return a time' do
|
12
|
+
t = CF::Date.from_time(Time.now).to_time
|
13
|
+
t.should be_a(Time)
|
14
|
+
t.should be_within(0.01).of(Time.now)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'to_ruby' do
|
19
|
+
it 'should behave like to_time' do
|
20
|
+
t = CF::Date.from_time(Time.now).to_ruby
|
21
|
+
t.should be_a(Time)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,81 @@
|
|
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
|
@@ -0,0 +1,63 @@
|
|
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
ADDED
data/spec/number_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
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
ADDED
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: corefoundation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Frederick Cheung
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.10'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.10'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: yard
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: redcarpet
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! 'FFI based Ruby wrappers for Core Foundation '
|
95
|
+
email: frederick.cheung@gmail.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- lib/corefoundation/array.rb
|
101
|
+
- lib/corefoundation/base.rb
|
102
|
+
- lib/corefoundation/boolean.rb
|
103
|
+
- lib/corefoundation/data.rb
|
104
|
+
- lib/corefoundation/date.rb
|
105
|
+
- lib/corefoundation/dictionary.rb
|
106
|
+
- lib/corefoundation/extensions.rb
|
107
|
+
- lib/corefoundation/null.rb
|
108
|
+
- lib/corefoundation/number.rb
|
109
|
+
- lib/corefoundation/string.rb
|
110
|
+
- lib/corefoundation/version.rb
|
111
|
+
- lib/corefoundation.rb
|
112
|
+
- spec/array_spec.rb
|
113
|
+
- spec/boolean_spec.rb
|
114
|
+
- spec/data_spec.rb
|
115
|
+
- spec/date_spec.rb
|
116
|
+
- spec/dictionary_spec.rb
|
117
|
+
- spec/extensions_spec.rb
|
118
|
+
- spec/null_spec.rb
|
119
|
+
- spec/number_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/string_spec.rb
|
122
|
+
- README.md
|
123
|
+
- LICENSE
|
124
|
+
homepage: http://github.com/fcheung/corefoundation
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 1.9.2
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 1.8.24
|
146
|
+
signing_key:
|
147
|
+
specification_version: 3
|
148
|
+
summary: Ruby wrapper for OS X's corefoundation
|
149
|
+
test_files: []
|
150
|
+
has_rdoc:
|