ffi-bit_masks 0.1.0 → 0.1.1
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 +1 -0
- data/.travis.yml +9 -0
- data/ChangeLog.md +4 -0
- data/Gemfile +7 -0
- data/Rakefile +11 -29
- data/gemspec.yml +2 -1
- data/lib/ffi/bit_masks/bit_mask.rb +3 -0
- data/lib/ffi/bit_masks/version.rb +1 -1
- data/spec/bit_mask_spec.rb +23 -23
- data/spec/bit_masks_spec.rb +3 -3
- data/spec/spec_helper.rb +0 -1
- metadata +35 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a03c17875bba4fcbc14670c4f40e02a98fc31dc5
|
4
|
+
data.tar.gz: babaf9890efd01a91ea48aef116e60434bcde567
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 390a534397b461a40828c0e8cbcd1b2c3759b31ad8d5b89ced6447c6a292a17b87d76b18a4e876df3f8424f3c63b4c544c35010ee5edd376f7ae049c9bc05dc5
|
7
|
+
data.tar.gz: 5a05ed68a37bd4d8b49abcf8e5bf40646fe0fd8fc35b6d1bca12999f66bda68ad908e56e386ce096905ee56829afa743ecad33dda50098ba6fb40c533da68b7d
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/ChangeLog.md
CHANGED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,40 +1,22 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'rubygems'
|
4
|
-
require 'rake'
|
5
|
-
|
6
3
|
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Gem::Tasks.new
|
11
|
-
rescue LoadError => e
|
12
|
-
warn e.message
|
13
|
-
warn "Run `gem install rubygems-tasks` to install Gem::Tasks."
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError => error
|
6
|
+
abort error.message
|
14
7
|
end
|
15
8
|
|
16
|
-
|
17
|
-
gem 'rspec', '~> 2.4'
|
18
|
-
require 'rspec/core/rake_task'
|
9
|
+
require 'rake'
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
11
|
+
require 'rubygems/tasks'
|
12
|
+
Gem::Tasks.new
|
13
|
+
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
RSpec::Core::RakeTask.new
|
26
16
|
|
27
17
|
task :test => :spec
|
28
18
|
task :default => :spec
|
29
19
|
|
30
|
-
|
31
|
-
|
32
|
-
require 'yard'
|
33
|
-
|
34
|
-
YARD::Rake::YardocTask.new
|
35
|
-
rescue LoadError => e
|
36
|
-
task :yard do
|
37
|
-
abort "Please run `gem install yard` to install YARD."
|
38
|
-
end
|
39
|
-
end
|
20
|
+
require 'yard'
|
21
|
+
YARD::Rake::YardocTask.new
|
40
22
|
task :doc => :yard
|
data/gemspec.yml
CHANGED
data/spec/bit_mask_spec.rb
CHANGED
@@ -10,66 +10,66 @@ describe FFI::BitMasks::BitMask do
|
|
10
10
|
subject { described_class.new(flags) }
|
11
11
|
|
12
12
|
it "should initialize the flags" do
|
13
|
-
subject.flags.
|
13
|
+
expect(subject.flags).to eq(flags)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should invert the flags into bitmasks" do
|
17
|
-
subject.bitmasks.
|
17
|
+
expect(subject.bitmasks).to eq(flags.invert)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should default type to uint" do
|
21
|
-
subject.native_type.
|
21
|
+
expect(subject.native_type).to eq(FFI::Type::UINT)
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when given a custom type" do
|
25
25
|
subject { described_class.new(flags,:ushort) }
|
26
26
|
|
27
27
|
it "should set native type" do
|
28
|
-
subject.native_type.
|
28
|
+
expect(subject.native_type).to eq(FFI::Type::USHORT)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#symbols" do
|
34
34
|
it "should return the names of the flags" do
|
35
|
-
subject.symbols.
|
35
|
+
expect(subject.symbols).to eq(flags.keys)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "#symbol_map" do
|
40
40
|
it "should return the flags" do
|
41
|
-
subject.symbol_map.
|
41
|
+
expect(subject.symbol_map).to eq(flags)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "#to_h" do
|
46
46
|
it "should return the flags" do
|
47
|
-
subject.to_h.
|
47
|
+
expect(subject.to_h).to eq(flags)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
describe "#to_hash" do
|
52
52
|
it "should return the flags" do
|
53
|
-
subject.to_hash.
|
53
|
+
expect(subject.to_hash).to eq(flags)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
describe "#[]" do
|
58
58
|
context "when given a Symbol" do
|
59
59
|
it "should lookup the bitmask" do
|
60
|
-
subject[:bar].
|
60
|
+
expect(subject[:bar]).to eq(flags[:bar])
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
context "when given an Integer" do
|
65
65
|
it "should lookup the flag" do
|
66
|
-
subject[flags[:bar]].
|
66
|
+
expect(subject[flags[:bar]]).to eq(:bar)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
context "otherwise" do
|
71
71
|
it "should return nil" do
|
72
|
-
subject[Object.new].
|
72
|
+
expect(subject[Object.new]).to be_nil
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -79,14 +79,14 @@ describe FFI::BitMasks::BitMask do
|
|
79
79
|
let(:hash) { {:foo => true, :bar => true, :baz => false} }
|
80
80
|
|
81
81
|
it "should bitwise or together the flag masks" do
|
82
|
-
subject.to_native(hash).
|
82
|
+
expect(subject.to_native(hash)).to eq(flags[:foo] | flags[:bar])
|
83
83
|
end
|
84
84
|
|
85
85
|
context "when one of the keys does not correspond to a flag" do
|
86
86
|
let(:hash) { {:foo => true, :bug => true, :baz => true} }
|
87
87
|
|
88
88
|
it "should ignore the key" do
|
89
|
-
subject.to_native(hash).
|
89
|
+
expect(subject.to_native(hash)).to eq(flags[:foo] | flags[:baz])
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -95,14 +95,14 @@ describe FFI::BitMasks::BitMask do
|
|
95
95
|
let(:int) { 0x3 }
|
96
96
|
|
97
97
|
it "should call #to_int" do
|
98
|
-
subject.to_native(int).
|
98
|
+
expect(subject.to_native(int)).to eq(0x3)
|
99
99
|
end
|
100
100
|
|
101
101
|
context "when given a bitmask that contains unknown masks" do
|
102
102
|
let(:int) { flags[:foo] | flags[:bar] | 0x8 | 0x10 }
|
103
103
|
|
104
104
|
it "should filter out the unknown masks" do
|
105
|
-
subject.to_native(int).
|
105
|
+
expect(subject.to_native(int)).to eq(
|
106
106
|
flags[:foo] | flags[:bar]
|
107
107
|
)
|
108
108
|
end
|
@@ -111,9 +111,9 @@ describe FFI::BitMasks::BitMask do
|
|
111
111
|
|
112
112
|
context "when given an Object that does not respond to #to_int" do
|
113
113
|
it "should raise an ArgumentError" do
|
114
|
-
|
114
|
+
expect {
|
115
115
|
subject.to_native(Object.new)
|
116
|
-
}.
|
116
|
+
}.to raise_error(ArgumentError)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -122,11 +122,11 @@ describe FFI::BitMasks::BitMask do
|
|
122
122
|
let(:value) { flags[:foo] | flags[:baz] }
|
123
123
|
|
124
124
|
it "should set the flags from the value" do
|
125
|
-
subject.from_native(value).
|
125
|
+
expect(subject.from_native(value)).to eq({
|
126
126
|
:foo => true,
|
127
127
|
:bar => false,
|
128
128
|
:baz => true
|
129
|
-
}
|
129
|
+
})
|
130
130
|
end
|
131
131
|
|
132
132
|
context "when one flag is a combination of other flags" do
|
@@ -134,11 +134,11 @@ describe FFI::BitMasks::BitMask do
|
|
134
134
|
let(:value) { flags[:foo] | flags[:bar] }
|
135
135
|
|
136
136
|
it "should set all flags whose bitmasks are present" do
|
137
|
-
subject.from_native(value).
|
137
|
+
expect(subject.from_native(value)).to eq({
|
138
138
|
:foo => true,
|
139
139
|
:bar => true,
|
140
140
|
:baz => true
|
141
|
-
}
|
141
|
+
})
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -146,11 +146,11 @@ describe FFI::BitMasks::BitMask do
|
|
146
146
|
let(:value) { flags[:foo] | flags[:baz] | 0x8 | 0x10 }
|
147
147
|
|
148
148
|
it "should ignore the unknown flags" do
|
149
|
-
subject.from_native(value).
|
149
|
+
expect(subject.from_native(value)).to eq({
|
150
150
|
:foo => true,
|
151
151
|
:bar => false,
|
152
152
|
:baz => true
|
153
|
-
}
|
153
|
+
})
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
data/spec/bit_masks_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'ffi/bit_masks'
|
|
3
3
|
|
4
4
|
describe FFI::BitMasks do
|
5
5
|
it "should have a VERSION constant" do
|
6
|
-
subject.const_get('VERSION').
|
6
|
+
expect(subject.const_get('VERSION')).not_to be_empty
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#bit_mask" do
|
@@ -16,13 +16,13 @@ describe FFI::BitMasks do
|
|
16
16
|
let(:flags) { {:foo => 0x1, :bar => 0x2, :baz => 0x4} }
|
17
17
|
|
18
18
|
it "should return a BitMask object" do
|
19
|
-
subject.bit_mask(:flags,flags).flags.
|
19
|
+
expect(subject.bit_mask(:flags,flags).flags).to eq(flags)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should define a typedef for the bitmask" do
|
23
23
|
bitmask = subject.bit_mask(:flags,flags)
|
24
24
|
|
25
|
-
subject.find_type(:flags).
|
25
|
+
expect(subject.find_type(:flags)).to be_kind_of(FFI::Type::Mapped)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-bit_masks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubygems-tasks
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.8'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.4'
|
69
83
|
description: FFI plugin which adds support for bitmasked types (or flags) to FFI.
|
70
84
|
email: postmodern.mod3@gmail.com
|
71
85
|
executables: []
|
@@ -75,11 +89,13 @@ extra_rdoc_files:
|
|
75
89
|
- LICENSE.txt
|
76
90
|
- README.md
|
77
91
|
files:
|
78
|
-
- .document
|
79
|
-
- .gitignore
|
80
|
-
- .rspec
|
81
|
-
- .
|
92
|
+
- ".document"
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- ".yardopts"
|
82
97
|
- ChangeLog.md
|
98
|
+
- Gemfile
|
83
99
|
- LICENSE.txt
|
84
100
|
- README.md
|
85
101
|
- Rakefile
|
@@ -101,17 +117,17 @@ require_paths:
|
|
101
117
|
- lib
|
102
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
119
|
requirements:
|
104
|
-
- -
|
120
|
+
- - ">="
|
105
121
|
- !ruby/object:Gem::Version
|
106
122
|
version: '0'
|
107
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
124
|
requirements:
|
109
|
-
- -
|
125
|
+
- - ">="
|
110
126
|
- !ruby/object:Gem::Version
|
111
127
|
version: '0'
|
112
128
|
requirements: []
|
113
129
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.4.7
|
115
131
|
signing_key:
|
116
132
|
specification_version: 4
|
117
133
|
summary: Adds support for bit-masked types in FFI.
|