- 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
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestRemoveLastModifiedComments(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "removes last modified comment",
|
|
input: "// Last modified: 2024-01-01\npackage main\n\nfunc main() {}",
|
|
expected: "package main\n\nfunc main() {}",
|
|
},
|
|
{
|
|
name: "removes multiple last modified comments",
|
|
input: "// Last modified: 2024-01-01\npackage main\n// Last modified by: user\nfunc main() {}",
|
|
expected: "package main\nfunc main() {}",
|
|
},
|
|
{
|
|
name: "preserves code without last modified",
|
|
input: "package main\n\nfunc main() {}",
|
|
expected: "package main\n\nfunc main() {}",
|
|
},
|
|
{
|
|
name: "handles empty string",
|
|
input: "",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "preserves other comments",
|
|
input: "// This is a regular comment\npackage main\n// Last modified: 2024\n// Another comment\nfunc main() {}",
|
|
expected: "// This is a regular comment\npackage main\n// Another comment\nfunc main() {}",
|
|
},
|
|
{
|
|
name: "handles line with only last modified",
|
|
input: "Last modified: 2024-01-01",
|
|
expected: "",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := removeLastModifiedComments(tt.input)
|
|
if result != tt.expected {
|
|
t.Errorf("removeLastModifiedComments() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|