barby 0.6.5 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/CHANGELOG +8 -0
- data/Gemfile +5 -0
- data/README.md +21 -20
- data/Rakefile +15 -0
- data/barby.gemspec +31 -0
- data/lib/barby/barcode/codabar.rb +82 -0
- data/lib/barby/barcode.rb +3 -3
- data/lib/barby/outputter/cairo_outputter.rb +11 -3
- data/lib/barby/outputter/png_outputter.rb +43 -11
- data/lib/barby/outputter/prawn_outputter.rb +12 -9
- data/lib/barby/outputter/rmagick_outputter.rb +38 -11
- data/lib/barby/outputter/svg_outputter.rb +11 -18
- data/lib/barby/outputter.rb +1 -1
- data/lib/barby/version.rb +2 -2
- data/test/barcodes.rb +20 -0
- data/test/bookland_test.rb +54 -0
- data/test/codabar_test.rb +58 -0
- data/test/code_128_test.rb +470 -0
- data/test/code_25_iata_test.rb +19 -0
- data/test/code_25_interleaved_test.rb +116 -0
- data/test/code_25_test.rb +110 -0
- data/test/code_39_test.rb +210 -0
- data/test/code_93_test.rb +144 -0
- data/test/data_matrix_test.rb +30 -0
- data/test/ean13_test.rb +169 -0
- data/test/ean8_test.rb +100 -0
- data/test/outputter/cairo_outputter_test.rb +129 -0
- data/test/outputter/html_outputter_test.rb +68 -0
- data/test/outputter/pdfwriter_outputter_test.rb +37 -0
- data/test/outputter/png_outputter_test.rb +49 -0
- data/test/outputter/prawn_outputter_test.rb +79 -0
- data/test/outputter/rmagick_outputter_test.rb +83 -0
- data/test/outputter/svg_outputter_test.rb +89 -0
- data/test/outputter_test.rb +134 -0
- data/test/pdf_417_test.rb +45 -0
- data/test/qr_code_test.rb +78 -0
- data/test/test_helper.rb +24 -0
- data/test/upc_supplemental_test.rb +109 -0
- metadata +157 -7
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'barby/barcode/code_25_interleaved'
|
3
|
+
|
4
|
+
class Code25InterleavedTest < Barby::TestCase
|
5
|
+
|
6
|
+
before do
|
7
|
+
@data = '12345670'
|
8
|
+
@code = Code25Interleaved.new(@data)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have the expected digit_pairs" do
|
12
|
+
@code.digit_pairs.must_equal [[1,2],[3,4],[5,6],[7,0]]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have the expected digit_encodings" do
|
16
|
+
@code.digit_encodings.must_equal %w(111010001010111000 111011101000101000 111010001110001010 101010001110001110)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have the expected start_encoding" do
|
20
|
+
@code.start_encoding.must_equal '1010'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have the expected stop_encoding" do
|
24
|
+
@code.stop_encoding.must_equal '11101'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have the expected data_encoding" do
|
28
|
+
@code.data_encoding.must_equal "111010001010111000111011101000101000111010001110001010101010001110001110"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have the expected encoding" do
|
32
|
+
@code.encoding.must_equal "101011101000101011100011101110100010100011101000111000101010101000111000111011101"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be valid" do
|
36
|
+
assert @code.valid?
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return the expected encoding for parameters passed to encoding_for_interleaved" do
|
40
|
+
w, n = Code25Interleaved::WIDE, Code25Interleaved::NARROW
|
41
|
+
# 1 2 1 2 1 2 1 2 1 2 digits 1 and 2
|
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).must_equal '111010001010111000'
|
44
|
+
# 3 4 3 4 3 4 3 4 3 4 digits 3 and 4
|
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).must_equal '111011101000101000'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return all characters in sequence for to_s" do
|
50
|
+
@code.to_s.must_equal @code.characters.join
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "with checksum" do
|
54
|
+
|
55
|
+
before do
|
56
|
+
@data = '1234567'
|
57
|
+
@code = Code25Interleaved.new(@data)
|
58
|
+
@code.include_checksum = true
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should have the expected digit_pairs_with_checksum" do
|
62
|
+
@code.digit_pairs_with_checksum.must_equal [[1,2],[3,4],[5,6],[7,0]]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have the expected digit_encodings_with_checksum" do
|
66
|
+
@code.digit_encodings_with_checksum.must_equal %w(111010001010111000 111011101000101000 111010001110001010 101010001110001110)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should have the expected data_encoding_with_checksum" do
|
70
|
+
@code.data_encoding_with_checksum.must_equal "111010001010111000111011101000101000111010001110001010101010001110001110"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have the expected encoding" do
|
74
|
+
@code.encoding.must_equal "101011101000101011100011101110100010100011101000111000101010101000111000111011101"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be valid" do
|
78
|
+
assert @code.valid?
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return all characters including checksum in sequence on to_s" do
|
82
|
+
@code.to_s.must_equal @code.characters_with_checksum.join
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "with invalid number of digits" do
|
88
|
+
|
89
|
+
before do
|
90
|
+
@data = '1234567'
|
91
|
+
@code = Code25Interleaved.new(@data)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not be valid" do
|
95
|
+
refute @code.valid?
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should raise ArgumentError on all encoding methods" do
|
99
|
+
lambda{ @code.encoding }.must_raise(ArgumentError)
|
100
|
+
lambda{ @code.data_encoding }.must_raise(ArgumentError)
|
101
|
+
lambda{ @code.digit_encodings }.must_raise(ArgumentError)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not raise ArgumentError on encoding methods that include checksum" do
|
105
|
+
b = Code25Interleaved.new(@data)
|
106
|
+
b.include_checksum = true
|
107
|
+
b.encoding
|
108
|
+
@code.data_encoding_with_checksum
|
109
|
+
@code.digit_encodings_with_checksum
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'barby/barcode/code_25'
|
3
|
+
|
4
|
+
class Code25Test < Barby::TestCase
|
5
|
+
|
6
|
+
before do
|
7
|
+
@data = "1234567"
|
8
|
+
@code = Code25.new(@data)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return the same data it was given" do
|
12
|
+
@code.data.must_equal @data
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have the expected characters" do
|
16
|
+
@code.characters.must_equal %w(1 2 3 4 5 6 7)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have the expected characters_with_checksum" do
|
20
|
+
@code.characters_with_checksum.must_equal %w(1 2 3 4 5 6 7 0)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have the expected digits" do
|
24
|
+
@code.digits.must_equal [1,2,3,4,5,6,7]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have the expected digits_with_checksum" do
|
28
|
+
@code.digits_with_checksum.must_equal [1,2,3,4,5,6,7,0]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have the expected even_and_odd_digits" do
|
32
|
+
@code.even_and_odd_digits.must_equal [[7,5,3,1], [6,4,2]]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have the expected start_encoding" do
|
36
|
+
@code.start_encoding.must_equal '1110111010'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have the expected stop_encoding" do
|
40
|
+
@code.stop_encoding.must_equal '111010111'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have a default narrow_width of 1" do
|
44
|
+
@code.narrow_width.must_equal 1
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have a default wide_width equal to narrow_width * 3" do
|
48
|
+
@code.wide_width.must_equal @code.narrow_width * 3
|
49
|
+
@code.narrow_width = 2
|
50
|
+
@code.wide_width.must_equal 6
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have a default space_width equal to narrow_width" do
|
54
|
+
@code.space_width.must_equal @code.narrow_width
|
55
|
+
@code.narrow_width = 23
|
56
|
+
@code.space_width.must_equal 23
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have the expected digit_encodings" do
|
60
|
+
@code.digit_encodings.must_equal %w(11101010101110 10111010101110 11101110101010 10101110101110 11101011101010 10111011101010 10101011101110)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should have the expected digit_encodings_with_checksum" do
|
64
|
+
@code.digit_encodings_with_checksum.must_equal %w(11101010101110 10111010101110 11101110101010 10101110101110 11101011101010 10111011101010 10101011101110 10101110111010)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have the expected data_encoding" do
|
68
|
+
@code.data_encoding.must_equal "11101010101110101110101011101110111010101010101110101110111010111010101011101110101010101011101110"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have the expected checksum" do
|
72
|
+
@code.checksum.must_equal 0
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should have the expected checksum_encoding" do
|
76
|
+
@code.checksum_encoding.must_equal '10101110111010'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should have the expected encoding" do
|
80
|
+
@code.encoding.must_equal "111011101011101010101110101110101011101110111010101010101110101110111010111010101011101110101010101011101110111010111"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should be valid" do
|
84
|
+
assert @code.valid?
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not be valid" do
|
88
|
+
@code.data = 'abc'
|
89
|
+
refute @code.valid?
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should raise on encoding methods that include data encoding if not valid" do
|
93
|
+
@code.data = 'abc'
|
94
|
+
lambda{ @code.encoding }.must_raise ArgumentError
|
95
|
+
lambda{ @code.data_encoding }.must_raise ArgumentError
|
96
|
+
lambda{ @code.data_encoding_with_checksum }.must_raise ArgumentError
|
97
|
+
lambda{ @code.digit_encodings }.must_raise ArgumentError
|
98
|
+
lambda{ @code.digit_encodings_with_checksum }.must_raise ArgumentError
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return all characters in sequence on to_s" do
|
102
|
+
@code.to_s.must_equal @code.characters.join
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should include checksum in to_s when include_checksum is true" do
|
106
|
+
@code.include_checksum = true
|
107
|
+
@code.to_s.must_equal @code.characters_with_checksum.join
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
#encoding: ASCII
|
2
|
+
require 'test_helper'
|
3
|
+
require 'barby/barcode/code_39'
|
4
|
+
|
5
|
+
class Code39Test < Barby::TestCase
|
6
|
+
|
7
|
+
before do
|
8
|
+
@data = 'TEST8052'
|
9
|
+
@code = Code39.new(@data)
|
10
|
+
@code.spacing = 3
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should yield self on initialize" do
|
14
|
+
c1 = nil
|
15
|
+
c2 = Code39.new('TEST'){|c| c1 = c }
|
16
|
+
c1.must_equal c2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have the expected data" do
|
20
|
+
@code.data.must_equal @data
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have the expected characters" do
|
24
|
+
@code.characters.must_equal @data.split(//)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have the expected start_encoding" do
|
28
|
+
@code.start_encoding.must_equal '100101101101'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have the expected stop_encoding" do
|
32
|
+
@code.stop_encoding.must_equal '100101101101'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have the expected spacing_encoding" do
|
36
|
+
@code.spacing_encoding.must_equal '000'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have the expected encoded characters" do
|
40
|
+
@code.encoded_characters.must_equal %w(101011011001 110101100101 101101011001 101011011001 110100101101 101001101101 110100110101 101100101011)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have the expected data_encoding" do
|
44
|
+
@code.data_encoding.must_equal '101011011001000110101100101000101101011001000101011011001000110100101101000101001101101000110100110101000101100101011'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have the expected encoding" do
|
48
|
+
@code.encoding.must_equal '100101101101000101011011001000110101100101000101101011001000101011011001000110100101101000101001101101000110100110101000101100101011000100101101101'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be valid" do
|
52
|
+
assert @code.valid?
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not be valid" do
|
56
|
+
@code.data = "123\200456"
|
57
|
+
refute @code.valid?
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should raise an exception when data is not valid on initialization" do
|
61
|
+
lambda{ Code39.new('abc') }.must_raise(ArgumentError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return all characters in sequence without checksum on to_s" do
|
65
|
+
@code.to_s.must_equal @data
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "Checksumming" do
|
69
|
+
|
70
|
+
before do
|
71
|
+
@code = Code39.new('CODE39')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have the expected checksum" do
|
75
|
+
@code.checksum.must_equal 32
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should have the expected checksum_character" do
|
79
|
+
@code.checksum_character.must_equal 'W'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should have the expected checksum_encoding" do
|
83
|
+
@code.checksum_encoding.must_equal '110011010101'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should have the expected characters_with_checksum" do
|
87
|
+
@code.characters_with_checksum.must_equal %w(C O D E 3 9 W)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should have the expected encoded_characters_with_checksum" do
|
91
|
+
@code.encoded_characters_with_checksum.must_equal %w(110110100101 110101101001 101011001011 110101100101 110110010101 101100101101 110011010101)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have the expected data_encoding_with_checksum" do
|
95
|
+
@code.data_encoding_with_checksum.must_equal "110110100101011010110100101010110010110110101100101011011001010101011001011010110011010101"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should have the expected encoding_with_checksum" do
|
99
|
+
@code.encoding_with_checksum.must_equal "10010110110101101101001010110101101001010101100101101101011001010110110010101010110010110101100110101010100101101101"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should return the encoding with checksum when include_checksum == true" do
|
103
|
+
@code.include_checksum = true
|
104
|
+
@code.encoding.must_equal "10010110110101101101001010110101101001010101100101101101011001010110110010101010110010110101100110101010100101101101"
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "Normal encoding" do
|
110
|
+
|
111
|
+
before do
|
112
|
+
@data = 'ABC$%'
|
113
|
+
@code = Code39.new(@data)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should have the expected characters" do
|
117
|
+
@code.characters.must_equal %w(A B C $ %)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should have the expected encoded_characters" do
|
121
|
+
@code.encoded_characters.must_equal %w(110101001011 101101001011 110110100101 100100100101 101001001001)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should have the expected data_encoding" do
|
125
|
+
@code.data_encoding.must_equal '1101010010110101101001011011011010010101001001001010101001001001'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should not be valid" do
|
129
|
+
@code.data = 'abc'
|
130
|
+
refute @code.valid?
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "Extended encoding" do
|
136
|
+
|
137
|
+
before do
|
138
|
+
@data = '<abc>'
|
139
|
+
@code = Code39.new(@data, true)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return true on extended?" do
|
143
|
+
assert @code.extended?
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should have the expected characters" do
|
147
|
+
@code.characters.must_equal %w(% G + A + B + C % I)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should have the expected encoded_characters" do
|
151
|
+
@code.encoded_characters.must_equal %w(101001001001 101010011011 100101001001 110101001011 100101001001 101101001011 100101001001 110110100101 101001001001 101101001101)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should have the expected data_encoding" do
|
155
|
+
@code.data_encoding.must_equal '101001001001010101001101101001010010010110101001011010010100100101011010010110100101001001011011010010101010010010010101101001101'
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should have the expected encoding" do
|
159
|
+
@code.encoding.must_equal '10010110110101010010010010101010011011010010100100101101010010110100101001001'+
|
160
|
+
'010110100101101001010010010110110100101010100100100101011010011010100101101101'
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should take a second parameter on initialize indicating it is extended" do
|
164
|
+
assert Code39.new('abc', true).extended?
|
165
|
+
refute Code39.new('ABC', false).extended?
|
166
|
+
refute Code39.new('ABC').extended?
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should be valid" do
|
170
|
+
assert @code.valid?
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should not be valid" do
|
174
|
+
@code.data = "abc\200123"
|
175
|
+
refute @code.valid?
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should return all characters in sequence without checksum on to_s" do
|
179
|
+
@code.to_s.must_equal @data
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "Variable widths" do
|
185
|
+
|
186
|
+
before do
|
187
|
+
@data = 'ABC$%'
|
188
|
+
@code = Code39.new(@data)
|
189
|
+
@code.narrow_width = 2
|
190
|
+
@code.wide_width = 5
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should have the expected encoded_characters" do
|
194
|
+
@code.encoded_characters.must_equal %w(111110011001100000110011111 110011111001100000110011111 111110011111001100000110011 110000011000001100000110011 110011000001100000110000011)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should have the expected data_encoding" do
|
198
|
+
# A SB SC S$ S%
|
199
|
+
@code.data_encoding.must_equal '1111100110011000001100111110110011111001100000110011111011111001111100110000011001101100000110000011000001100110110011000001100000110000011'
|
200
|
+
|
201
|
+
@code.spacing = 3
|
202
|
+
# A S B S C S $ S %
|
203
|
+
@code.data_encoding.must_equal '111110011001100000110011111000110011111001100000110011111000111110011111001100000110011000110000011000001100000110011000110011000001100000110000011'
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
|
@@ -0,0 +1,144 @@
|
|
1
|
+
#encoding: ASCII
|
2
|
+
require 'test_helper'
|
3
|
+
require 'barby/barcode/code_93'
|
4
|
+
|
5
|
+
class Code93Test < Barby::TestCase
|
6
|
+
|
7
|
+
before do
|
8
|
+
@data = 'TEST93'
|
9
|
+
@code = Code93.new(@data)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return the same data we put in" do
|
13
|
+
@code.data.must_equal @data
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have the expected characters" do
|
17
|
+
@code.characters.must_equal @data.split(//)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have the expected start_encoding" do
|
21
|
+
@code.start_encoding.must_equal '101011110'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have the expected stop_encoding" do
|
25
|
+
# STOP TERM
|
26
|
+
@code.stop_encoding.must_equal '1010111101'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have the expected encoded characters" do
|
30
|
+
# T E S T 9 3
|
31
|
+
@code.encoded_characters.must_equal %w(110100110 110010010 110101100 110100110 100001010 101000010)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have the expected data_encoding" do
|
35
|
+
# T E S T 9 3
|
36
|
+
@code.data_encoding.must_equal "110100110110010010110101100110100110100001010101000010"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have the expected data_encoding_with_checksums" do
|
40
|
+
# T E S T 9 3 + (C) 6 (K)
|
41
|
+
@code.data_encoding_with_checksums.must_equal "110100110110010010110101100110100110100001010101000010101110110100100010"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have the expected encoding" do
|
45
|
+
# START T E S T 9 3 + (C) 6 (K) STOP TERM
|
46
|
+
@code.encoding.must_equal "1010111101101001101100100101101011001101001101000010101010000101011101101001000101010111101"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should have the expected checksum_values" do
|
50
|
+
@code.checksum_values.must_equal [29, 14, 28, 29, 9, 3].reverse #!
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have the expected c_checksum" do
|
54
|
+
@code.c_checksum.must_equal 41 #calculate this first!
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have the expected c_checksum_character" do
|
58
|
+
@code.c_checksum_character.must_equal '+'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should have the expected c_checksum_encoding" do
|
62
|
+
@code.c_checksum_encoding.must_equal '101110110'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have the expected checksum_values_with_c_checksum" do
|
66
|
+
@code.checksum_values_with_c_checksum.must_equal [29, 14, 28, 29, 9, 3, 41].reverse #!
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should have the expected k_checksum" do
|
70
|
+
@code.k_checksum.must_equal 6 #calculate this first!
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have the expected k_checksum_character" do
|
74
|
+
@code.k_checksum_character.must_equal '6'
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have the expected k_checksum_encoding" do
|
78
|
+
@code.k_checksum_encoding.must_equal '100100010'
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have the expected checksums" do
|
82
|
+
@code.checksums.must_equal [41, 6]
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should have the expected checksum_characters" do
|
86
|
+
@code.checksum_characters.must_equal ['+', '6']
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have the expected checksum_encodings" do
|
90
|
+
@code.checksum_encodings.must_equal %w(101110110 100100010)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have the expected checksum_encoding" do
|
94
|
+
@code.checksum_encoding.must_equal '101110110100100010'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be valid" do
|
98
|
+
assert @code.valid?
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should not be valid when not in extended mode" do
|
102
|
+
@code.data = 'not extended'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return data with no checksums on to_s" do
|
106
|
+
@code.to_s.must_equal 'TEST93'
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "Extended mode" do
|
110
|
+
|
111
|
+
before do
|
112
|
+
@data = "Extended!"
|
113
|
+
@code = Code93.new(@data)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be extended" do
|
117
|
+
assert @code.extended?
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should convert extended characters to special shift characters" do
|
121
|
+
@code.characters.must_equal ["E", "\304", "X", "\304", "T", "\304", "E", "\304", "N", "\304", "D", "\304", "E", "\304", "D", "\303", "A"]
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should have the expected data_encoding" do
|
125
|
+
@code.data_encoding.must_equal '110010010100110010101100110100110010110100110100110010110010010'+
|
126
|
+
'100110010101000110100110010110010100100110010110010010100110010110010100111010110110101000'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should have the expected c_checksum" do
|
130
|
+
@code.c_checksum.must_equal 9
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should have the expected k_checksum" do
|
134
|
+
@code.k_checksum.must_equal 46
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should return the original data on to_s with no checksums" do
|
138
|
+
@code.to_s.must_equal 'Extended!'
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'barby/barcode/data_matrix'
|
3
|
+
|
4
|
+
class DataMatrixTest < Barby::TestCase
|
5
|
+
|
6
|
+
before do
|
7
|
+
@data = "humbaba"
|
8
|
+
@code = Barby::DataMatrix.new(@data)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have the expected encoding" do
|
12
|
+
@code.encoding.must_equal ["1010101010101010", "1011111000011111", "1110111000010100",
|
13
|
+
"1110100100000111", "1101111010101000", "1101111011110011",
|
14
|
+
"1111111100000100", "1100101111110001", "1001000010001010",
|
15
|
+
"1101010110111011", "1000000100011110", "1001010010000011",
|
16
|
+
"1101100111011110", "1110111010000101", "1110010110001010",
|
17
|
+
"1111111111111111"]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return data on to_s" do
|
21
|
+
@code.to_s.must_equal @data
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be able to change its data" do
|
25
|
+
prev_encoding = @code.encoding
|
26
|
+
@code.data = "after eight"
|
27
|
+
@code.encoding.wont_equal prev_encoding
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|