- Introduce tests for chat history file handling, loading/saving, and error cases in cmd/chat_test.go - Add tests for removeLastModifiedComments in cmd/edit_helper_test.go - Add comprehensive tests for CleanCodeResponse in internal/grok/cleancode_test.go - Update Makefile to centralize build artifacts in build/ directory for coverage reports and binary - Adjust .gitignore to ignore chat_history.json and remove obsolete coverage file entries
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package grok
|
|
|
|
import "testing"
|
|
|
|
func TestCleanCodeResponse_Comprehensive(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "removes go markdown fences",
|
|
input: "```go\npackage main\n\nfunc main() {}\n```",
|
|
expected: "package main\n\nfunc main() {}",
|
|
},
|
|
{
|
|
name: "removes python markdown fences",
|
|
input: "```python\ndef hello():\n print('hello')\n```",
|
|
expected: "def hello():\n print('hello')",
|
|
},
|
|
{
|
|
name: "removes plain markdown fences",
|
|
input: "```\nsome code\n```",
|
|
expected: "some code",
|
|
},
|
|
{
|
|
name: "handles no fences",
|
|
input: "func main() {}",
|
|
expected: "func main() {}",
|
|
},
|
|
{
|
|
name: "preserves internal blank lines",
|
|
input: "```\nline1\n\nline2\n\nline3\n```",
|
|
expected: "line1\n\nline2\n\nline3",
|
|
},
|
|
{
|
|
name: "trims leading whitespace",
|
|
input: " \n\n```\ncode\n```",
|
|
expected: "code",
|
|
},
|
|
{
|
|
name: "trims trailing whitespace",
|
|
input: "```\ncode\n```\n\n ",
|
|
expected: "code",
|
|
},
|
|
{
|
|
name: "handles multiple languages",
|
|
input: "```javascript\nconst x = 1;\n```",
|
|
expected: "const x = 1;",
|
|
},
|
|
{
|
|
name: "handles fences with extra spaces",
|
|
input: "``` \ncode\n``` ",
|
|
expected: "code",
|
|
},
|
|
{
|
|
name: "removes only fence lines",
|
|
input: "text before\n```go\ncode\n```\ntext after",
|
|
expected: "text before\n\ncode\n\ntext after",
|
|
},
|
|
{
|
|
name: "handles empty input",
|
|
input: "",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "handles only fences",
|
|
input: "```\n```",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "preserves code indentation",
|
|
input: "```\nfunc main() {\n fmt.Println(\"hello\")\n}\n```",
|
|
expected: "func main() {\n fmt.Println(\"hello\")\n}",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := CleanCodeResponse(tt.input)
|
|
if result != tt.expected {
|
|
t.Errorf("CleanCodeResponse():\ngot: %q\nwant: %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|