(t *testing.T)
| 42 | } |
| 43 | |
| 44 | func TestNormalizeSet(t *testing.T) { |
| 45 | t.Run("duplicate-element", func(t *testing.T) { |
| 46 | b := scode.NewBuilder() |
| 47 | b.BeginContainer() |
| 48 | b.Append([]byte("dup")) |
| 49 | b.Append([]byte("dup")) |
| 50 | b.TransformContainer(super.NormalizeSet) |
| 51 | b.EndContainer() |
| 52 | set := scode.Append(nil, []byte("dup")) |
| 53 | expected := scode.Append(nil, set) |
| 54 | require.Exactly(t, expected, b.Bytes()) |
| 55 | }) |
| 56 | t.Run("unsorted-elements", func(t *testing.T) { |
| 57 | b := scode.NewBuilder() |
| 58 | b.BeginContainer() |
| 59 | b.Append([]byte("z")) |
| 60 | b.Append([]byte("a")) |
| 61 | b.TransformContainer(super.NormalizeSet) |
| 62 | b.EndContainer() |
| 63 | set := scode.Append(nil, []byte("a")) |
| 64 | set = scode.Append(set, []byte("z")) |
| 65 | expected := scode.Append(nil, set) |
| 66 | require.Exactly(t, expected, b.Bytes()) |
| 67 | }) |
| 68 | t.Run("unsorted-and-duplicate-elements", func(t *testing.T) { |
| 69 | b := scode.NewBuilder() |
| 70 | big := bytes.Repeat([]byte("x"), 256) |
| 71 | small := []byte("small") |
| 72 | b.Append(big) |
| 73 | b.BeginContainer() |
| 74 | // Append duplicate elements in reverse of set-normal order. |
| 75 | for range 3 { |
| 76 | b.Append(big) |
| 77 | b.Append(big) |
| 78 | b.Append(small) |
| 79 | b.Append(small) |
| 80 | b.Append(nil) |
| 81 | b.Append(nil) |
| 82 | } |
| 83 | b.TransformContainer(super.NormalizeSet) |
| 84 | b.EndContainer() |
| 85 | set := scode.Append(nil, nil) |
| 86 | set = scode.Append(set, small) |
| 87 | set = scode.Append(set, big) |
| 88 | expected := scode.Append(nil, big) |
| 89 | expected = scode.Append(expected, set) |
| 90 | require.Exactly(t, expected, b.Bytes()) |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | func TestDuplicates(t *testing.T) { |
| 95 | ctx := super.NewContext() |
nothing calls this directly
no test coverage detected