data_encoder_test.go 964 B

123456789101112131415161718192021222324252627282930313233343536
  1. package pdf417
  2. import "testing"
  3. func TestEncode(t *testing.T) {
  4. encoder := newDataEncoder()
  5. // When starting with text, the first code word does not need to be the switch
  6. if result, err := encoder.Encode("ABC123"); err != nil {
  7. t.Error(err)
  8. } else {
  9. compareIntSlice(t, []int{1, 89, 902, 1, 223}, result)
  10. }
  11. // When starting with numbers, we do need to switchresult := encoder.Encode("ABC123")
  12. if result, err := encoder.Encode("123ABC"); err != nil {
  13. t.Error(err)
  14. } else {
  15. compareIntSlice(t, []int{902, 1, 223, 900, 1, 89}, result)
  16. }
  17. /*
  18. // Also with bytes
  19. if result, err := encoder.Encode("\x0B"); err != nil {
  20. t.Error(err)
  21. } else {
  22. compareIntSlice(t, []int{901, 11}, result)
  23. }
  24. // Alternate bytes switch code when number of bytes is divisble by 6
  25. if result, err := encoder.Encode("\x0B\x0B\x0B\x0B\x0B\x0B"); err != nil {
  26. t.Error(err)
  27. } else {
  28. compareIntSlice(t, []int{924, 18, 455, 694, 754, 291}, result)
  29. }
  30. */
  31. }