...
1 package qr
2
3 import (
4 "bytes"
5 "testing"
6 )
7
8 func Test_NumericEncoding(t *testing.T) {
9 encode := Numeric.getEncoder()
10 x, vi, err := encode("01234567", H)
11 if x == nil || vi == nil || vi.Version != 1 || bytes.Compare(x.GetBytes(), []byte{16, 32, 12, 86, 97, 128, 236, 17, 236}) != 0 {
12 t.Error("\"01234567\" failed to encode")
13 }
14 x, vi, err = encode("0123456789012345", H)
15 if x == nil || vi == nil || vi.Version != 1 || bytes.Compare(x.GetBytes(), []byte{16, 64, 12, 86, 106, 110, 20, 234, 80}) != 0 {
16 t.Error("\"0123456789012345\" failed to encode")
17 }
18 x, vi, err = encode("foo", H)
19 if err == nil {
20 t.Error("Numeric encoding should not be able to encode \"foo\"")
21 }
22 x, vi, err = encode(makeString(14297, "1"), H)
23 if x != nil || vi != nil || err == nil {
24 t.Fail()
25 }
26 }
27
View as plain text