참고소스 수정본
This commit is contained in:
65
참고/firecrawl-main/apps/go-sdk/options_test.go
Normal file
65
참고/firecrawl-main/apps/go-sdk/options_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package firecrawl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScrapeOptionsSerializesQueryFormatMode(t *testing.T) {
|
||||
payload, err := json.Marshal(ScrapeOptions{
|
||||
FormatOptions: []interface{}{
|
||||
QueryFormat{
|
||||
Prompt: "What is Firecrawl?",
|
||||
Mode: QueryModeDirectQuote,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal ScrapeOptions: %v", err)
|
||||
}
|
||||
|
||||
jsonBody := string(payload)
|
||||
for _, want := range []string{
|
||||
`"formats":[{"type":"query","prompt":"What is Firecrawl?","mode":"directQuote"}]`,
|
||||
} {
|
||||
if !strings.Contains(jsonBody, want) {
|
||||
t.Fatalf("serialized query format = %s, want to contain %s", jsonBody, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestScrapeOptionsSerializesQuestionAndHighlightsFormats(t *testing.T) {
|
||||
payload, err := json.Marshal(ScrapeOptions{
|
||||
FormatOptions: []interface{}{
|
||||
QuestionFormat{Question: "What is Firecrawl?"},
|
||||
HighlightsFormat{Query: "What is Firecrawl?"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal ScrapeOptions: %v", err)
|
||||
}
|
||||
|
||||
jsonBody := string(payload)
|
||||
for _, want := range []string{
|
||||
`{"type":"question","question":"What is Firecrawl?"}`,
|
||||
`{"type":"highlights","query":"What is Firecrawl?"}`,
|
||||
} {
|
||||
if !strings.Contains(jsonBody, want) {
|
||||
t.Fatalf("serialized formats = %s, want to contain %s", jsonBody, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestScrapeOptionsPreservesStringFormats(t *testing.T) {
|
||||
payload, err := json.Marshal(ScrapeOptions{
|
||||
Formats: []string{"markdown"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal ScrapeOptions: %v", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(string(payload), `"formats":["markdown"]`) {
|
||||
t.Fatalf("serialized string formats = %s", payload)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user