package ckconfig import ( "reflect" "testing" configkit "go.maximumdirect.net/configkit" ) func TestDecodeJSONPointerPreservesSemanticTokens(t *testing.T) { tests := []struct { pointer string want []string }{ {pointer: "", want: nil}, {pointer: "/", want: []string{""}}, {pointer: "/parent/child", want: []string{"parent", "child"}}, {pointer: "/0/../a.b/50%", want: []string{"0", "..", "a.b", "50%"}}, {pointer: "/a~1b/c~0d", want: []string{"a/b", "c~d"}}, {pointer: "/~01", want: []string{"~1"}}, {pointer: "/café", want: []string{"café"}}, } for _, test := range tests { path, err := configkit.ParsePath(test.pointer) if err != nil { t.Fatal(err) } got := decodeJSONPointer(path) if !reflect.DeepEqual(got, test.want) { t.Errorf("decode %q = %#v, want %#v", test.pointer, got, test.want) } } } func TestPlaceReportValue(t *testing.T) { var root any = map[string]any{} var err error root, err = placeReportValue(root, []string{"a/b", "~1"}, false) if err != nil { t.Fatal(err) } root, err = placeReportValue(root, []string{""}, nil) if err != nil { t.Fatal(err) } want := map[string]any{"a/b": map[string]any{"~1": false}, "": nil} if !reflect.DeepEqual(root, want) { t.Fatalf("got %#v", root) } if _, err := placeReportValue(root, []string{"a/b", "~1", "child"}, 1); err == nil { t.Fatal("scalar ancestor accepted") } if value, err := placeReportValue(root, nil, "replacement"); err != nil || value != "replacement" { t.Fatalf("root: %#v, %v", value, err) } }