Skip to content

Commit ef58327

Browse files
committed
chore: add tests for parsing empty files and strings
Signed-off-by: Donnie Adams <[email protected]>
1 parent de120f1 commit ef58327

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

gptscript_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,22 @@ func TestParseSimpleFile(t *testing.T) {
445445
}
446446
}
447447

448+
func TestParseEmptyFile(t *testing.T) {
449+
wd, err := os.Getwd()
450+
if err != nil {
451+
t.Fatalf("Error getting working directory: %v", err)
452+
}
453+
454+
tools, err := g.Parse(context.Background(), wd+"/test/empty.gpt")
455+
if err != nil {
456+
t.Errorf("Error parsing file: %v", err)
457+
}
458+
459+
if len(tools) != 0 {
460+
t.Fatalf("Unexpected number of tools: %d", len(tools))
461+
}
462+
}
463+
448464
func TestParseFileWithMetadata(t *testing.T) {
449465
wd, err := os.Getwd()
450466
if err != nil {
@@ -500,6 +516,17 @@ func TestParseTool(t *testing.T) {
500516
}
501517
}
502518

519+
func TestEmptyParseTool(t *testing.T) {
520+
tools, err := g.ParseTool(context.Background(), "")
521+
if err != nil {
522+
t.Errorf("Error parsing tool: %v", err)
523+
}
524+
525+
if len(tools) != 0 {
526+
t.Fatalf("Unexpected number of tools: %d", len(tools))
527+
}
528+
}
529+
503530
func TestParseToolWithTextNode(t *testing.T) {
504531
tools, err := g.ParseTool(context.Background(), "echo hello\n---\n!markdown\nhello")
505532
if err != nil {

test/empty.gpt

Whitespace-only changes.

0 commit comments

Comments
 (0)