Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadJSONStructurePagesAndResolvesPointers(t *testing.T) {
|
|
source := `{"name":"city","nested":{"a":1,"b":[true,false]},"items":[{"id":1},{"id":2},{"id":3}]}`
|
|
root, err := readJSONStructure(json.NewDecoder(strings.NewReader(source)), "", 0, 2)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if root.Kind != "object" || len(root.Items) != 2 || !root.Truncated || root.NextOffset != 2 {
|
|
t.Fatalf("root=%#v", root)
|
|
}
|
|
if root.Items[1].Path != "/nested" || !root.Items[1].Expandable {
|
|
t.Fatalf("nested=%#v", root.Items[1])
|
|
}
|
|
nested, err := readJSONStructure(json.NewDecoder(strings.NewReader(source)), "/nested/b", 0, 10)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if nested.Kind != "array" || len(nested.Items) != 2 || nested.Items[0].Preview != "true" {
|
|
t.Fatalf("nested=%#v", nested)
|
|
}
|
|
items, err := readJSONStructure(json.NewDecoder(strings.NewReader(source)), "/items", 1, 1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(items.Items) != 1 || items.Items[0].Key != "1" || items.Items[0].Path != "/items/1" || !items.Truncated {
|
|
t.Fatalf("items=%#v", items)
|
|
}
|
|
}
|
|
|
|
func TestReadJSONStructureEscapesPointerKeys(t *testing.T) {
|
|
source := `{"a/b":{"~key":"ok"}}`
|
|
page, err := readJSONStructure(json.NewDecoder(strings.NewReader(source)), "/a~1b", 0, 10)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(page.Items) != 1 || page.Items[0].Path != "/a~1b/~0key" {
|
|
t.Fatalf("page=%#v", page)
|
|
}
|
|
}
|