midi-nibbler 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,28 +2,127 @@ require "helper"
2
2
 
3
3
  class Nibbler::TypeConversionTest < Minitest::Test
4
4
 
5
- def test_hex_chars_to_numeric_bytes
6
- nibbles = ["4", "5", "9", "3"]
7
- bytes = Nibbler::TypeConversion.hex_chars_to_numeric_bytes(nibbles)
5
+ context "TypeConversion" do
8
6
 
9
- assert_equal(["4", "5", "9", "3"], nibbles)
10
- assert_equal([0x45, 0x93], bytes)
11
- end
7
+ context ".hex_chars_to_numeric_bytes" do
12
8
 
13
- def test_hex_str_to_hex_chars
14
- str = "904050"
15
- nibbles = Nibbler::TypeConversion.send(:hex_str_to_hex_chars, str)
9
+ setup do
10
+ @nibbles = ["4", "5", "9", "3"]
11
+ @bytes = Nibbler::TypeConversion.hex_chars_to_numeric_bytes(@nibbles)
12
+ end
16
13
 
17
- assert_equal("904050", str)
18
- assert_equal(["9", "0", "4", "0", "5", "0"], nibbles)
19
- end
14
+ should "not have side effects" do
15
+ assert_equal(["4", "5", "9", "3"], @nibbles)
16
+ end
17
+
18
+ should "return correct bytes" do
19
+ assert_equal([0x45, 0x93], @bytes)
20
+ end
21
+
22
+ end
23
+
24
+ context ".hex_str_to_hex_chars" do
25
+
26
+ setup do
27
+ @str = "904050"
28
+ @nibbles = Nibbler::TypeConversion.send(:hex_str_to_hex_chars, @str)
29
+ end
30
+
31
+ should "not have side effects" do
32
+ assert_equal("904050", @str)
33
+ end
34
+
35
+ should "return correct chars" do
36
+ assert_equal(["9", "0", "4", "0", "5", "0"], @nibbles)
37
+ end
38
+
39
+ end
40
+
41
+ context ".hex_str_to_numeric_bytes" do
42
+
43
+ setup do
44
+ @str = "904050"
45
+ @bytes = Nibbler::TypeConversion.send(:hex_str_to_numeric_bytes, @str)
46
+ end
47
+
48
+ should "not have side effects" do
49
+ assert_equal("904050", @str)
50
+ end
51
+
52
+ should "return correct bytes" do
53
+ assert_equal([0x90, 0x40, 0x50], @bytes)
54
+ end
55
+
56
+ end
57
+
58
+ context ".numeric_bytes_to_numeric_nibbles" do
59
+
60
+ setup do
61
+ @bytes = [0x90, 0x40, 0x50]
62
+ @nibbles = Nibbler::TypeConversion.send(:numeric_bytes_to_numeric_nibbles, @bytes)
63
+ end
64
+
65
+ should "not have side effects" do
66
+ assert_equal([0x90, 0x40, 0x50], @bytes)
67
+ end
68
+
69
+ should "return correct nibbles" do
70
+ assert_equal([0x9, 0x0, 0x4, 0x0, 0x5, 0x0], @nibbles)
71
+ end
72
+
73
+ end
74
+
75
+ context ".hex_str_to_numeric_nibbles" do
76
+
77
+ setup do
78
+ @str = "904050"
79
+ @nibbles = Nibbler::TypeConversion.send(:hex_str_to_numeric_nibbles, @str)
80
+ end
81
+
82
+ should "not have side effects" do
83
+ assert_equal("904050", @str)
84
+ end
85
+
86
+ should "return correct nibbles" do
87
+ assert_equal([0x9, 0x0, 0x4, 0x0, 0x5, 0x0], @nibbles)
88
+ end
89
+
90
+ end
91
+
92
+ context ".numeric_byte_to_numeric_nibbles" do
93
+
94
+ setup do
95
+ @num = 0x90
96
+ @nibbles = Nibbler::TypeConversion.send(:numeric_byte_to_numeric_nibbles, @num)
97
+ end
98
+
99
+ should "not have side effects" do
100
+ assert_equal(0x90, @num)
101
+ end
102
+
103
+ should "return correct nibbles" do
104
+ assert_equal([0x9, 0x0], @nibbles)
105
+ end
106
+
107
+ end
108
+
109
+ context ".numeric_byte_to_hex_chars" do
110
+
111
+ setup do
112
+ @num = 0x90
113
+ @nibbles = Nibbler::TypeConversion.send(:numeric_byte_to_hex_chars, @num)
114
+ end
115
+
116
+ should "not have side effects" do
117
+ assert_equal(0x90, @num)
118
+ end
119
+
120
+ should "return correct chars" do
121
+ assert_equal(["9", "0"], @nibbles)
122
+ end
20
123
 
