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