| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package mcp |
| 6 |
|
| 7 |
import ( |
| 8 |
"slices" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"github.com/google/go-cmp/cmp" |
| 12 |
"github.com/google/go-cmp/cmp/cmpopts" |
| 13 |
"github.com/google/jsonschema-go/jsonschema" |
| 14 |
) |
| 15 |
|
| 16 |
type SayHiParams struct { |
| 17 |
Name string `json:"name"` |
| 18 |
} |
| 19 |
|
| 20 |
func TestFeatureSetOrder(t *testing.T) { |
| 21 |
toolA := &Tool{Name: "apple", Description: "apple tool"} |
| 22 |
toolB := &Tool{Name: "banana", Description: "banana tool"} |
| 23 |
toolC := &Tool{Name: "cherry", Description: "cherry tool"} |
| 24 |
|
| 25 |
testCases := []struct { |
| 26 |
tools []*Tool |
| 27 |
want []*Tool |
| 28 |
}{ |
| 29 |
{[]*Tool{toolA, toolB, toolC}, []*Tool{toolA, toolB, toolC}}, |
| 30 |
{[]*Tool{toolB, toolC, toolA}, []*Tool{toolA, toolB, toolC}}, |
| 31 |
{[]*Tool{toolA, toolC}, []*Tool{toolA, toolC}}, |
| 32 |
{[]*Tool{toolA, toolA, toolA}, []*Tool{toolA}}, |
| 33 |
{[]*Tool{}, nil}, |
| 34 |
} |
| 35 |
for _, tc := range testCases { |
| 36 |
fs := newFeatureSet(func(t *Tool) string { return t.Name }) |
| 37 |
fs.add(tc.tools...) |
| 38 |
got := slices.Collect(fs.all()) |
| 39 |
if diff := cmp.Diff(got, tc.want, cmpopts.IgnoreUnexported(jsonschema.Schema{})); diff != "" { |
| 40 |
t.Errorf("expected %v, got %v, (-want +got):\n%s", tc.want, got, diff) |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
func TestFeatureSetAbove(t *testing.T) { |
| 46 |
toolA := &Tool{Name: "apple", Description: "apple tool"} |
| 47 |
toolB := &Tool{Name: "banana", Description: "banana tool"} |
| 48 |
toolC := &Tool{Name: "cherry", Description: "cherry tool"} |
| 49 |
|
| 50 |
testCases := []struct { |
| 51 |
tools []*Tool |
| 52 |
above string |
| 53 |
want []*Tool |
| 54 |
}{ |
| 55 |
{[]*Tool{toolA, toolB, toolC}, "apple", []*Tool{toolB, toolC}}, |
| 56 |
{[]*Tool{toolA, toolB, toolC}, "banana", []*Tool{toolC}}, |
| 57 |
{[]*Tool{toolA, toolB, toolC}, "cherry", nil}, |
| 58 |
} |
| 59 |
for _, tc := range testCases { |
| 60 |
fs := newFeatureSet(func(t *Tool) string { return t.Name }) |
| 61 |
fs.add(tc.tools...) |
| 62 |
got := slices.Collect(fs.above(tc.above)) |
| 63 |
if diff := cmp.Diff(got, tc.want, cmpopts.IgnoreUnexported(jsonschema.Schema{})); diff != "" { |
| 64 |
t.Errorf("expected %v, got %v, (-want +got):\n%s", tc.want, got, diff) |
| 65 |
} |
| 66 |
} |
| 67 |
} |