62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
|
|
package recipe
|
||
|
|
|
||
|
|
import (
|
||
|
|
"reflect"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestExtractCodeBlocks(t *testing.T) {
|
||
|
|
t.Parallel()
|
||
|
|
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
input string
|
||
|
|
expected map[string]string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "Single block",
|
||
|
|
input: "// main.go\n```go\npackage main\n\nfunc main() {}\n```",
|
||
|
|
expected: map[string]string{
|
||
|
|
"main.go": "package main\n\nfunc main() {}",
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "Multiple blocks",
|
||
|
|
input: `// internal/utils.go
|
||
|
|
` + "```" + `go
|
||
|
|
package utils
|
||
|
|
func Help() {}
|
||
|
|
` + "```" + `
|
||
|
|
Some commentary.
|
||
|
|
// cmd/root.go
|
||
|
|
` + "```" + `go
|
||
|
|
package cmd
|
||
|
|
func Execute() {}
|
||
|
|
` + "```",
|
||
|
|
expected: map[string]string{
|
||
|
|
"internal/utils.go": "package utils\nfunc Help() {}",
|
||
|
|
"cmd/root.go": "package cmd\nfunc Execute() {}",
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "No blocks",
|
||
|
|
input: "Just some text without any blocks.",
|
||
|
|
expected: map[string]string{},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "Incomplete block",
|
||
|
|
input: "// oops.go\n```go\nfunc incomplete() {",
|
||
|
|
expected: map[string]string{},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
got := extractCodeBlocks(tt.input)
|
||
|
|
if !reflect.DeepEqual(got, tt.expected) {
|
||
|
|
t.Errorf("extractCodeBlocks() = %v, want %v", got, tt.expected)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|