Do a thorough job of parsing json struct tags. Move the code to a place where both mcp and jsonschema can use it. Change-Id: I6c86308834706b12a1e22cd96ae120590f49d3f4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/678757 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com>
38 lines
794 B
Go
38 lines
794 B
Go
// Copyright 2025 The Go MCP SDK Authors. All rights reserved.
|
|
// Use of this source code is governed by an MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package util
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestJSONInfo(t *testing.T) {
|
|
type S struct {
|
|
A int
|
|
B int `json:","`
|
|
C int `json:"-"`
|
|
D int `json:"-,"`
|
|
E int `json:"echo"`
|
|
F int `json:"foxtrot,omitempty"`
|
|
g int `json:"golf"`
|
|
}
|
|
want := []JSONInfo{
|
|
{Name: "A"},
|
|
{Name: "B"},
|
|
{Omit: true},
|
|
{Name: "-"},
|
|
{Name: "echo"},
|
|
{Name: "foxtrot", Settings: map[string]bool{"omitempty": true}},
|
|
{Omit: true},
|
|
}
|
|
tt := reflect.TypeFor[S]()
|
|
for i := range tt.NumField() {
|
|
got := FieldJSONInfo(tt.Field(i))
|
|
if !reflect.DeepEqual(got, want[i]) {
|
|
t.Errorf("got %+v, want %+v", got, want[i])
|
|
}
|
|
}
|
|
}
|