og-corefoundation 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +14 -0
- data/LICENSE +8 -0
- data/README.md +41 -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 +42 -0
- data/lib/corefoundation/date.rb +32 -0
- data/lib/corefoundation/dictionary.rb +114 -0
- data/lib/corefoundation/extensions.rb +158 -0
- data/lib/corefoundation/null.rb +11 -0
- data/lib/corefoundation/number.rb +98 -0
- data/lib/corefoundation/string.rb +91 -0
- data/lib/corefoundation/version.rb +4 -0
- data/lib/corefoundation.rb +13 -0
- data/spec/array_spec.rb +92 -0
- data/spec/boolean_spec.rb +24 -0
- data/spec/data_spec.rb +30 -0
- data/spec/date_spec.rb +25 -0
- data/spec/dictionary_spec.rb +81 -0
- data/spec/extensions_spec.rb +127 -0
- data/spec/null_spec.rb +7 -0
- data/spec/number_spec.rb +52 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/string_spec.rb +48 -0
- metadata +137 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'extensions' do
|
5
|
+
context 'with an integer' do
|
6
|
+
it 'should return a cfnumber' do
|
7
|
+
1.to_cf.should be_a(CF::Number)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'with a float' do
|
12
|
+
it 'should return a cfnumber' do
|
13
|
+
(1.0).to_cf.should be_a(CF::Number)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe String do
|
18
|
+
uber = [195, 188, 98, 101, 114]
|
19
|
+
|
20
|
+
describe 'to_cf' do
|
21
|
+
|
22
|
+
unless defined? RUBY_ENGINE and RUBY_ENGINE == 'jruby'
|
23
|
+
context 'with data incorrectly marked as non binary' do
|
24
|
+
it 'returns nil' do
|
25
|
+
[0xff, 0xff, 0xff].pack("C*").binary!(false).to_cf.should be_nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with a non binary string' do
|
31
|
+
it 'should return a cf string' do
|
32
|
+
'123'.to_cf.should be_a(CF::String)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with a string marked as binary' do
|
37
|
+
it 'should return a cf data' do
|
38
|
+
'123'.binary!.to_cf.should be_a(CF::Data)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with a binary string' do
|
43
|
+
it 'should return a cf data' do
|
44
|
+
[0xff, 0xff, 0xff].pack("C*").to_cf.should be_a(CF::Data)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with a utf-8 string' do
|
49
|
+
it 'should return a cfstring' do
|
50
|
+
uber.pack("C*").should_not be_a(CF::String)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'binary?' do
|
56
|
+
|
57
|
+
it 'should return false on a plain ascii string' do
|
58
|
+
'123'.should_not be_binary
|
59
|
+
end
|
60
|
+
|
61
|
+
if CF::String::HAS_ENCODING
|
62
|
+
it 'should return false on valid utf data' do
|
63
|
+
"\xc3\xc9".should_not be_binary
|
64
|
+
end
|
65
|
+
else
|
66
|
+
it 'should return false on valid utf data' do
|
67
|
+
uber.pack("C*").should_not be_binary
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should return false on string forced to non binary' do
|
72
|
+
"\xc3\xc9".binary!(false).should_not be_binary
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should return true if binary! has been called' do
|
76
|
+
'123'.binary!.should be_binary
|
77
|
+
end
|
78
|
+
|
79
|
+
if CF::String::HAS_ENCODING
|
80
|
+
it 'should return true for ascii 8bit strings' do
|
81
|
+
'123'.encode(Encoding::ASCII_8BIT).should be_binary
|
82
|
+
end
|
83
|
+
else
|
84
|
+
it 'should return true for data that cannot be converted to utf8' do
|
85
|
+
"\xff\xff\xff".should be_binary
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with true' do
|
93
|
+
it 'should return CF::Boolean::TRUE' do
|
94
|
+
true.to_cf.should == CF::Boolean::TRUE
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with false' do
|
99
|
+
it 'should return CF::Boolean::FALSE' do
|
100
|
+
false.to_cf.should == CF::Boolean::FALSE
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'with a time' do
|
105
|
+
it 'should return a CFDate' do
|
106
|
+
Time.now.to_cf.should be_a(CF::Date)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with an array' do
|
111
|
+
it 'should return a cfarray containing cf objects' do
|
112
|
+
cf_array = [true, 1, 'hello'].to_cf
|
113
|
+
cf_array.should be_a(CF::Array)
|
114
|
+
cf_array[0].should == CF::Boolean::TRUE
|
115
|
+
cf_array[1].should be_a(CF::Number)
|
116
|
+
cf_array[2].should == CF::String.from_string('hello')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'with a dictionary' do
|
121
|
+
it 'should return a cfdictionary containing cf objects' do
|
122
|
+
cf_hash = {'key_1' => true, 'key_2' => false}.to_cf
|
123
|
+
cf_hash['key_1'].should == CF::Boolean::TRUE
|
124
|
+
cf_hash['key_2'].should == CF::Boolean::FALSE
|
125
|
+
end
|
126
|
+
end
|
127
|
+
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,48 @@
|
|
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 defined? RUBY_ENGINE and RUBY_ENGINE == 'jruby'
|
13
|
+
context 'with invalid data' do
|
14
|
+
it 'returns nil' do
|
15
|
+
if CF::String::HAS_ENCODING
|
16
|
+
CF::String.from_string("\xff\xff\xff".force_encoding('UTF-8')).should be_nil
|
17
|
+
else
|
18
|
+
CF::String.from_string("\xff\xff\xff").should be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#to_s' do
|
26
|
+
it 'should return a utf ruby string' do
|
27
|
+
ruby_string = CF::String.from_string('A CF string').to_s
|
28
|
+
ruby_string.should == 'A CF string'
|
29
|
+
if CF::String::HAS_ENCODING
|
30
|
+
ruby_string.encoding.should == Encoding::UTF_8
|
31
|
+
else
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'to_ruby' do
|
37
|
+
it 'should behave like to_s' do
|
38
|
+
CF::String.from_string('A CF string').to_ruby.should == 'A CF string'
|
39
|
+
if CF::String::HAS_ENCODING
|
40
|
+
CF::String.from_string('A CF string').to_ruby.encoding.should == Encoding::UTF_8
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should be comparable' do
|
46
|
+
CF::String.from_string('aaa').should <= CF::String.from_string('zzz')
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: og-corefoundation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frederick Cheung
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "<"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "<"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: 'FFI based Ruby wrappers for Core Foundation '
|
84
|
+
email: frederick.cheung@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- CHANGELOG
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- lib/corefoundation.rb
|
93
|
+
- lib/corefoundation/array.rb
|
94
|
+
- lib/corefoundation/base.rb
|
95
|
+
- lib/corefoundation/boolean.rb
|
96
|
+
- lib/corefoundation/data.rb
|
97
|
+
- lib/corefoundation/date.rb
|
98
|
+
- lib/corefoundation/dictionary.rb
|
99
|
+
- lib/corefoundation/extensions.rb
|
100
|
+
- lib/corefoundation/null.rb
|
101
|
+
- lib/corefoundation/number.rb
|
102
|
+
- lib/corefoundation/string.rb
|
103
|
+
- lib/corefoundation/version.rb
|
104
|
+
- spec/array_spec.rb
|
105
|
+
- spec/boolean_spec.rb
|
106
|
+
- spec/data_spec.rb
|
107
|
+
- spec/date_spec.rb
|
108
|
+
- spec/dictionary_spec.rb
|
109
|
+
- spec/extensions_spec.rb
|
110
|
+
- spec/null_spec.rb
|
111
|
+
- spec/number_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/string_spec.rb
|
114
|
+
homepage: http://github.com/fcheung/corefoundation
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.8.7
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubygems_version: 3.0.3
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Ruby wrapper for OS X corefoundation
|
137
|
+
test_files: []
|