gitblog1
This commit is contained in:
110
internal/content/manager_test.go
Normal file
110
internal/content/manager_test.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenerateSlug(t *testing.T) {
|
||||
m := &Manager{}
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"Hello World", "hello-world"},
|
||||
{"Hello, World!", "hello-world"},
|
||||
{"Test@#$%^&*()", "test"},
|
||||
{" Multiple Spaces ", "multiple-spaces"},
|
||||
{"", "untitled"},
|
||||
{"!@#$%", "untitled"},
|
||||
{"123 Test", "123-test"},
|
||||
{"Test-With-Dashes", "test-with-dashes"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := m.generateSlug(test.input)
|
||||
if result != test.expected {
|
||||
t.Errorf("generateSlug(%q) = %q, expected %q", test.input, result, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateExcerpt(t *testing.T) {
|
||||
m := &Manager{}
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
"This is a short text",
|
||||
"This is a short text",
|
||||
},
|
||||
{
|
||||
"One two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty-one twenty-two twenty-three twenty-four twenty-five twenty-six twenty-seven twenty-eight twenty-nine thirty thirty-one",
|
||||
"One two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty-one twenty-two twenty-three twenty-four twenty-five twenty-six twenty-seven twenty-eight twenty-nine thirty...",
|
||||
},
|
||||
{
|
||||
"",
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := m.generateExcerpt(test.input)
|
||||
if result != test.expected {
|
||||
t.Errorf("generateExcerpt() = %q, expected %q", result, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFrontmatter(t *testing.T) {
|
||||
m := &Manager{}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
lines []string
|
||||
expected map[string]interface{}
|
||||
}{
|
||||
{
|
||||
name: "simple frontmatter",
|
||||
lines: []string{
|
||||
"title: My Post",
|
||||
"date: 2024-01-15",
|
||||
"---",
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "My Post",
|
||||
"date": "2024-01-15",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "frontmatter with arrays",
|
||||
lines: []string{
|
||||
"title: My Post",
|
||||
"categories: [Technology, Go]",
|
||||
"tags: [golang, web]",
|
||||
"---",
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"title": "My Post",
|
||||
"categories": []interface{}{"Technology", "Go"},
|
||||
"tags": []interface{}{"golang", "web"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty frontmatter",
|
||||
lines: []string{},
|
||||
expected: map[string]interface{}{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
result := m.parseFrontmatter(test.lines)
|
||||
if len(result) != len(test.expected) {
|
||||
t.Errorf("parseFrontmatter() returned %d items, expected %d", len(result), len(test.expected))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user