Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
56
backend/internal/translator/common/bytes_test.go
Normal file
56
backend/internal/translator/common/bytes_test.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package common
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestJoinRawArray(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
items [][]byte
|
||||
want string
|
||||
}{
|
||||
{name: "empty", want: "[]"},
|
||||
{name: "single", items: [][]byte{[]byte(`{"id":1}`)}, want: `[{"id":1}]`},
|
||||
{name: "multiple", items: [][]byte{[]byte(`{"id":1}`), []byte(`{"id":2}`)}, want: `[{"id":1},{"id":2}]`},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := string(JoinRawArray(test.items)); got != test.want {
|
||||
t.Fatalf("JoinRawArray() = %s, want %s", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRawArrayItems(t *testing.T) {
|
||||
if items := NewRawArrayItems(0); items != nil {
|
||||
t.Fatalf("NewRawArrayItems(0) = %#v, want nil", items)
|
||||
}
|
||||
if items := NewRawArrayItems(3); len(items) != 0 || cap(items) != 3 {
|
||||
t.Fatalf("NewRawArrayItems(3) len = %d, cap = %d; want len 0, cap 3", len(items), cap(items))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetRawArrayItems(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
data string
|
||||
path string
|
||||
items [][]byte
|
||||
want string
|
||||
}{
|
||||
{name: "empty", data: `{"items":[]}`, path: "items", want: `{"items":[]}`},
|
||||
{name: "single nested", data: `{"before":1,"request":{"contents":[]},"after":2}`, path: "request.contents", items: [][]byte{[]byte(`{"id":1}`)}, want: `{"before":1,"request":{"contents":[{"id":1}]},"after":2}`},
|
||||
{name: "single fallback", data: `{"items":[{"old":1},{"old":2}]}`, path: "items", items: [][]byte{[]byte(`{"id":1}`)}, want: `{"items":[{"id":1}]}`},
|
||||
{name: "multiple", data: `{"items":[]}`, path: "items", items: [][]byte{[]byte(`{"id":1}`), []byte(`{"id":2}`)}, want: `{"items":[{"id":1},{"id":2}]}`},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := SetRawArrayItems([]byte(test.data), test.path, test.items)
|
||||
if string(got) != test.want {
|
||||
t.Fatalf("SetRawArrayItems() = %s, want %s", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue