numeric_test.go 783 B

1234567891011121314151617181920212223242526
  1. package qr
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. func Test_NumericEncoding(t *testing.T) {
  7. encode := Numeric.getEncoder()
  8. x, vi, err := encode("01234567", H)
  9. if x == nil || vi == nil || vi.Version != 1 || bytes.Compare(x.GetBytes(), []byte{16, 32, 12, 86, 97, 128, 236, 17, 236}) != 0 {
  10. t.Error("\"01234567\" failed to encode")
  11. }
  12. x, vi, err = encode("0123456789012345", H)
  13. if x == nil || vi == nil || vi.Version != 1 || bytes.Compare(x.GetBytes(), []byte{16, 64, 12, 86, 106, 110, 20, 234, 80}) != 0 {
  14. t.Error("\"0123456789012345\" failed to encode")
  15. }
  16. x, vi, err = encode("foo", H)
  17. if err == nil {
  18. t.Error("Numeric encoding should not be able to encode \"foo\"")
  19. }
  20. x, vi, err = encode(makeString(14297, "1"), H)
  21. if x != nil || vi != nil || err == nil {
  22. t.Fail()
  23. }
  24. }