lame 0.0.3 → 0.0.5
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/.github/workflows/ci.yml +47 -0
- data/.travis.yml +3 -4
- data/README.md +51 -19
- data/docs/lame-3.101.h +1357 -0
- data/lame.gemspec +2 -1
- data/lib/lame/buffer.rb +1 -1
- data/lib/lame/encoder.rb +10 -11
- data/lib/lame/encoding/interleaved_int_buffer_encoder.rb +15 -0
- data/lib/lame/encoding/long_buffer_encoder.rb +1 -1
- data/lib/lame/encoding/stereo_buffer_encoder.rb +1 -0
- data/lib/lame/ffi/functions.rb +99 -38
- data/lib/lame/ffi.rb +2 -0
- data/lib/lame/version.rb +1 -1
- data/lib/lame.rb +2 -0
- data/spec/buffer_spec.rb +8 -8
- data/spec/configuration_spec.rb +76 -76
- data/spec/decoder_spec.rb +34 -34
- data/spec/decoding/decoded_frame_spec.rb +7 -7
- data/spec/decoding/id3_tag_parser_spec.rb +3 -3
- data/spec/decoding/mp3_data_header_parser_spec.rb +21 -21
- data/spec/decoding/mpeg_audio_frame_finder_spec.rb +15 -15
- data/spec/decoding/mpeg_audio_frame_matcher_spec.rb +2 -2
- data/spec/decoding/single_frame_decoder_spec.rb +36 -35
- data/spec/decoding/stream_decoder_spec.rb +10 -10
- data/spec/delegation_spec.rb +37 -37
- data/spec/encoder_spec.rb +100 -100
- data/spec/encoding/flusher_spec.rb +16 -16
- data/spec/encoding/id3_spec.rb +38 -38
- data/spec/encoding/interleaved_buffer_encoder_spec.rb +32 -25
- data/spec/encoding/stereo_buffer_encoder_spec.rb +34 -33
- data/spec/encoding/vbr_info_spec.rb +16 -16
- data/spec/ffi/decode_flags_spec.rb +3 -2
- data/spec/ffi/encoding_spec.rb +22 -22
- data/spec/ffi/global_flags_spec.rb +166 -160
- data/spec/ffi/id3tag_spec.rb +26 -26
- data/spec/ffi/mp3_data_spec.rb +3 -3
- data/spec/integration/encoding_spec.rb +75 -3
- data/spec/integration/id3_tags_spec.rb +18 -18
- data/spec/lib/custom_matchers.rb +4 -4
- data/spec/lib/wave_file_generator.rb +9 -9
- data/spec/spec_helper.rb +14 -10
- metadata +58 -67
|
@@ -6,22 +6,22 @@ module LAME
|
|
|
6
6
|
|
|
7
7
|
subject(:parser) { Mp3DataHeaderParser.new(decode_flags, stream) }
|
|
8
8
|
|
|
9
|
-
let(:decode_flags) {
|
|
9
|
+
let(:decode_flags) { double("decode flags") }
|
|
10
10
|
let(:stream) { StringIO.new(stream_string) }
|
|
11
|
-
let(:mpeg_finder) {
|
|
11
|
+
let(:mpeg_finder) { double("mpeg_finder") }
|
|
12
12
|
|
|
13
13
|
let(:stream_string) { "a"*100 }
|
|
14
14
|
|
|
15
15
|
before do
|
|
16
|
-
LAME.
|
|
16
|
+
allow(LAME).to receive(:hip_decode1_headersB) do |_, _, _, _, _, mp3_data, _, _|
|
|
17
17
|
# fake that the header was found
|
|
18
18
|
mp3_data[:header_parsed] = 1
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "seeks the input stream until the first mpeg frame" do
|
|
23
|
-
MPEGAudioFrameFinder.
|
|
24
|
-
mpeg_finder.
|
|
23
|
+
expect(MPEGAudioFrameFinder).to receive(:new).with(stream).and_return(mpeg_finder)
|
|
24
|
+
expect(mpeg_finder).to receive(:find!)
|
|
25
25
|
|
|
26
26
|
parser.parse!
|
|
27
27
|
end
|
|
@@ -29,20 +29,20 @@ module LAME
|
|
|
29
29
|
context "decoding headers" do
|
|
30
30
|
|
|
31
31
|
before do
|
|
32
|
-
MPEGAudioFrameFinder.
|
|
32
|
+
allow(MPEGAudioFrameFinder).to receive(:new).and_return(double.as_null_object)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "reads 100 bytes from the stream" do
|
|
36
|
-
stream.
|
|
36
|
+
expect(stream).to receive(:read).with(100).and_return("a"*100)
|
|
37
37
|
parser.parse!
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "parses headers with LAME" do
|
|
41
|
-
LAME.
|
|
42
|
-
decode_flags.
|
|
43
|
-
in_buffer.get_string(0).
|
|
44
|
-
size.
|
|
45
|
-
mp3_data.
|
|
41
|
+
expect(LAME).to receive(:hip_decode1_headersB) do |decode_flags, in_buffer, size, _, _, mp3_data, _, _|
|
|
42
|
+
expect(decode_flags).to eql decode_flags
|
|
43
|
+
expect(in_buffer.get_string(0)).to eql "a"*100
|
|
44
|
+
expect(size).to eql 100
|
|
45
|
+
expect(mp3_data).to be_a(LAME::FFI::MP3Data)
|
|
46
46
|
|
|
47
47
|
# fake that the header was found
|
|
48
48
|
mp3_data[:header_parsed] = 1
|
|
@@ -57,9 +57,9 @@ module LAME
|
|
|
57
57
|
it "reads 100 bytes until a header was parsed" do
|
|
58
58
|
decode_count = 0
|
|
59
59
|
|
|
60
|
-
LAME.
|
|
60
|
+
expect(LAME).to receive(:hip_decode1_headersB).exactly(expected_reads).times
|
|
61
61
|
|
|
62
|
-
LAME.
|
|
62
|
+
allow(LAME).to receive(:hip_decode1_headersB) do |_, _, _, _, _, mp3_data, _, _|
|
|
63
63
|
decode_count += 1
|
|
64
64
|
|
|
65
65
|
# simulate parsed header after 5 reads:
|
|
@@ -71,17 +71,17 @@ module LAME
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "returns the parsed mp3 data if a header was parsed" do
|
|
74
|
-
mp3_data =
|
|
75
|
-
LAME::FFI::MP3Data.
|
|
76
|
-
LAME.
|
|
74
|
+
mp3_data = double("mp3 data", :header_parsed? => true)
|
|
75
|
+
allow(LAME::FFI::MP3Data).to receive(:new).and_return(mp3_data)
|
|
76
|
+
allow(LAME).to receive(:hip_decode1_headersB)
|
|
77
77
|
|
|
78
|
-
parser.parse
|
|
78
|
+
expect(parser.parse!).to eql mp3_data
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "raises an error if the header could not be parsed" do
|
|
82
|
-
mp3_data =
|
|
83
|
-
LAME::FFI::MP3Data.
|
|
84
|
-
LAME.
|
|
82
|
+
mp3_data = double("mp3 data", :header_parsed? => false)
|
|
83
|
+
allow(LAME::FFI::MP3Data).to receive(:new).and_return(mp3_data)
|
|
84
|
+
allow(LAME).to receive(:hip_decode1_headersB)
|
|
85
85
|
|
|
86
86
|
expect {
|
|
87
87
|
parser.parse!
|
|
@@ -10,35 +10,35 @@ module LAME
|
|
|
10
10
|
let(:stream_string) { "1234567890" }
|
|
11
11
|
|
|
12
12
|
it "tries to find the mpeg frame 4 bytes at a time until a header is found" do
|
|
13
|
-
matcher1 =
|
|
14
|
-
matcher2 =
|
|
15
|
-
matcher3 =
|
|
13
|
+
matcher1 = double("matcher", :match? => false)
|
|
14
|
+
matcher2 = double("matcher", :match? => false)
|
|
15
|
+
matcher3 = double("matcher", :match? => true)
|
|
16
16
|
|
|
17
|
-
MPEGAudioFrameMatcher.
|
|
18
|
-
MPEGAudioFrameMatcher.
|
|
19
|
-
MPEGAudioFrameMatcher.
|
|
17
|
+
expect(MPEGAudioFrameMatcher).to receive(:new).with("1234").and_return(matcher1)
|
|
18
|
+
expect(MPEGAudioFrameMatcher).to receive(:new).with("2345").and_return(matcher2)
|
|
19
|
+
expect(MPEGAudioFrameMatcher).to receive(:new).with("3456").and_return(matcher3)
|
|
20
20
|
|
|
21
21
|
finder.find!
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "seeks the stream at the position of the found frame" do
|
|
25
|
-
matcher1 =
|
|
26
|
-
matcher2 =
|
|
27
|
-
matcher3 =
|
|
25
|
+
matcher1 = double("matcher", :match? => false)
|
|
26
|
+
matcher2 = double("matcher", :match? => false)
|
|
27
|
+
matcher3 = double("matcher", :match? => true)
|
|
28
28
|
|
|
29
|
-
MPEGAudioFrameMatcher.
|
|
30
|
-
MPEGAudioFrameMatcher.
|
|
31
|
-
MPEGAudioFrameMatcher.
|
|
29
|
+
allow(MPEGAudioFrameMatcher).to receive(:new).with("1234").and_return(matcher1)
|
|
30
|
+
allow(MPEGAudioFrameMatcher).to receive(:new).with("2345").and_return(matcher2)
|
|
31
|
+
allow(MPEGAudioFrameMatcher).to receive(:new).with("3456").and_return(matcher3)
|
|
32
32
|
|
|
33
33
|
finder.find!
|
|
34
34
|
|
|
35
|
-
stream.pos.
|
|
35
|
+
expect(stream.pos).to eql 2
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "raises an error if no header could be found" do
|
|
39
|
-
matcher =
|
|
39
|
+
matcher = double("matcher", :match? => false)
|
|
40
40
|
|
|
41
|
-
MPEGAudioFrameMatcher.
|
|
41
|
+
allow(MPEGAudioFrameMatcher).to receive(:new).and_return(matcher)
|
|
42
42
|
|
|
43
43
|
expect {
|
|
44
44
|
finder.find!
|
|
@@ -41,14 +41,14 @@ module LAME
|
|
|
41
41
|
shared_examples_for "4 valid bytes" do
|
|
42
42
|
it "matches" do
|
|
43
43
|
bytes = [b1, b2, b3, b4].pack("C*")
|
|
44
|
-
MPEGAudioFrameMatcher.new(bytes).match
|
|
44
|
+
expect(MPEGAudioFrameMatcher.new(bytes).match?).to be_truthy
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
shared_examples_for "4 invalid bytes" do
|
|
49
49
|
it "does not match" do
|
|
50
50
|
bytes = [b1, b2, b3, b4].pack("C*")
|
|
51
|
-
MPEGAudioFrameMatcher.new(bytes).match
|
|
51
|
+
expect(MPEGAudioFrameMatcher.new(bytes).match?).to be_falsy
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -6,41 +6,41 @@ module LAME
|
|
|
6
6
|
|
|
7
7
|
subject(:decoder) { SingleFrameDecoder.new(decode_flags, mp3_data) }
|
|
8
8
|
|
|
9
|
-
let(:decode_flags) {
|
|
10
|
-
let(:mp3_data) {
|
|
9
|
+
let(:decode_flags) { double("decode flags") }
|
|
10
|
+
let(:mp3_data) { double("mp3 data") }
|
|
11
11
|
let(:data) { "a"*1024 }
|
|
12
12
|
|
|
13
13
|
it "always checks if there is a decoded frame in the internal buffer" do
|
|
14
14
|
# initial decoded frame
|
|
15
|
-
LAME.
|
|
16
|
-
flags.
|
|
17
|
-
in_buffer.size.
|
|
18
|
-
in_size.
|
|
19
|
-
out_left.size.
|
|
20
|
-
out_right.size.
|
|
21
|
-
mp3_data_arg.
|
|
15
|
+
expect(LAME).to receive(:hip_decode1_headers) do |flags, in_buffer, in_size, out_left, out_right, mp3_data_arg|
|
|
16
|
+
expect(flags).to eql decode_flags
|
|
17
|
+
expect(in_buffer.size).to eql 0
|
|
18
|
+
expect(in_size).to eql 0
|
|
19
|
+
expect(out_left.size).to eql 1152*2 # short is 2 bytes
|
|
20
|
+
expect(out_right.size).to eql 1152*2
|
|
21
|
+
expect(mp3_data_arg).to eql mp3_data
|
|
22
22
|
0
|
|
23
23
|
end
|
|
24
24
|
# new data
|
|
25
|
-
LAME.
|
|
25
|
+
allow(LAME).to receive(:hip_decode1_headers).and_return(0)
|
|
26
26
|
|
|
27
27
|
decoder.decode(data)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "writes the input data into the LAME decoder" do
|
|
31
31
|
# initial
|
|
32
|
-
LAME.
|
|
33
|
-
in_buffer.size.
|
|
32
|
+
expect(LAME).to receive(:hip_decode1_headers) do |_, in_buffer, _, _ , _, _|
|
|
33
|
+
expect(in_buffer.size).to eql 0
|
|
34
34
|
0
|
|
35
35
|
end
|
|
36
36
|
# new data
|
|
37
|
-
LAME.
|
|
38
|
-
flags.
|
|
39
|
-
in_buffer.size.
|
|
40
|
-
in_size.
|
|
41
|
-
out_left.size.
|
|
42
|
-
out_right.size.
|
|
43
|
-
mp3_data_arg.
|
|
37
|
+
expect(LAME).to receive(:hip_decode1_headers) do |flags, in_buffer, in_size, out_left, out_right, mp3_data_arg|
|
|
38
|
+
expect(flags).to eql decode_flags
|
|
39
|
+
expect(in_buffer.size).to eql 1024
|
|
40
|
+
expect(in_size).to eql 1024
|
|
41
|
+
expect(out_left.size).to eql 1152*2 # short is 2 bytes
|
|
42
|
+
expect(out_right.size).to eql 1152*2
|
|
43
|
+
expect(mp3_data_arg).to eql mp3_data
|
|
44
44
|
0
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -48,14 +48,14 @@ module LAME
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "decodes until no more frames were decoded" do
|
|
51
|
-
LAME.
|
|
52
|
-
LAME.
|
|
51
|
+
allow(LAME).to receive(:hip_decode1_headers).and_return(0, 1, 1, 0)
|
|
52
|
+
expect(LAME).to receive(:hip_decode1_headers).exactly(4).times
|
|
53
53
|
|
|
54
54
|
decoder.decode(data) {}
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "yields decoded frames if one is left in internal buffer" do
|
|
58
|
-
LAME.
|
|
58
|
+
allow(LAME).to receive(:hip_decode1_headers).and_return(1, 0)
|
|
59
59
|
|
|
60
60
|
expect { |block|
|
|
61
61
|
decoder.decode(data, &block)
|
|
@@ -63,7 +63,7 @@ module LAME
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "yields decoded frames for new data" do
|
|
66
|
-
LAME.
|
|
66
|
+
allow(LAME).to receive(:hip_decode1_headers).and_return(0, 1, 1, 0)
|
|
67
67
|
|
|
68
68
|
expect { |block|
|
|
69
69
|
decoder.decode(data, &block)
|
|
@@ -71,31 +71,32 @@ module LAME
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "raises an error if decoding failed" do
|
|
74
|
-
LAME.
|
|
74
|
+
allow(LAME).to receive(:hip_decode1_headers).and_return(-1)
|
|
75
75
|
|
|
76
76
|
expect {
|
|
77
77
|
decoder.decode(data)
|
|
78
78
|
}.to raise_error(DecodingError)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
LAME.stub(:hip_decode1_headers).and_return(0, 1, 1, 0)
|
|
81
|
+
it "yields until no more data is decoded" do
|
|
82
|
+
allow(LAME).to receive(:hip_decode1_headers).and_return(0, 1, 1, 0)
|
|
84
83
|
|
|
85
|
-
LAME.
|
|
84
|
+
expect(LAME).to receive(:hip_decode1_headers).exactly(4).times
|
|
86
85
|
|
|
87
|
-
expect {
|
|
88
|
-
decoder.decode(data)
|
|
86
|
+
expect { |block|
|
|
87
|
+
decoder.decode(data, &block)
|
|
89
88
|
}.to yield_control.exactly(2).times
|
|
90
89
|
end
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
it "yields if the decoder still had a decoded frame " do
|
|
92
|
+
# the initial '1' indicates a frame was still in the internal buffer (flush)
|
|
93
|
+
# the subsequent '1's are newly decoded frames
|
|
94
|
+
allow(LAME).to receive(:hip_decode1_headers).and_return(1, 0, 1, 1, 0)
|
|
94
95
|
|
|
95
|
-
LAME.
|
|
96
|
+
expect(LAME).to receive(:hip_decode1_headers).exactly(5).times
|
|
96
97
|
|
|
97
|
-
expect {
|
|
98
|
-
decoder.decode(data)
|
|
98
|
+
expect { |block|
|
|
99
|
+
decoder.decode(data, &block)
|
|
99
100
|
}.to yield_control.exactly(3).times
|
|
100
101
|
end
|
|
101
102
|
|
|
@@ -6,32 +6,32 @@ module LAME
|
|
|
6
6
|
|
|
7
7
|
subject(:decoder) { StreamDecoder.new(decode_flags, mp3_data, stream) }
|
|
8
8
|
|
|
9
|
-
let(:decode_flags) {
|
|
10
|
-
let(:mp3_data) {
|
|
9
|
+
let(:decode_flags) { double("decode flags") }
|
|
10
|
+
let(:mp3_data) { double("mp3 data") }
|
|
11
11
|
|
|
12
12
|
let(:stream) { StringIO.new(stream_string) }
|
|
13
13
|
let(:stream_string) { "a" * 1024 + "b" * 1024}
|
|
14
14
|
|
|
15
15
|
it "creates a single frame decoder" do
|
|
16
|
-
SingleFrameDecoder.
|
|
16
|
+
expect(SingleFrameDecoder).to receive(:new).with(decode_flags, mp3_data)
|
|
17
17
|
decoder
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "it passes chunks of stream into the single frame decoder" do
|
|
21
|
-
single_frame_decoder =
|
|
22
|
-
SingleFrameDecoder.
|
|
21
|
+
single_frame_decoder = double("single_frame_decoder")
|
|
22
|
+
allow(SingleFrameDecoder).to receive(:new).and_return(single_frame_decoder)
|
|
23
23
|
|
|
24
|
-
single_frame_decoder.
|
|
24
|
+
expect(single_frame_decoder).to receive(:decode).exactly(:twice)
|
|
25
25
|
|
|
26
26
|
decoder.each_decoded_frame
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "yields the decoded frame" do
|
|
30
|
-
single_frame_decoder =
|
|
31
|
-
SingleFrameDecoder.
|
|
30
|
+
single_frame_decoder = double("single frame decoder")
|
|
31
|
+
allow(SingleFrameDecoder).to receive(:new).and_return(single_frame_decoder)
|
|
32
32
|
|
|
33
|
-
single_frame_decoder.
|
|
34
|
-
single_frame_decoder.
|
|
33
|
+
allow(single_frame_decoder).to receive(:decode).with("a"*1024).and_yield(:one)
|
|
34
|
+
allow(single_frame_decoder).to receive(:decode).with("b"*1024).and_yield(:two).and_yield(:three)
|
|
35
35
|
|
|
36
36
|
expect { |block|
|
|
37
37
|
decoder.each_decoded_frame(&block)
|
data/spec/delegation_spec.rb
CHANGED
|
@@ -14,7 +14,7 @@ module LAME
|
|
|
14
14
|
|
|
15
15
|
describe Delegation do
|
|
16
16
|
|
|
17
|
-
let(:global_flags) {
|
|
17
|
+
let(:global_flags) { double("global_flags") }
|
|
18
18
|
subject { FakeEncoder.new }
|
|
19
19
|
|
|
20
20
|
before do
|
|
@@ -23,71 +23,71 @@ module LAME
|
|
|
23
23
|
|
|
24
24
|
context "#delegate_alias_to_lame" do
|
|
25
25
|
it "delegates #foo= to LAME" do
|
|
26
|
-
LAME.
|
|
27
|
-
subject.foo =
|
|
26
|
+
expect(LAME).to receive(:lame_set_bar).with(global_flags, anything)
|
|
27
|
+
subject.foo = double("delegate")
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "delegates #foo to LAME" do
|
|
31
|
-
LAME.
|
|
31
|
+
expect(LAME).to receive(:lame_get_bar).with(global_flags)
|
|
32
32
|
subject.foo
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "delegates #foo? to LAME" do
|
|
36
|
-
LAME.
|
|
36
|
+
expect(LAME).to receive(:lame_get_bar).with(global_flags)
|
|
37
37
|
subject.foo?
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
context "#delegate_to_lame" do
|
|
42
42
|
it "delegates #baz= to LAME" do
|
|
43
|
-
LAME.
|
|
44
|
-
subject.baz =
|
|
43
|
+
expect(LAME).to receive(:lame_set_baz).with(global_flags, anything)
|
|
44
|
+
subject.baz = double("delegate")
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "delegates #baz to LAME" do
|
|
48
|
-
LAME.
|
|
48
|
+
expect(LAME).to receive(:lame_get_baz).with(global_flags)
|
|
49
49
|
subject.baz
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "delegates #baz? to LAME" do
|
|
53
|
-
LAME.
|
|
53
|
+
expect(LAME).to receive(:lame_get_baz).with(global_flags)
|
|
54
54
|
subject.baz?
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
context "#delegate_id3_to_lame" do
|
|
59
59
|
it "delegates #qux= to LAME" do
|
|
60
|
-
LAME.
|
|
61
|
-
subject.qux =
|
|
60
|
+
expect(LAME).to receive(:id3tag_set_qux).with(global_flags, anything)
|
|
61
|
+
subject.qux = double("delegate")
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
context "type conversion" do
|
|
66
66
|
it "converts the input type" do
|
|
67
|
-
value =
|
|
68
|
-
Delegation::TypeConvertor.
|
|
69
|
-
LAME.
|
|
67
|
+
value = double("value")
|
|
68
|
+
expect(Delegation::TypeConvertor).to receive(:convert).with(value)
|
|
69
|
+
allow(LAME).to receive(:lame_set_baz)
|
|
70
70
|
subject.baz = value
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "passes on converted value to setter" do
|
|
74
|
-
value =
|
|
75
|
-
converted_value =
|
|
76
|
-
Delegation::TypeConvertor.
|
|
77
|
-
LAME.
|
|
74
|
+
value = double("value")
|
|
75
|
+
converted_value = double("converted_value")
|
|
76
|
+
allow(Delegation::TypeConvertor).to receive(:convert).and_return(converted_value)
|
|
77
|
+
expect(LAME).to receive(:lame_set_baz).with(global_flags, converted_value)
|
|
78
78
|
subject.baz = value
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "converts question mark style getters to return booleans" do
|
|
82
|
-
LAME.
|
|
83
|
-
Delegation::TypeConvertor.
|
|
82
|
+
allow(LAME).to receive(:lame_get_baz).and_return(0)
|
|
83
|
+
expect(Delegation::TypeConvertor).to receive(:convert_return).with(0)
|
|
84
84
|
subject.baz?
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
it "converts question mark style getters to return booleans" do
|
|
88
|
-
LAME.
|
|
89
|
-
Delegation::TypeConvertor.
|
|
90
|
-
subject.baz
|
|
88
|
+
allow(LAME).to receive(:lame_get_baz)
|
|
89
|
+
allow(Delegation::TypeConvertor).to receive(:convert_return).and_return(false)
|
|
90
|
+
expect(subject.baz?).to be_falsy
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
|
|
@@ -99,45 +99,45 @@ module LAME
|
|
|
99
99
|
|
|
100
100
|
describe "#convert" do
|
|
101
101
|
it "converts true to 1" do
|
|
102
|
-
converter.convert(true).
|
|
102
|
+
expect(converter.convert(true)).to eql 1
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
it "converts false to 0" do
|
|
106
|
-
converter.convert(false).
|
|
106
|
+
expect(converter.convert(false)).to eql 0
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
it "converts a string to a pointer with correct value" do
|
|
110
110
|
input = "some string"
|
|
111
111
|
value = converter.convert(input)
|
|
112
|
-
value.
|
|
113
|
-
value.get_string(0).
|
|
112
|
+
expect(value).to be_a(::FFI::MemoryPointer)
|
|
113
|
+
expect(value.get_string(0)).to eql input
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
it "does not convert other values" do
|
|
117
|
-
converter.convert(:foo).
|
|
118
|
-
converter.convert(1.2).
|
|
117
|
+
expect(converter.convert(:foo)).to eql :foo
|
|
118
|
+
expect(converter.convert(1.2)).to eql 1.2
|
|
119
119
|
end
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
describe "#convert_return" do
|
|
123
123
|
it "converts 1 to true" do
|
|
124
|
-
converter.convert_return(1).
|
|
124
|
+
expect(converter.convert_return(1)).to eql true
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
it "converts 0 to false" do
|
|
128
|
-
converter.convert_return(0).
|
|
128
|
+
expect(converter.convert_return(0)).to eql false
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
it "converts 0.0 to false" do
|
|
132
|
-
converter.convert_return(0.0).
|
|
132
|
+
expect(converter.convert_return(0.0)).to eql false
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
it "returns truthy to true" do
|
|
136
|
-
converter.convert_return(:truthy).
|
|
137
|
-
converter.convert_return("truthy").
|
|
138
|
-
converter.convert_return(Object).
|
|
139
|
-
converter.convert_return(Object.new).
|
|
140
|
-
converter.convert_return(4.2).
|
|
136
|
+
expect(converter.convert_return(:truthy)).to eql true
|
|
137
|
+
expect(converter.convert_return("truthy")).to eql true
|
|
138
|
+
expect(converter.convert_return(Object)).to eql true
|
|
139
|
+
expect(converter.convert_return(Object.new)).to eql true
|
|
140
|
+
expect(converter.convert_return(4.2)).to eql true
|
|
141
141
|
end
|
|
142
142
|
end
|
|
143
143
|
|