git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/barcode/codabar/encoder_test.go (about) 1 package codabar 2 3 import ( 4 "image/color" 5 "testing" 6 ) 7 8 func Test_Encode(t *testing.T) { 9 _, err := Encode("FOOBAR") 10 if err == nil { 11 t.Error("\"FOOBAR\" should not be encodable") 12 } 13 14 testEncode := func(txt, testResult string) { 15 code, err := Encode(txt) 16 if err != nil || code == nil { 17 t.Fail() 18 } else { 19 if code.Bounds().Max.X != len(testResult) { 20 t.Errorf("%v: length missmatch", txt) 21 } else { 22 for i, r := range testResult { 23 if (code.At(i, 0) == color.Black) != (r == '1') { 24 t.Errorf("%v: code missmatch on position %d", txt, i) 25 } 26 } 27 } 28 } 29 } 30 31 testEncode("A40156B", "10110010010101101001010101001101010110010110101001010010101101001001011") 32 }