barcode/qr/automatic_test.go

31 lines
786 B
Go
Raw Normal View History

2013-12-11 13:31:11 +00:00
package qr
import (
"bytes"
"testing"
)
func Test_AutomaticEncoding(t *testing.T) {
2013-12-11 14:22:46 +00:00
tests := map[string]encodeFn{
2013-12-11 21:08:12 +00:00
"0123456789": Numeric.getEncoder(),
"ALPHA NUMERIC": AlphaNumeric.getEncoder(),
"unicode encoing": Unicode.getEncoder(),
"very long unicode encoding" + makeString(3000): nil,
2013-12-11 13:31:11 +00:00
}
for str, enc := range tests {
2013-12-11 14:22:46 +00:00
testValue, _, _ := Auto.getEncoder()(str, M)
2013-12-11 13:31:11 +00:00
if enc != nil {
2013-12-11 14:22:46 +00:00
correctValue, _, _ := enc(str, M)
2013-12-11 13:31:11 +00:00
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)
}
}
}
}