File: numeric_test.go

package info (click to toggle)
golang-barcode 0.0~git20140830-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 280 kB
  • ctags: 270
  • sloc: makefile: 4
file content (26 lines) | stat: -rw-r--r-- 783 bytes parent folder | download | duplicates (4)
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
package qr

import (
	"bytes"
	"testing"
)

func Test_NumericEncoding(t *testing.T) {
	encode := Numeric.getEncoder()
	x, vi, err := encode("01234567", H)
	if x == nil || vi == nil || vi.Version != 1 || bytes.Compare(x.GetBytes(), []byte{16, 32, 12, 86, 97, 128, 236, 17, 236}) != 0 {
		t.Error("\"01234567\" failed to encode")
	}
	x, vi, err = encode("0123456789012345", H)
	if x == nil || vi == nil || vi.Version != 1 || bytes.Compare(x.GetBytes(), []byte{16, 64, 12, 86, 106, 110, 20, 234, 80}) != 0 {
		t.Error("\"0123456789012345\" failed to encode")
	}
	x, vi, err = encode("foo", H)
	if err == nil {
		t.Error("Numeric encoding should not be able to encode \"foo\"")
	}
	x, vi, err = encode(makeString(14297, "1"), H)
	if x != nil || vi != nil || err == nil {
		t.Fail()
	}
}