encoder_test.go 691 B

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