33 lines
1.3 KiB
Go
33 lines
1.3 KiB
Go
package format
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/promptkit"
|
|
)
|
|
|
|
func TestFormatPromptInspectionPreservesDeclaredOrderAndEmptyValues(t *testing.T) {
|
|
value := &promptkit.PromptInspection{PromptID: "p", PromptVersion: "1", PromptHash: "hash", Inputs: []promptkit.PromptInputDefinition{{Name: "first", Required: true, ContentType: "text/plain", Description: "first input"}, {Name: "second"}}, OutputContract: promptkit.OutputContract{Format: "text", ValidationMode: promptkit.ValidationNone}}
|
|
text, err := FormatPromptInspection(value, OutputFormatText)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(text), "default_profile_id: \ninputs:\n - name: first") || strings.Index(string(text), "name: first") > strings.Index(string(text), "name: second") {
|
|
t.Fatalf("unexpected text inspection: %s", text)
|
|
}
|
|
jsonOutput, err := FormatPromptInspection(value, OutputFormatJSON)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.HasSuffix(string(jsonOutput), "\n") || !strings.Contains(string(jsonOutput), `"default_profile_id": ""`) {
|
|
t.Fatalf("unexpected json inspection: %s", jsonOutput)
|
|
}
|
|
}
|
|
|
|
func TestFormatPromptInspectionRejectsNil(t *testing.T) {
|
|
if _, err := FormatPromptInspection(nil, OutputFormatText); err == nil {
|
|
t.Fatal("expected nil inspection error")
|
|
}
|
|
}
|