21
- def test_numeric_byte_to_hex_chars
22
- num = 0x90
23
- nibbles = Nibbler::TypeConversion.send(:numeric_byte_to_hex_chars, num)
124
+ end
24
125
 
25
- assert_equal(0x90, num)
26
- assert_equal(["9", "0"], nibbles)
27
126
  end
28
127
 
29
128
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midi-nibbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-31 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: midilib
@@ -140,24 +140,27 @@ files:
140
140
  - LICENSE
141
141
  - README.md
142
142
  - lib/nibbler.rb
143
- - lib/nibbler/hex_processor.rb
143
+ - lib/nibbler/data_processor.rb
144
+ - lib/nibbler/message_builder.rb
145
+ - lib/nibbler/message_library.rb
144
146
  - lib/nibbler/midi-message.rb
145
147
  - lib/nibbler/midilib.rb
146
148
  - lib/nibbler/parser.rb
147
149
  - lib/nibbler/session.rb
148
150
  - lib/nibbler/type_conversion.rb
151
+ - test/data_processor_test.rb
152
+ - test/functional_buffer_test.rb
153
+ - test/functional_rejected_test.rb
149
154
  - test/helper.rb
150
- - test/hex_processor_test.rb
155
+ - test/message_library_test.rb
151
156
  - test/midi_message_test.rb
152
157
  - test/midilib_test.rb
153
- - test/parser_buffer_test.rb
154
- - test/parser_rejected_test.rb
155
158
  - test/parser_test.rb
156
159
  - test/session_test.rb
157
160
  - test/type_conversion_test.rb
158
161
  homepage: http://github.com/arirusso/nibbler
159
162
  licenses:
160
- - Apache 2.0
163
+ - Apache-2.0
161
164
  metadata: {}
162
165
  post_install_message:
163
166
  rdoc_options: []
@@ -175,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
178
  version: 1.3.6
176
179
  requirements: []
177
180
  rubyforge_project: nibbler
178
- rubygems_version: 2.2.2
181
+ rubygems_version: 2.6.8
179
182
  signing_key:
180
183
  specification_version: 4
181
184
  summary: Parse MIDI Messages
