You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB

  1. package _generated
  2. import (
  3. "bytes"
  4. "reflect"
  5. "testing"
  6. "github.com/tinylib/msgp/msgp"
  7. )
  8. func TestRuneEncodeDecode(t *testing.T) {
  9. tt := &TestType{}
  10. r := 'r'
  11. rp := &r
  12. tt.Rune = r
  13. tt.RunePtr = &r
  14. tt.RunePtrPtr = &rp
  15. tt.RuneSlice = []rune{'a', 'b', '😳'}
  16. var buf bytes.Buffer
  17. wrt := msgp.NewWriter(&buf)
  18. if err := tt.EncodeMsg(wrt); err != nil {
  19. t.Errorf("%v", err)
  20. }
  21. wrt.Flush()
  22. var out TestType
  23. rdr := msgp.NewReader(&buf)
  24. if err := (&out).DecodeMsg(rdr); err != nil {
  25. t.Errorf("%v", err)
  26. }
  27. if r != out.Rune {
  28. t.Errorf("rune mismatch: expected %c found %c", r, out.Rune)
  29. }
  30. if r != *out.RunePtr {
  31. t.Errorf("rune ptr mismatch: expected %c found %c", r, *out.RunePtr)
  32. }
  33. if r != **out.RunePtrPtr {
  34. t.Errorf("rune ptr ptr mismatch: expected %c found %c", r, **out.RunePtrPtr)
  35. }
  36. if !reflect.DeepEqual(tt.RuneSlice, out.RuneSlice) {
  37. t.Errorf("rune slice mismatch")
  38. }
  39. }
  40. func TestRuneMarshalUnmarshal(t *testing.T) {
  41. tt := &TestType{}
  42. r := 'r'
  43. rp := &r
  44. tt.Rune = r
  45. tt.RunePtr = &r
  46. tt.RunePtrPtr = &rp
  47. tt.RuneSlice = []rune{'a', 'b', '😳'}
  48. bts, err := tt.MarshalMsg(nil)
  49. if err != nil {
  50. t.Errorf("%v", err)
  51. }
  52. var out TestType
  53. if _, err := (&out).UnmarshalMsg(bts); err != nil {
  54. t.Errorf("%v", err)
  55. }
  56. if r != out.Rune {
  57. t.Errorf("rune mismatch: expected %c found %c", r, out.Rune)
  58. }
  59. if r != *out.RunePtr {
  60. t.Errorf("rune ptr mismatch: expected %c found %c", r, *out.RunePtr)
  61. }
  62. if r != **out.RunePtrPtr {
  63. t.Errorf("rune ptr ptr mismatch: expected %c found %c", r, **out.RunePtrPtr)
  64. }
  65. if !reflect.DeepEqual(tt.RuneSlice, out.RuneSlice) {
  66. t.Errorf("rune slice mismatch")
  67. }
  68. }