(t *testing.T)
| 47 | } |
| 48 | |
| 49 | func TestEncodingEmbeddedJSON(t *testing.T) { |
| 50 | t.Run("basic-embedded-json", func(t *testing.T) { |
| 51 | ej := EmbeddedJSON([]byte(`"test"`)) |
| 52 | b := &strings.Builder{} |
| 53 | enc := BorrowEncoder(b) |
| 54 | err := enc.Encode(&ej) |
| 55 | assert.Nil(t, err, "err should be nil") |
| 56 | assert.Equal(t, b.String(), `"test"`, "b should be equal to content of EmbeddedJSON") |
| 57 | }) |
| 58 | t.Run("basic-embedded-json-marshal-api", func(t *testing.T) { |
| 59 | ej := EmbeddedJSON([]byte(`"test"`)) |
| 60 | b, err := Marshal(&ej) |
| 61 | assert.Nil(t, err, "err should be nil") |
| 62 | assert.Equal(t, string(b), `"test"`, "b should be equal to content of EmbeddedJSON") |
| 63 | }) |
| 64 | t.Run("object-embedded-json", func(t *testing.T) { |
| 65 | req := Request{ |
| 66 | id: "test", |
| 67 | method: "GET", |
| 68 | params: EmbeddedJSON([]byte(`"test"`)), |
| 69 | } |
| 70 | b := &strings.Builder{} |
| 71 | enc := BorrowEncoder(b) |
| 72 | err := enc.EncodeObject(&req) |
| 73 | assert.Nil(t, err, "err should be nil") |
| 74 | assert.Equal( |
| 75 | t, |
| 76 | b.String(), |
| 77 | `{"id":"test","method":"GET","params":"test","params3":"test","more":0}`, |
| 78 | "b should be equal to content of EmbeddedJSON", |
| 79 | ) |
| 80 | }) |
| 81 | t.Run("array-embedded-json", func(t *testing.T) { |
| 82 | ear := EmbeddedJSONArr{ |
| 83 | []byte(`"test"`), |
| 84 | []byte(`{"test":"test"}`), |
| 85 | } |
| 86 | b := &strings.Builder{} |
| 87 | enc := BorrowEncoder(b) |
| 88 | err := enc.EncodeArray(ear) |
| 89 | assert.Nil(t, err, "err should be nil") |
| 90 | assert.Equal( |
| 91 | t, |
| 92 | b.String(), |
| 93 | `["test",{"test":"test"}]`, |
| 94 | "b should be equal to content of EmbeddedJSON", |
| 95 | ) |
| 96 | }) |
| 97 | t.Run("array-embedded-json-omit-empty", func(t *testing.T) { |
| 98 | ear := EmbeddedJSONOmitEmptyArr{ |
| 99 | []byte(`"test"`), |
| 100 | []byte(``), |
| 101 | []byte(`{"test":"test"}`), |
| 102 | []byte(``), |
| 103 | []byte(`{"test":"test"}`), |
| 104 | } |
| 105 | b := &strings.Builder{} |
| 106 | enc := BorrowEncoder(b) |
nothing calls this directly
no test coverage detected
searching dependent graphs…