MCPcopy Create free account
hub / github.com/astercloud/aster / TestParseTyped

Function TestParseTyped

pkg/structured/typed_test.go:119–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestParseTyped(t *testing.T) {
120 spec := TypedOutputSpec{
121 StructType: &TestTask{},
122 RequiredFields: []string{"id", "title"},
123 Strict: true,
124 }
125
126 jsonText := `{
127 "id": "task-3",
128 "title": "Typed Task",
129 "priority": 3
130 }`
131
132 result, err := ParseTyped(context.Background(), jsonText, spec)
133 if err != nil {
134 t.Fatalf("ParseTyped failed: %v", err)
135 }
136
137 if !result.Success {
138 t.Error("expected success=true")
139 }
140
141 task, ok := result.Data.(*TestTask)
142 if !ok {
143 t.Fatal("expected data to be *TestTask")
144 }
145
146 if task.ID != "task-3" {
147 t.Errorf("expected ID='task-3', got '%s'", task.ID)
148 }
149}
150
151func TestParseTyped_MissingRequired(t *testing.T) {
152 spec := TypedOutputSpec{

Callers

nothing calls this directly

Calls 2

ParseTypedFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected