61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package instructions
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestFormat_empty(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
}{
|
|
{"empty_string", "", ""},
|
|
{"whitespace_only", " ", ""},
|
|
{"newline_only", "\n\n", ""},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := Format(tt.input); got != tt.want {
|
|
t.Errorf("Format(%q) = %q; want %q", tt.input, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFormat_valid(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
}{
|
|
{"single_line", "hello world"},
|
|
{"multi_line", "line 1\nline 2\nline 3"},
|
|
{"trailing_newlines", "content\n\n\n"},
|
|
{"leading_whitespace", "\n\ncontent"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := Format(tt.input)
|
|
if !strings.HasPrefix(got, "> Instructions:\n") {
|
|
t.Errorf("missing instructions header")
|
|
}
|
|
if !strings.HasSuffix(got, "\n") {
|
|
t.Errorf("does not end with newline")
|
|
}
|
|
lines := strings.Split(got, "\n")
|
|
for _, line := range lines {
|
|
if line != "" && !strings.HasPrefix(line, ">") {
|
|
t.Errorf("line does not start with '>': %q", line)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFileName_constant(t *testing.T) {
|
|
if FileName != ".dirmd" {
|
|
t.Errorf("FileName = %q; want \".dirmd\"", FileName)
|
|
}
|
|
}
|