jsonschema: pre-compile regexps
This is the first CL that deals with the process of preparing a schema for validation. Perform some basic checks on the scheme. Along the way, compile regexps and store them in the schema for use during validation. Change-Id: I0e5e6ce28656dcecb6d2d4b2fdc98998fa05b6f1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/669696 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
cc7bdd8d43
commit
3d33fafc5d
1 changed files with 153 additions and 34 deletions
37
internal/jsonschema/resolve_test.go
Normal file
37
internal/jsonschema/resolve_test.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// 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 jsonschema
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCheckLocal(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
s *Schema
|
||||
want string // error must be non-nil and match this regexp
|
||||
}{
|
||||
{nil, "nil"},
|
||||
{
|
||||
&Schema{Pattern: "]["},
|
||||
"regexp",
|
||||
},
|
||||
{
|
||||
&Schema{PatternProperties: map[string]*Schema{"*": nil}},
|
||||
"regexp",
|
||||
},
|
||||
} {
|
||||
_, err := tt.s.Resolve()
|
||||
if err == nil {
|
||||
t.Errorf("%s: unexpectedly passed", tt.s.json())
|
||||
continue
|
||||
}
|
||||
if !regexp.MustCompile(tt.want).MatchString(err.Error()) {
|
||||
t.Errorf("%s: did not match\nerror: %s\nregexp: %s",
|
||||
tt.s.json(), err, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue