grokkit/internal/recipe/runner_test.go
Greg Gauthier b9de35f48b refactor(recipe): simplify apply step to dry-run only and add extraction tests
- Restrict filesystem interactions to apply/patch steps exclusively.
- Remove real apply logic with user confirmation; default to creating a patch file in dry-run mode.
- Update prompts, comments, and regex for better clarity and precision.
- Add unit tests for the extractCodeBlocks function to ensure reliable parsing.
2026-03-06 21:36:31 +00:00

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)
}
})
}
}