encoder_test.go 606 B

1234567891011121314151617181920212223242526272829
  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. code, err := Encode("A40156B")
  12. if err != nil || code == nil {
  13. t.Fail()
  14. } else {
  15. testResult := "10110010010101101001010101001101010110010110101001010010101101010010011"
  16. if code.Bounds().Max.X != len(testResult) {
  17. t.Error("length missmatch")
  18. } else {
  19. for i, r := range testResult {
  20. if (code.At(i, 0) == color.Black) != (r == '1') {
  21. t.Errorf("code missmatch on position %d", i)
  22. }
  23. }
  24. }
  25. }
  26. }