internal/mcp: unify json tag parsing
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>
This commit is contained in:
parent
b1eb3c8804
commit
12761ffcb6
1 changed files with 101 additions and 97 deletions
|
|
@ -259,26 +259,6 @@ func TestStructInstance(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestJSONName(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 := []string{"A", "B", "", "-", "echo", "foxtrot", ""}
|
||||
tt := reflect.TypeFor[S]()
|
||||
for i := range tt.NumField() {
|
||||
got, _ := jsonName(tt.Field(i))
|
||||
if got != want[i] {
|
||||
t.Errorf("got %q, want %q", got, want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mustMarshal(x any) json.RawMessage {
|
||||
data, err := json.Marshal(x)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue