From 5ae56e6a778d84ac42935b9ba580df5748bbb593 Mon Sep 17 00:00:00 2001 From: boombuler Date: Sat, 21 Dec 2013 01:17:58 +0100 Subject: [PATCH] added codabar test --- codabar/encoder_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 codabar/encoder_test.go diff --git a/codabar/encoder_test.go b/codabar/encoder_test.go new file mode 100644 index 0000000..24c2aaa --- /dev/null +++ b/codabar/encoder_test.go @@ -0,0 +1,29 @@ +package codabar + +import ( + "image/color" + "testing" +) + +func Test_Encode(t *testing.T) { + _, err := Encode("FOOBAR") + if err == nil { + t.Error("\"FOOBAR\" should not be encodable") + } + + code, err := Encode("A40156B") + if err != nil || code == nil { + t.Fail() + } else { + testResult := "10110010010101101001010101001101010110010110101001010010101101010010011" + if code.Bounds().Max.X != len(testResult) { + t.Error("length missmatch") + } else { + for i, r := range testResult { + if (code.At(i, 0) == color.Black) != (r == '1') { + t.Errorf("code missmatch on position %d", i) + } + } + } + } +}