home/internal/domain/path_test.go

169 lines
3.6 KiB
Go

package domain_test
import (
"path/filepath"
"testing"
"source.toby3d.me/toby3d/home/internal/domain"
)
var (
testRegularPath string = filepath.Join("news", "a.en.md")
testLeafPath string = filepath.Join("news", "b", "index.en.md")
testBranchPath string = filepath.Join("news", "_index.en.md")
)
func TestPath_BaseFileName(t *testing.T) {
t.Parallel()
for name, tc := range map[string]struct {
input, expect string
}{
"regular": {testRegularPath, "a.en"},
"leaf": {testLeafPath, "index.en"},
"branch": {testBranchPath, "_index.en"},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if actual := domain.NewPath(tc.input).BaseFileName(); actual != tc.expect {
t.Errorf("BaseFileName() = '%s', want '%s'", actual, tc.expect)
}
})
}
}
func TestPath_ContentBaseName(t *testing.T) {
t.Parallel()
for name, tc := range map[string]struct {
input, expect string
}{
"regular": {testRegularPath, "a"},
"leaf": {testLeafPath, "b"},
"branch": {testBranchPath, "news"},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if actual := domain.NewPath(tc.input).ContentBaseName(); actual != tc.expect {
t.Errorf("ContentBaseName() = '%s', want '%s'", actual, tc.expect)
}
})
}
}
func TestPath_Dir(t *testing.T) {
t.Parallel()
for name, tc := range map[string]struct {
input, expect string
}{
"regular": {testRegularPath, "news/"},
"leaf": {testLeafPath, "news/b/"},
"branch": {testBranchPath, "news/"},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if actual := domain.NewPath(tc.input).Dir(); actual != tc.expect {
t.Errorf("Dir() = '%s', want '%s'", actual, tc.expect)
}
})
}
}
func TestPath_Ext(t *testing.T) {
t.Parallel()
const expect string = "md"
for name, input := range map[string]string{
"regular": testRegularPath,
"leaf": testLeafPath,
"branch": testBranchPath,
} {
name, input := name, input
t.Run(name, func(t *testing.T) {
t.Parallel()
if actual := domain.NewPath(input).Ext(); actual != expect {
t.Errorf("Ext() = '%s', want '%s'", actual, expect)
}
})
}
}
func TestPath_Language(t *testing.T) {
t.Parallel()
var expect domain.Language = domain.NewLanguage("en")
for name, input := range map[string]string{
"regular": testRegularPath,
"leaf": testLeafPath,
"branch": testBranchPath,
} {
name, input := name, input
t.Run(name, func(t *testing.T) {
t.Parallel()
if actual := domain.NewPath(input).Language; actual != expect {
t.Errorf("Language() = '%s', want '%s'", actual, expect)
}
})
}
}
func TestPath_LogicalName(t *testing.T) {
t.Parallel()
for name, tc := range map[string]struct {
input, expect string
}{
"regular": {testRegularPath, "a.en.md"},
"leaf": {testLeafPath, "index.en.md"},
"branch": {testBranchPath, "_index.en.md"},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if actual := domain.NewPath(tc.input).LogicalName(); actual != tc.expect {
t.Errorf("LogicalName() = '%s', want '%s'", actual, tc.expect)
}
})
}
}
func TestPath_TranslationBaseName(t *testing.T) {
t.Parallel()
for name, tc := range map[string]struct {
input, expect string
}{
"regular": {testRegularPath, "a"},
"leaf": {testLeafPath, "index"},
"branch": {testBranchPath, "_index"},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if actual := domain.NewPath(tc.input).TranslationBaseName(); actual != tc.expect {
t.Errorf("TranslationBaseName() = '%s', want '%s'", actual, tc.expect)
}
})
}
}