@@ -1,56 +0,0 @@
1
- require "helper"
2
-
3
- class Nibbler::HexProcessorTest < Minitest::Test
4
-
5
- def test_to_nibbles_array_mixed
6
- processor = Nibbler::HexProcessor
7
- array = [0x90, "90", "9"]
8
- nibbles = processor.send(:process, array)
9
- assert_equal([0x90, "90", "9"], array)
10
- assert_equal(["9", "0", "9", "0", "9"], nibbles)
11
- end
12
-
13
- def test_to_nibbles_mixed
14
- processor = Nibbler::HexProcessor
15
- array = [0x90, "90", "9"]
16
- nibbles = processor.send(:process, *array)
17
- assert_equal([0x90, "90", "9"], array)
18
- assert_equal(["9", "0", "9", "0", "9"], nibbles)
19
- end
20
-
21
- def test_to_nibbles_numeric
22
- processor = Nibbler::HexProcessor
23
- num = 0x90
24
- nibbles = processor.send(:process, num)
25
- assert_equal(0x90, num)
26
- assert_equal(["9", "0"], nibbles)
27
- end
28
-
29
- def test_to_nibbles_string
30
- processor = Nibbler::HexProcessor
31
- str = "904050"
32
- nibbles = processor.send(:process, str)
33
- assert_equal("904050", str)
34
- assert_equal(["9", "0", "4", "0", "5", "0"], nibbles)
35
- end
36
-
37
- def test_processor_numeric
38
- processor = Nibbler::HexProcessor
39
- badnum = 560
40
- output = processor.send(:filter_numeric, badnum)
41
- assert_equal(560, badnum)
42
- assert_equal(nil, output)
43
- goodnum = 50
44
- output = processor.send(:filter_numeric, goodnum)
45
- assert_equal(50, goodnum)
46
- assert_equal(50, output)
47
- end
48
-
49
- def test_processor_string
50
- processor = Nibbler::HexProcessor
51
- str = "(0xAdjskla#(#"
52
- outp = processor.send(:filter_string, str)
53
- assert_equal("0ADA", outp)
54
- end
55
-
56
- end
@@ -1,66 +0,0 @@
1
- require "helper"
2
-
3
- class Nibbler::BufferTest < Minitest::Test
4
-
5
- def test_buffer_nibble_str
6
- nibbler = Nibbler.new
7
- nibbler.parse("9")
8
- assert_equal(["9"], nibbler.buffer)
9
- end
10
-
11
- def test_buffer_single_byte
12
- nibbler = Nibbler.new
13
- nibbler.parse(0x90)
14
- assert_equal(["9", "0"], nibbler.buffer)
15
- end
16
-
17
- def test_buffer_single_byte_str
18
- nibbler = Nibbler.new
19
- nibbler.parse("90")
20
- assert_equal(["9", "0"], nibbler.buffer)
21
- end
22
-
23
- def test_buffer_single_byte_in_array
24
- nibbler = Nibbler.new
25
- nibbler.parse([0x90])
26
- assert_equal(["9", "0"], nibbler.buffer)
27
- end
28
-
29
- def test_buffer_two_bytes
30
- nibbler = Nibbler.new
31
- nibbler.parse(0x90, 0x40)
32
- assert_equal(["9", "0", "4", "0"], nibbler.buffer)
33
- end
34
-
35
- def test_buffer_two_bytes_str
36
- nibbler = Nibbler.new
37
- nibbler.parse("90", "40")
38
- assert_equal(["9", "0", "4", "0"], nibbler.buffer)
39
- end
40
-
41
- def test_buffer_two_bytes_single_str
42
- nibbler = Nibbler.new
43
- nibbler.parse("9040")
44
- assert_equal(["9", "0", "4", "0"], nibbler.buffer)
45
- end
46
-
47
- def test_buffer_two_bytes_mixed
48
- nibbler = Nibbler.new
49
- nibbler.parse("90", 0x40)
50
- assert_equal(["9", "0", "4", "0"], nibbler.buffer)
51
- end
52
-
53
- def test_buffer_nibble_and_byte_mixed
54
- nibbler = Nibbler.new
55
- nibbler.parse("9", 0x40)
56
- assert_equal(["9", "4", "0"], nibbler.buffer)
57
- end
58
-
59
- def test_buffer_stepped
60
- nibbler = Nibbler.new
61
- nibbler.parse("9")
62
- nibbler.parse(0x40)
63
- assert_equal(["9", "4", "0"], nibbler.buffer)
64
- end
65
-
66
- end
@@ -1,60 +0,0 @@
1
- require "helper"
2
-
3
- class Nibbler::ParserRejectedTest < Minitest::Test
4
-
5
- def test_leading_chars
6
- nibbler = Nibbler.new
7
- msg = nibbler.parse("0", "9", "04", "040")
8
- assert_equal(::MIDIMessage::NoteOn, msg.class)
9
- assert_equal(["0"], nibbler.rejected)
10
- end
11
-
12
- def test_2_leading_chars
13
- nibbler = Nibbler.new
14
- msg = nibbler.parse("1", "0", "9", "04", "040")
15
- assert_equal(["1", "0"], nibbler.rejected)
16
- end
17
-
18
- def test_leading_string
19
- nibbler = Nibbler.new
20
- msg = nibbler.parse("10", "9", "04", "040")
21
- assert_equal(::MIDIMessage::NoteOn, msg.class)
22
- assert_equal(["1", "0"], nibbler.rejected)
23
- end
24
-
25
- def test_long_leading_string
26
- nibbler = Nibbler.new
27
- msg = nibbler.parse("000001000010", "9", "04", "040")
28
- assert_equal(::MIDIMessage::NoteOn, msg.class)
29
- assert_equal("000001000010".split(//), nibbler.rejected)
30
- end
31
-
32
- def test_long_leading_string_overlap
33
- nibbler = Nibbler.new
34
- msg = nibbler.parse("000001000010090", "4", "040")
35
- assert_equal(::MIDIMessage::NoteOn, msg.class)
36
- assert_equal("0000010000100".split(//), nibbler.rejected)
37
- end
38
-
39
- def test_leading_number
40
- nibbler = Nibbler.new
41
- msg = nibbler.parse(0x30, "9", "04", "040")
42
- assert_equal(::MIDIMessage::NoteOn, msg.class)
43
- assert_equal(["3", "0"], nibbler.rejected)
44
- end
45
-
46
- def test_2_leading_numbers
47
- nibbler = Nibbler.new
48
- msg = nibbler.parse(0x60, 0x30, "9", "04", "040")
49
- assert_equal(::MIDIMessage::NoteOn, msg.class)
50
- assert_equal(["6", "0", "3", "0"], nibbler.rejected)
51
- end
52
-
53
- def test_3_leading_numbers
54
- nibbler = Nibbler.new
55
- msg = nibbler.parse(0x00, 0x30, "9", "04", "040")
56
- assert_equal(::MIDIMessage::NoteOn, msg.class)
57
- assert_equal(["0", "0", "3", "0"], nibbler.rejected)
58
- end
59
-
60
- end