File: encoder_test.go

package info (click to toggle)
golang-barcode 0.0~git20140830-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 288 kB
  • sloc: makefile: 3
file content (32 lines) | stat: -rw-r--r-- 691 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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")
	}

	testEncode := func(txt, testResult string) {
		code, err := Encode(txt)
		if err != nil || code == nil {
			t.Fail()
		} else {
			if code.Bounds().Max.X != len(testResult) {
				t.Errorf("%v: length missmatch", txt)
			} else {
				for i, r := range testResult {
					if (code.At(i, 0) == color.Black) != (r == '1') {
						t.Errorf("%v: code missmatch on position %d", txt, i)
					}
				}
			}
		}
	}

	testEncode("A40156B", "10110010010101101001010101001101010110010110101001010010101101010010011")
}