automatic_test.go 806 B

123456789101112131415161718192021222324252627282930
  1. package qr
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. func Test_AutomaticEncoding(t *testing.T) {
  7. tests := map[string]encodeFn{
  8. "0123456789": Numeric.getEncoder(),
  9. "ALPHA NUMERIC": AlphaNumeric.getEncoder(),
  10. "unicode encoing": Unicode.getEncoder(),
  11. "very long unicode encoding" + makeString(3000, "A"): nil,
  12. }
  13. for str, enc := range tests {
  14. testValue, _, _ := Auto.getEncoder()(str, M)
  15. if enc != nil {
  16. correctValue, _, _ := enc(str, M)
  17. if testValue == nil || bytes.Compare(correctValue.GetBytes(), testValue.GetBytes()) != 0 {
  18. t.Errorf("wrong encoding used for '%s'", str)
  19. }
  20. } else {
  21. if testValue != nil {
  22. t.Errorf("wrong encoding used for '%s'", str)
  23. }
  24. }
  25. }
  26. }