barby 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +2 -1
- data/barby.gemspec +17 -17
- data/lib/barby/barcode/data_matrix.rb +42 -7
- data/lib/barby/version.rb +2 -2
- data/test/bookland_test.rb +10 -8
- data/test/codabar_test.rb +7 -4
- data/test/code_128_test.rb +134 -128
- data/test/code_25_iata_test.rb +2 -2
- data/test/code_25_interleaved_test.rb +24 -18
- data/test/code_25_test.rb +36 -26
- data/test/code_39_test.rb +35 -32
- data/test/code_93_test.rb +31 -28
- data/test/data_matrix_test.rb +19 -8
- data/test/ean13_test.rb +31 -28
- data/test/ean8_test.rb +10 -10
- data/test/outputter/cairo_outputter_test.rb +31 -29
- data/test/outputter/html_outputter_test.rb +1 -2
- data/test/outputter/pdfwriter_outputter_test.rb +7 -7
- data/test/outputter/png_outputter_test.rb +9 -9
- data/test/outputter/prawn_outputter_test.rb +22 -22
- data/test/outputter/rmagick_outputter_test.rb +22 -22
- data/test/outputter/svg_outputter_test.rb +32 -31
- data/test/outputter_test.rb +30 -32
- data/test/pdf_417_test.rb +23 -23
- data/test/qr_code_test.rb +42 -37
- data/test/test_helper.rb +1 -1
- data/test/upc_supplemental_test.rb +39 -39
- metadata +24 -24
data/test/code_128_test.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require 'test_helper'
|
3
2
|
require 'barby/barcode/code_128'
|
4
3
|
|
@@ -14,23 +13,25 @@ class Code128Test < Barby::TestCase
|
|
14
13
|
end
|
15
14
|
|
16
15
|
it "should have the expected stop encoding (including termination bar 11)" do
|
17
|
-
@code.send(:stop_encoding)
|
16
|
+
assert_equal '1100011101011', @code.send(:stop_encoding)
|
18
17
|
end
|
19
18
|
|
20
19
|
it "should find the right class for a character A, B or C" do
|
21
|
-
@code.send(:class_for, 'A')
|
22
|
-
@code.send(:class_for, 'B')
|
23
|
-
@code.send(:class_for, 'C')
|
20
|
+
assert_equal Code128A, @code.send(:class_for, 'A')
|
21
|
+
assert_equal Code128B, @code.send(:class_for, 'B')
|
22
|
+
assert_equal Code128C, @code.send(:class_for, 'C')
|
24
23
|
end
|
25
24
|
|
26
25
|
it "should find the right change code for a class" do
|
27
|
-
@code.send(:change_code_for_class, Code128A)
|
28
|
-
@code.send(:change_code_for_class, Code128B)
|
29
|
-
@code.send(:change_code_for_class, Code128C)
|
26
|
+
assert_equal Code128::CODEA, @code.send(:change_code_for_class, Code128A)
|
27
|
+
assert_equal Code128::CODEB, @code.send(:change_code_for_class, Code128B)
|
28
|
+
assert_equal Code128::CODEC, @code.send(:change_code_for_class, Code128C)
|
30
29
|
end
|
31
30
|
|
32
31
|
it "should not allow empty data" do
|
33
|
-
|
32
|
+
assert_raises ArgumentError do
|
33
|
+
Code128B.new("")
|
34
|
+
end
|
34
35
|
end
|
35
36
|
|
36
37
|
describe "single encoding" do
|
@@ -41,13 +42,13 @@ class Code128Test < Barby::TestCase
|
|
41
42
|
end
|
42
43
|
|
43
44
|
it "should have the same data as when initialized" do
|
44
|
-
@
|
45
|
+
assert_equal @data, @code.data
|
45
46
|
end
|
46
47
|
|
47
48
|
it "should be able to change its data" do
|
48
49
|
@code.data = '123ABC'
|
49
|
-
@code.data
|
50
|
-
@
|
50
|
+
assert_equal '123ABC', @code.data
|
51
|
+
refute_equal @data, @code.data
|
51
52
|
end
|
52
53
|
|
53
54
|
it "should not have an extra" do
|
@@ -55,15 +56,15 @@ class Code128Test < Barby::TestCase
|
|
55
56
|
end
|
56
57
|
|
57
58
|
it "should have empty extra encoding" do
|
58
|
-
@code.extra_encoding
|
59
|
+
assert_equal '', @code.extra_encoding
|
59
60
|
end
|
60
61
|
|
61
62
|
it "should have the correct checksum" do
|
62
|
-
@code.checksum
|
63
|
+
assert_equal 66, @code.checksum
|
63
64
|
end
|
64
65
|
|
65
66
|
it "should return all data for to_s" do
|
66
|
-
@code.to_s
|
67
|
+
assert_equal @data, @code.to_s
|
67
68
|
end
|
68
69
|
|
69
70
|
end
|
@@ -76,32 +77,32 @@ class Code128Test < Barby::TestCase
|
|
76
77
|
end
|
77
78
|
|
78
79
|
it "should be able to return full_data which includes the entire extra chain excluding charset change characters" do
|
79
|
-
@code.full_data
|
80
|
+
assert_equal "ABC123def4567", @code.full_data
|
80
81
|
end
|
81
82
|
|
82
83
|
it "should be able to return full_data_with_change_codes which includes the entire extra chain including charset change characters" do
|
83
|
-
@code.full_data_with_change_codes
|
84
|
+
assert_equal @data, @code.full_data_with_change_codes
|
84
85
|
end
|
85
86
|
|
86
87
|
it "should not matter if extras were added separately" do
|
87
88
|
code = Code128B.new("ABC")
|
88
89
|
code.extra = binary_encode("\3071234")
|
89
|
-
|
90
|
-
|
90
|
+
assert_equal "ABC1234", code.full_data
|
91
|
+
assert_equal binary_encode("ABC\3071234"), code.full_data_with_change_codes
|
91
92
|
code.extra.extra = binary_encode("\306abc")
|
92
|
-
|
93
|
-
|
93
|
+
assert_equal "ABC1234abc", code.full_data
|
94
|
+
assert_equal binary_encode("ABC\3071234\306abc"), code.full_data_with_change_codes
|
94
95
|
code.extra.extra.data = binary_encode("abc\305DEF")
|
95
|
-
|
96
|
-
|
97
|
-
code.extra.extra.full_data
|
98
|
-
|
99
|
-
code.extra.full_data
|
100
|
-
|
96
|
+
assert_equal "ABC1234abcDEF", code.full_data
|
97
|
+
assert_equal binary_encode("ABC\3071234\306abc\305DEF"), code.full_data_with_change_codes
|
98
|
+
assert_equal "abcDEF", code.extra.extra.full_data
|
99
|
+
assert_equal binary_encode("abc\305DEF"), code.extra.extra.full_data_with_change_codes
|
100
|
+
assert_equal "1234abcDEF", code.extra.full_data
|
101
|
+
assert_equal binary_encode("1234\306abc\305DEF"), code.extra.full_data_with_change_codes
|
101
102
|
end
|
102
103
|
|
103
104
|
it "should have a Code B extra" do
|
104
|
-
@code.extra.
|
105
|
+
assert @code.extra.is_a?(Code128B)
|
105
106
|
end
|
106
107
|
|
107
108
|
it "should have a valid extra" do
|
@@ -109,7 +110,7 @@ class Code128Test < Barby::TestCase
|
|
109
110
|
end
|
110
111
|
|
111
112
|
it "the extra should also have an extra of type C" do
|
112
|
-
@code.extra.extra.
|
113
|
+
assert @code.extra.extra.is_a?(Code128C)
|
113
114
|
end
|
114
115
|
|
115
116
|
it "the extra's extra should be valid" do
|
@@ -122,55 +123,58 @@ class Code128Test < Barby::TestCase
|
|
122
123
|
|
123
124
|
it "should split extra data from string on data assignment" do
|
124
125
|
@code.data = binary_encode("123\306abc")
|
125
|
-
@code.data
|
126
|
-
@code.extra.
|
127
|
-
@code.extra.data
|
126
|
+
assert_equal '123', @code.data
|
127
|
+
assert @code.extra.is_a?(Code128B)
|
128
|
+
assert_equal 'abc', @code.extra.data
|
128
129
|
end
|
129
130
|
|
130
131
|
it "should be be able to change its extra" do
|
131
132
|
@code.extra = binary_encode("\3071234")
|
132
|
-
@code.extra.
|
133
|
-
@code.extra.data
|
133
|
+
assert @code.extra.is_a?(Code128C)
|
134
|
+
assert_equal '1234', @code.extra.data
|
134
135
|
end
|
135
136
|
|
136
137
|
it "should split extra data from string on extra assignment" do
|
137
138
|
@code.extra = binary_encode("\306123\3074567")
|
138
|
-
@code.extra.
|
139
|
-
@code.extra.data
|
140
|
-
@code.extra.extra.
|
141
|
-
@code.extra.extra.data
|
139
|
+
assert @code.extra.is_a?(Code128B)
|
140
|
+
assert_equal '123', @code.extra.data
|
141
|
+
assert @code.extra.extra.is_a?(Code128C)
|
142
|
+
assert_equal '4567', @code.extra.extra.data
|
142
143
|
end
|
143
144
|
|
144
145
|
it "should not fail on newlines in extras" do
|
145
146
|
code = Code128B.new(binary_encode("ABC\305\n"))
|
146
|
-
|
147
|
-
code.extra.
|
148
|
-
code.extra.data
|
147
|
+
assert_equal "ABC", code.data
|
148
|
+
assert code.extra.is_a?(Code128A)
|
149
|
+
assert_equal "\n", code.extra.data
|
149
150
|
code.extra.extra = binary_encode("\305\n\n\n\n\n\nVALID")
|
150
|
-
|
151
|
+
assert_equal "\n\n\n\n\n\nVALID", code.extra.extra.data
|
151
152
|
end
|
152
153
|
|
153
154
|
it "should raise an exception when extra string doesn't start with the special code character" do
|
154
|
-
|
155
|
+
assert_raises ArgumentError do
|
156
|
+
@code.extra = '123'
|
157
|
+
end
|
155
158
|
end
|
156
159
|
|
157
160
|
it "should have the correct checksum" do
|
158
|
-
@code.checksum
|
161
|
+
assert_equal 84, @code.checksum
|
159
162
|
end
|
160
163
|
|
161
164
|
it "should have the expected encoding" do
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
165
|
+
#STARTA A B C 1 2 3
|
166
|
+
expected = '11010000100101000110001000101100010001000110100111001101100111001011001011100'+
|
167
|
+
#CODEB d e f
|
168
|
+
'10111101110100001001101011001000010110000100'+
|
169
|
+
#CODEC 45 67
|
170
|
+
'101110111101011101100010000101100'+
|
171
|
+
#CHECK=84 STOP
|
172
|
+
'100111101001100011101011'
|
173
|
+
assert_equal expected, @code.encoding
|
170
174
|
end
|
171
175
|
|
172
176
|
it "should return all data including extras, except change codes for to_s" do
|
173
|
-
@code.to_s
|
177
|
+
assert_equal "ABC123def4567", @code.to_s
|
174
178
|
end
|
175
179
|
|
176
180
|
end
|
@@ -192,23 +196,23 @@ class Code128Test < Barby::TestCase
|
|
192
196
|
end
|
193
197
|
|
194
198
|
it "should have the expected characters" do
|
195
|
-
|
199
|
+
assert_equal %w(A B C 1 2 3), @code.characters
|
196
200
|
end
|
197
201
|
|
198
202
|
it "should have the expected start encoding" do
|
199
|
-
@code.start_encoding
|
203
|
+
assert_equal '11010000100', @code.start_encoding
|
200
204
|
end
|
201
205
|
|
202
206
|
it "should have the expected data encoding" do
|
203
|
-
@code.data_encoding
|
207
|
+
assert_equal '101000110001000101100010001000110100111001101100111001011001011100', @code.data_encoding
|
204
208
|
end
|
205
209
|
|
206
210
|
it "should have the expected encoding" do
|
207
|
-
@code.encoding
|
211
|
+
assert_equal '11010000100101000110001000101100010001000110100111001101100111001011001011100100100001101100011101011', @code.encoding
|
208
212
|
end
|
209
213
|
|
210
214
|
it "should have the expected checksum encoding" do
|
211
|
-
@code.checksum_encoding
|
215
|
+
assert_equal '10010000110', @code.checksum_encoding
|
212
216
|
end
|
213
217
|
|
214
218
|
end
|
@@ -230,23 +234,23 @@ class Code128Test < Barby::TestCase
|
|
230
234
|
end
|
231
235
|
|
232
236
|
it "should have the expected characters" do
|
233
|
-
|
237
|
+
assert_equal %w(a b c 1 2 3), @code.characters
|
234
238
|
end
|
235
239
|
|
236
240
|
it "should have the expected start encoding" do
|
237
|
-
@code.start_encoding
|
241
|
+
assert_equal '11010010000', @code.start_encoding
|
238
242
|
end
|
239
243
|
|
240
244
|
it "should have the expected data encoding" do
|
241
|
-
@code.data_encoding
|
245
|
+
assert_equal '100101100001001000011010000101100100111001101100111001011001011100', @code.data_encoding
|
242
246
|
end
|
243
247
|
|
244
248
|
it "should have the expected encoding" do
|
245
|
-
@code.encoding
|
249
|
+
assert_equal '11010010000100101100001001000011010000101100100111001101100111001011001011100110111011101100011101011', @code.encoding
|
246
250
|
end
|
247
251
|
|
248
252
|
it "should have the expected checksum encoding" do
|
249
|
-
@code.checksum_encoding
|
253
|
+
assert_equal '11011101110', @code.checksum_encoding
|
250
254
|
end
|
251
255
|
|
252
256
|
end
|
@@ -270,23 +274,23 @@ class Code128Test < Barby::TestCase
|
|
270
274
|
end
|
271
275
|
|
272
276
|
it "should have the expected characters" do
|
273
|
-
|
277
|
+
assert_equal %w(12 34 56), @code.characters
|
274
278
|
end
|
275
279
|
|
276
280
|
it "should have the expected start encoding" do
|
277
|
-
@code.start_encoding
|
281
|
+
assert_equal '11010011100', @code.start_encoding
|
278
282
|
end
|
279
283
|
|
280
284
|
it "should have the expected data encoding" do
|
281
|
-
@code.data_encoding
|
285
|
+
assert_equal '101100111001000101100011100010110', @code.data_encoding
|
282
286
|
end
|
283
287
|
|
284
288
|
it "should have the expected encoding" do
|
285
|
-
@code.encoding
|
289
|
+
assert_equal '11010011100101100111001000101100011100010110100011011101100011101011', @code.encoding
|
286
290
|
end
|
287
291
|
|
288
292
|
it "should have the expected checksum encoding" do
|
289
|
-
@code.checksum_encoding
|
293
|
+
assert_equal '10001101110', @code.checksum_encoding
|
290
294
|
end
|
291
295
|
|
292
296
|
end
|
@@ -294,29 +298,29 @@ class Code128Test < Barby::TestCase
|
|
294
298
|
describe "Function characters" do
|
295
299
|
|
296
300
|
it "should retain the special symbols in the data accessor" do
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
+
assert_equal binary_encode("\301ABC\301DEF"), Code128A.new(binary_encode("\301ABC\301DEF")).data
|
302
|
+
assert_equal binary_encode("\301ABC\302DEF"), Code128B.new(binary_encode("\301ABC\302DEF")).data
|
303
|
+
assert_equal binary_encode("\301123456"), Code128C.new(binary_encode("\301123456")).data
|
304
|
+
assert_equal binary_encode("12\30134\30156"), Code128C.new(binary_encode("12\30134\30156")).data
|
301
305
|
end
|
302
306
|
|
303
307
|
it "should keep the special symbols as characters" do
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
+
assert_equal binary_encode_array(%W(\301 A B C \301 D E F)), Code128A.new(binary_encode("\301ABC\301DEF")).characters
|
309
|
+
assert_equal binary_encode_array(%W(\301 A B C \302 D E F)), Code128B.new(binary_encode("\301ABC\302DEF")).characters
|
310
|
+
assert_equal binary_encode_array(%W(\301 12 34 56)), Code128C.new(binary_encode("\301123456")).characters
|
311
|
+
assert_equal binary_encode_array(%W(12 \301 34 \301 56)), Code128C.new(binary_encode("12\30134\30156")).characters
|
308
312
|
end
|
309
313
|
|
310
314
|
it "should not allow FNC > 1 for Code C" do
|
311
|
-
|
312
|
-
|
313
|
-
|
315
|
+
assert_raises(ArgumentError){ Code128C.new("12\302") }
|
316
|
+
assert_raises(ArgumentError){ Code128C.new("\30312") }
|
317
|
+
assert_raises(ArgumentError){ Code128C.new("12\304") }
|
314
318
|
end
|
315
319
|
|
316
320
|
it "should be included in the encoding" do
|
317
321
|
a = Code128A.new(binary_encode("\301AB"))
|
318
|
-
|
319
|
-
|
322
|
+
assert_equal '111101011101010001100010001011000', a.data_encoding
|
323
|
+
assert_equal '11010000100111101011101010001100010001011000101000011001100011101011', a.encoding
|
320
324
|
end
|
321
325
|
|
322
326
|
end
|
@@ -328,7 +332,9 @@ class Code128Test < Barby::TestCase
|
|
328
332
|
#end
|
329
333
|
|
330
334
|
it "should raise an exception when given a non-existent type" do
|
331
|
-
|
335
|
+
assert_raises ArgumentError do
|
336
|
+
Code128.new('abc', 'F')
|
337
|
+
end
|
332
338
|
end
|
333
339
|
|
334
340
|
it "should not fail on frozen type" do
|
@@ -338,17 +344,17 @@ class Code128Test < Barby::TestCase
|
|
338
344
|
|
339
345
|
it "should give the right encoding for type A" do
|
340
346
|
code = Code128.new('ABC123', 'A')
|
341
|
-
|
347
|
+
assert_equal '11010000100101000110001000101100010001000110100111001101100111001011001011100100100001101100011101011', code.encoding
|
342
348
|
end
|
343
349
|
|
344
350
|
it "should give the right encoding for type B" do
|
345
351
|
code = Code128.new('abc123', 'B')
|
346
|
-
|
352
|
+
assert_equal '11010010000100101100001001000011010000101100100111001101100111001011001011100110111011101100011101011', code.encoding
|
347
353
|
end
|
348
354
|
|
349
355
|
it "should give the right encoding for type B" do
|
350
356
|
code = Code128.new('123456', 'C')
|
351
|
-
|
357
|
+
assert_equal '11010011100101100111001000101100011100010110100011011101100011101011', code.encoding
|
352
358
|
end
|
353
359
|
|
354
360
|
end
|
@@ -385,72 +391,72 @@ class Code128Test < Barby::TestCase
|
|
385
391
|
=end
|
386
392
|
it "should minimize symbol length according to GS1-128 guidelines" do
|
387
393
|
# Determine the Start Character.
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
Code128.apply_shortest_encoding_for_data("lot1")
|
394
|
+
assert_equal "#{CODEC}#{FNC1}10", Code128.apply_shortest_encoding_for_data("#{FNC1}10")
|
395
|
+
assert_equal "#{CODEC}#{FNC1}101234", Code128.apply_shortest_encoding_for_data("#{FNC1}101234")
|
396
|
+
assert_equal "#{CODEA}10\001LOT", Code128.apply_shortest_encoding_for_data("10\001LOT")
|
397
|
+
assert_equal "#{CODEB}lot1", Code128.apply_shortest_encoding_for_data("lot1")
|
392
398
|
|
393
399
|
# Switching to codeset B from codeset C
|
394
|
-
|
400
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEB}1", Code128.apply_shortest_encoding_for_data("#{FNC1}101")
|
395
401
|
# Switching to codeset A from codeset C
|
396
|
-
|
402
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEA}\001#{CODEB}a", Code128.apply_shortest_encoding_for_data("#{FNC1}10\001a")
|
397
403
|
|
398
404
|
# Switching to codeset C from codeset A
|
399
|
-
|
400
|
-
|
405
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEA}\001LOT#{CODEC}1234", Code128.apply_shortest_encoding_for_data("#{FNC1}10\001LOT1234")
|
406
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEA}\001LOT1#{CODEC}2345", Code128.apply_shortest_encoding_for_data("#{FNC1}10\001LOT12345")
|
401
407
|
|
402
408
|
# Switching to codeset C from codeset B
|
403
|
-
|
404
|
-
|
409
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEB}LOT#{CODEC}1234", Code128.apply_shortest_encoding_for_data("#{FNC1}10LOT1234")
|
410
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEB}LOT1#{CODEC}2345", Code128.apply_shortest_encoding_for_data("#{FNC1}10LOT12345")
|
405
411
|
|
406
412
|
# Switching to codeset A from codeset B
|
407
|
-
|
408
|
-
|
413
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEB}lot#{SHIFT}\001a", Code128.apply_shortest_encoding_for_data("#{FNC1}10lot\001a")
|
414
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEB}lot#{CODEA}\001\001", Code128.apply_shortest_encoding_for_data("#{FNC1}10lot\001\001")
|
409
415
|
|
410
416
|
# Switching to codeset B from codeset A
|
411
|
-
|
412
|
-
|
417
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEA}\001#{SHIFT}l\001", Code128.apply_shortest_encoding_for_data("#{FNC1}10\001l\001")
|
418
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEA}\001#{CODEB}ll", Code128.apply_shortest_encoding_for_data("#{FNC1}10\001ll")
|
413
419
|
|
414
420
|
# testing "Note 2" from the GS1 specification
|
415
|
-
|
416
|
-
|
417
|
-
|
421
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEB}LOT#{CODEC}#{FNC1}0101", Code128.apply_shortest_encoding_for_data("#{FNC1}10LOT#{FNC1}0101")
|
422
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEB}LOT#{FNC1}0#{CODEC}1010", Code128.apply_shortest_encoding_for_data("#{FNC1}10LOT#{FNC1}01010")
|
423
|
+
assert_equal "#{CODEC}#{FNC1}10#{CODEB}LOT#{CODEC}01#{FNC1}0101", Code128.apply_shortest_encoding_for_data("#{FNC1}10LOT01#{FNC1}0101")
|
418
424
|
end
|
419
425
|
|
420
426
|
it "should know how to extract CODEC segments properly from a data string" do
|
421
|
-
|
422
|
-
Code128.send(:extract_codec, "12345abc6")
|
423
|
-
Code128.send(:extract_codec, "abcdef")
|
424
|
-
Code128.send(:extract_codec, "123abcdef45678")
|
425
|
-
Code128.send(:extract_codec, "abcd12345")
|
426
|
-
|
427
|
-
Code128.send(:extract_codec, "12345")
|
428
|
-
Code128.send(:extract_codec, "12345abc")
|
429
|
-
Code128.send(:extract_codec, "abcdef1234567")
|
427
|
+
assert_equal ["1234", "abcd", "5678", "\r\n\r\n"], Code128.send(:extract_codec, "1234abcd5678\r\n\r\n")
|
428
|
+
assert_equal ["1234", "5abc6"], Code128.send(:extract_codec, "12345abc6")
|
429
|
+
assert_equal ["abcdef"], Code128.send(:extract_codec, "abcdef")
|
430
|
+
assert_equal ["123abcdef4", "5678"], Code128.send(:extract_codec, "123abcdef45678")
|
431
|
+
assert_equal ["abcd1", "2345"], Code128.send(:extract_codec, "abcd12345")
|
432
|
+
assert_equal ["abcd1", "2345", "efg"], Code128.send(:extract_codec, "abcd12345efg")
|
433
|
+
assert_equal ["1234", "5"], Code128.send(:extract_codec, "12345")
|
434
|
+
assert_equal ["1234", "5abc"], Code128.send(:extract_codec, "12345abc")
|
435
|
+
assert_equal ["abcdef1", "234567"], Code128.send(:extract_codec, "abcdef1234567")
|
430
436
|
end
|
431
437
|
|
432
438
|
it "should know how to most efficiently apply different encodings to a data string" do
|
433
|
-
Code128.apply_shortest_encoding_for_data("123456")
|
434
|
-
Code128.apply_shortest_encoding_for_data("abcdef")
|
435
|
-
Code128.apply_shortest_encoding_for_data("ABCDEF")
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
Code128.apply_shortest_encoding_for_data("123b456")
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
439
|
+
assert_equal "#{CODEC}123456", Code128.apply_shortest_encoding_for_data("123456")
|
440
|
+
assert_equal "#{CODEB}abcdef", Code128.apply_shortest_encoding_for_data("abcdef")
|
441
|
+
assert_equal "#{CODEB}ABCDEF", Code128.apply_shortest_encoding_for_data("ABCDEF")
|
442
|
+
assert_equal "#{CODEA}\n\t\r", Code128.apply_shortest_encoding_for_data("\n\t\r")
|
443
|
+
assert_equal "#{CODEC}123456#{CODEB}abcdef", Code128.apply_shortest_encoding_for_data("123456abcdef")
|
444
|
+
assert_equal "#{CODEB}abcdef#{CODEC}123456", Code128.apply_shortest_encoding_for_data("abcdef123456")
|
445
|
+
assert_equal "#{CODEC}123456#{CODEB}7", Code128.apply_shortest_encoding_for_data("1234567")
|
446
|
+
assert_equal "#{CODEB}123b456", Code128.apply_shortest_encoding_for_data("123b456")
|
447
|
+
assert_equal "#{CODEB}abc123def4#{CODEC}5678#{CODEB}gh", Code128.apply_shortest_encoding_for_data("abc123def45678gh")
|
448
|
+
assert_equal "#{CODEC}1234#{CODEA}5AB\nEE#{CODEB}asdgr12EE#{CODEA}\r\n", Code128.apply_shortest_encoding_for_data("12345AB\nEEasdgr12EE\r\n")
|
449
|
+
assert_equal "#{CODEC}123456#{CODEA}QWERTY\r\n\tAA#{CODEB}bbcc12XX3#{CODEC}4567", Code128.apply_shortest_encoding_for_data("123456QWERTY\r\n\tAAbbcc12XX34567")
|
450
|
+
|
451
|
+
assert_equal "#{CODEB}ABCdef#{SHIFT}\rGHIjkl", Code128.apply_shortest_encoding_for_data("ABCdef\rGHIjkl")
|
452
|
+
assert_equal "#{CODEA}ABC\r#{SHIFT}b\nDEF12#{CODEB}gHI#{CODEC}3456", Code128.apply_shortest_encoding_for_data("ABC\rb\nDEF12gHI3456")
|
453
|
+
assert_equal "#{CODEB}ABCdef#{SHIFT}\rGHIjkl#{SHIFT}\tMNop#{SHIFT}\nqRs", Code128.apply_shortest_encoding_for_data("ABCdef\rGHIjkl\tMNop\nqRs")
|
448
454
|
end
|
449
455
|
|
450
456
|
it "should apply automatic charset when no charset is given" do
|
451
457
|
b = Code128.new("123456QWERTY\r\n\tAAbbcc12XX34567")
|
452
|
-
|
453
|
-
|
458
|
+
assert_equal 'C', b.type
|
459
|
+
assert_equal "123456#{CODEA}QWERTY\r\n\tAA#{CODEB}bbcc12XX3#{CODEC}4567", b.full_data_with_change_codes
|
454
460
|
end
|
455
461
|
|
456
462
|
end
|
data/test/code_25_iata_test.rb
CHANGED
@@ -9,11 +9,11 @@ class Code25IATATest < Barby::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have the expected start_encoding" do
|
12
|
-
@code.start_encoding
|
12
|
+
assert_equal '1010', @code.start_encoding
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should have the expected stop_encoding" do
|
16
|
-
@code.stop_encoding
|
16
|
+
assert_equal '11101', @code.stop_encoding
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -9,27 +9,27 @@ class Code25InterleavedTest < Barby::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have the expected digit_pairs" do
|
12
|
-
|
12
|
+
assert_equal [[1,2],[3,4],[5,6],[7,0]], @code.digit_pairs
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should have the expected digit_encodings" do
|
16
|
-
|
16
|
+
assert_equal %w(111010001010111000 111011101000101000 111010001110001010 101010001110001110), @code.digit_encodings
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should have the expected start_encoding" do
|
20
|
-
@code.start_encoding
|
20
|
+
assert_equal '1010', @code.start_encoding
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should have the expected stop_encoding" do
|
24
|
-
@code.stop_encoding
|
24
|
+
assert_equal '11101', @code.stop_encoding
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should have the expected data_encoding" do
|
28
|
-
@code.data_encoding
|
28
|
+
assert_equal "111010001010111000111011101000101000111010001110001010101010001110001110", @code.data_encoding
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should have the expected encoding" do
|
32
|
-
@code.encoding
|
32
|
+
assert_equal "101011101000101011100011101110100010100011101000111000101010101000111000111011101", @code.encoding
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should be valid" do
|
@@ -40,16 +40,16 @@ class Code25InterleavedTest < Barby::TestCase
|
|
40
40
|
w, n = Code25Interleaved::WIDE, Code25Interleaved::NARROW
|
41
41
|
# 1 2 1 2 1 2 1 2 1 2 digits 1 and 2
|
42
42
|
# B S B S B S B S B S bars and spaces
|
43
|
-
@code.encoding_for_interleaved(w,n,n,w,n,n,n,n,w,w)
|
43
|
+
assert_equal '111010001010111000', @code.encoding_for_interleaved(w,n,n,w,n,n,n,n,w,w)
|
44
44
|
# 3 4 3 4 3 4 3 4 3 4 digits 3 and 4
|
45
45
|
# B S B S B S B S B S bars and spaces
|
46
|
-
@code.encoding_for_interleaved(w,n,w,n,n,w,n,n,n,w)
|
46
|
+
assert_equal '111011101000101000', @code.encoding_for_interleaved(w,n,w,n,n,w,n,n,n,w)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should return all characters in sequence for to_s" do
|
50
|
-
@code.
|
50
|
+
assert_equal @code.characters.join, @code.to_s
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
describe "with checksum" do
|
54
54
|
|
55
55
|
before do
|
@@ -59,19 +59,19 @@ class Code25InterleavedTest < Barby::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should have the expected digit_pairs_with_checksum" do
|
62
|
-
|
62
|
+
assert_equal [[1,2],[3,4],[5,6],[7,0]], @code.digit_pairs_with_checksum
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should have the expected digit_encodings_with_checksum" do
|
66
|
-
|
66
|
+
assert_equal %w(111010001010111000 111011101000101000 111010001110001010 101010001110001110), @code.digit_encodings_with_checksum
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should have the expected data_encoding_with_checksum" do
|
70
|
-
@code.data_encoding_with_checksum
|
70
|
+
assert_equal "111010001010111000111011101000101000111010001110001010101010001110001110", @code.data_encoding_with_checksum
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should have the expected encoding" do
|
74
|
-
@code.encoding
|
74
|
+
assert_equal "101011101000101011100011101110100010100011101000111000101010101000111000111011101", @code.encoding
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should be valid" do
|
@@ -79,7 +79,7 @@ class Code25InterleavedTest < Barby::TestCase
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should return all characters including checksum in sequence on to_s" do
|
82
|
-
@code.
|
82
|
+
assert_equal @code.characters_with_checksum.join, @code.to_s
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
@@ -96,9 +96,15 @@ class Code25InterleavedTest < Barby::TestCase
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should raise ArgumentError on all encoding methods" do
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
assert_raises ArgumentError do
|
100
|
+
@code.encoding
|
101
|
+
end
|
102
|
+
assert_raises ArgumentError do
|
103
|
+
@code.data_encoding
|
104
|
+
end
|
105
|
+
assert_raises ArgumentError do
|
106
|
+
@code.digit_encodings
|
107
|
+
end
|
102
108
|
end
|
103
109
|
|
104
110
|
it "should not raise ArgumentError on encoding methods that include checksum" do
|