...
1 package code39
2
3 import (
4 "image/color"
5 "testing"
6 )
7
8 func doTest(t *testing.T, addCS, fullASCII bool, data, testResult string) {
9 code, err := Encode(data, addCS, fullASCII)
10 if err != nil {
11 t.Error(err)
12 }
13 if len(testResult) != code.Bounds().Max.X {
14 t.Errorf("Invalid code size. Expected %d got %d", len(testResult), code.Bounds().Max.X)
15 }
16 for i, r := range testResult {
17 if (code.At(i, 0) == color.Black) != (r == '1') {
18 t.Errorf("Failed at position %d", i)
19 }
20 }
21 }
22
23 func Test_Encode(t *testing.T) {
24 doTest(t, false, false, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
25 "1001011011010110101001011010110100101101101101001010101011001011011010110010101"+
26 "011011001010101010011011011010100110101011010011010101011001101011010101001101011010"+
27 "100110110110101001010101101001101101011010010101101101001010101011001101101010110010"+
28 "101101011001010101101100101100101010110100110101011011001101010101001011010110110010"+
29 "110101010011011010101010011011010110100101011010110010101101101100101010101001101011"+
30 "011010011010101011001101010101001011011011010010110101011001011010100101101101")
31 }
32
View as plain text