git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/barcode/qr/automatic_test.go (about) 1 package qr 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 func Test_AutomaticEncoding(t *testing.T) { 9 tests := map[string]encodeFn{ 10 "0123456789": Numeric.getEncoder(), 11 "ALPHA NUMERIC": AlphaNumeric.getEncoder(), 12 "unicode encoing": Unicode.getEncoder(), 13 "very long unicode encoding" + makeString(3000, "A"): nil, 14 } 15 16 for str, enc := range tests { 17 testValue, _, _ := Auto.getEncoder()(str, M) 18 if enc != nil { 19 correctValue, _, _ := enc(str, M) 20 if testValue == nil || bytes.Compare(correctValue.GetBytes(), testValue.GetBytes()) != 0 { 21 t.Errorf("wrong encoding used for '%s'", str) 22 } 23 } else { 24 if testValue != nil { 25 t.Errorf("wrong encoding used for '%s'", str) 26 } 27 } 28 29 } 30 }