File: automatic_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 (30 lines) | stat: -rw-r--r-- 806 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
package qr

import (
	"bytes"
	"testing"
)

func Test_AutomaticEncoding(t *testing.T) {
	tests := map[string]encodeFn{
		"0123456789":                                         Numeric.getEncoder(),
		"ALPHA NUMERIC":                                      AlphaNumeric.getEncoder(),
		"unicode encoing":                                    Unicode.getEncoder(),
		"very long unicode encoding" + makeString(3000, "A"): nil,
	}

	for str, enc := range tests {
		testValue, _, _ := Auto.getEncoder()(str, M)
		if enc != nil {
			correctValue, _, _ := enc(str, M)
			if testValue == nil || bytes.Compare(correctValue.GetBytes(), testValue.GetBytes()) != 0 {
				t.Errorf("wrong encoding used for '%s'", str)
			}
		} else {
			if testValue != nil {
				t.Errorf("wrong encoding used for '%s'", str)
			}
		}

	}
}