File: alphanumeric_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 (44 lines) | stat: -rw-r--r-- 978 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package qr

import (
	"bytes"
	"testing"
)

func makeString(length int, content string) string {
	res := ""

	for i := 0; i < length; i++ {
		res += content
	}

	return res
}

func Test_AlphaNumericEncoding(t *testing.T) {
	encode := AlphaNumeric.getEncoder()

	x, vi, err := encode("HELLO WORLD", M)

	if x == nil || vi == nil || vi.Version != 1 || bytes.Compare(x.GetBytes(), []byte{32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, 17, 236, 17, 236, 17}) != 0 {
		t.Errorf("\"HELLO WORLD\" failed to encode: %s", err)
	}

	x, vi, err = encode(makeString(4296, "A"), L)
	if x == nil || vi == nil || err != nil {
		t.Fail()
	}
	x, vi, err = encode(makeString(4297, "A"), L)
	if x != nil || vi != nil || err == nil {
		t.Fail()
	}
	x, vi, err = encode("ABc", L)
	if x != nil || vi != nil || err == nil {
		t.Fail()
	}
	x, vi, err = encode("hello world", M)

	if x != nil || vi != nil || err == nil {
		t.Error("\"hello world\" should not be encodable in alphanumeric mode")
	}
}