automatic_test.go 635 B

1234567891011121314151617181920212223242526272829
  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. "no matching encoing": nil,
  11. }
  12. for str, enc := range tests {
  13. testValue, _, _ := Auto.getEncoder()(str, M)
  14. if enc != nil {
  15. correctValue, _, _ := enc(str, M)
  16. if testValue == nil || bytes.Compare(correctValue.GetBytes(), testValue.GetBytes()) != 0 {
  17. t.Errorf("wrong encoding used for '%s'", str)
  18. }
  19. } else {
  20. if testValue != nil {
  21. t.Errorf("wrong encoding used for '%s'", str)
  22. }
  23. }
  24. }
  25. }