numeric_test.go 679 B

12345678910111213141516171819202122
  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. }