(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestBuilder(t *testing.T) { |
| 11 | empty := []byte{} |
| 12 | null := []byte(nil) |
| 13 | v1, v2 := []byte("1"), []byte("22") |
| 14 | t.Run("AppendContainer", func(t *testing.T) { |
| 15 | b := NewBuilder() |
| 16 | b.Append(empty) |
| 17 | expected := Append(nil, empty) |
| 18 | require.Exactly(t, expected, b.Bytes()) |
| 19 | b.Append(null) |
| 20 | expected = Append(expected, null) |
| 21 | require.Exactly(t, expected, b.Bytes()) |
| 22 | b.Append(v1) |
| 23 | b.Append(v2) |
| 24 | expected = Append(expected, v1) |
| 25 | expected = Append(expected, v2) |
| 26 | require.Exactly(t, expected, b.Bytes()) |
| 27 | }) |
| 28 | t.Run("AppendPrimitive", func(t *testing.T) { |
| 29 | b := NewBuilder() |
| 30 | b.Append(empty) |
| 31 | expected := Append(nil, empty) |
| 32 | require.Exactly(t, expected, b.Bytes()) |
| 33 | b.Append(null) |
| 34 | expected = Append(expected, null) |
| 35 | require.Exactly(t, expected, b.Bytes()) |
| 36 | b.Append(v1) |
| 37 | b.Append(v2) |
| 38 | expected = Append(expected, v1) |
| 39 | expected = Append(expected, v2) |
| 40 | require.Exactly(t, expected, b.Bytes()) |
| 41 | }) |
| 42 | t.Run("BeginContainer/empty", func(t *testing.T) { |
| 43 | b := NewBuilder() |
| 44 | b.BeginContainer() |
| 45 | b.EndContainer() |
| 46 | expected := Append(nil, empty) |
| 47 | require.Exactly(t, expected, b.Bytes()) |
| 48 | }) |
| 49 | t.Run("BeginContainer/nonempty", func(t *testing.T) { |
| 50 | b := NewBuilder() |
| 51 | big := bytes.Repeat([]byte("x"), 256) |
| 52 | v1, v2, v3, v4 := []byte("1"), []byte("22"), []byte("333"), []byte("4444") |
| 53 | b.Append(v1) |
| 54 | b.BeginContainer() // Start of outer container. |
| 55 | b.Append(v2) |
| 56 | b.BeginContainer() // Start of inner container. |
| 57 | b.Append(big) |
| 58 | b.EndContainer() // End of inner container. |
| 59 | b.Append(v3) |
| 60 | b.EndContainer() // End of outer container. |
| 61 | b.Append(v4) |
| 62 | innerContainer := Append(nil, big) |
| 63 | outerContainer := Append(nil, v2) |
| 64 | outerContainer = Append(outerContainer, innerContainer) |
| 65 | outerContainer = Append(outerContainer, v3) |
| 66 | expected := Append(nil, v1) |
| 67 | expected = Append(expected, outerContainer) |
nothing calls this directly
no test coverage detected