Publish an IntentSpec JSON sample #5
@@ -0,0 +1 @@
|
||||
{"id":"demo.write","domain":"demo","version":1,"matcher":{"includes_any":["写"]}}
|
||||
@@ -0,0 +1,34 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"agent-intent/intent"
|
||||
)
|
||||
|
||||
func TestIntentSpecRoundTrip(t *testing.T) {
|
||||
raw, err := os.ReadFile("intentspec.sample.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var spec intent.IntentSpec
|
||||
if err := json.Unmarshal(raw, &spec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if spec.ID != "demo.write" || spec.Matcher.IncludesAny[0] != "写" {
|
||||
t.Fatalf("%+v", spec)
|
||||
}
|
||||
back, err := json.Marshal(spec)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var again intent.IntentSpec
|
||||
if err := json.Unmarshal(back, &again); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if again.ID != spec.ID || again.Version != 1 {
|
||||
t.Fatalf("%+v", again)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user