1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-23 00:21:15 +01:00
gojekyll/permalinks_test.go

49 lines
1.4 KiB
Go
Raw Normal View History

2017-06-11 16:00:03 -04:00
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExpandPermalinkPattern(t *testing.T) {
2017-06-13 08:51:58 -04:00
var (
2017-06-15 09:01:42 -04:00
d = VariableMap{}
path = "/a/b/base.html"
2017-06-13 08:51:58 -04:00
)
t.Run(":output_ext", func(t *testing.T) {
2017-06-15 09:01:42 -04:00
p, _ := expandPermalinkPattern("/base:output_ext", path, d)
assert.Equal(t, "/base.html", p)
2017-06-13 08:51:58 -04:00
})
2017-06-15 09:01:42 -04:00
t.Run(":output_ext renames markdown to .html", func(t *testing.T) {
p, _ := expandPermalinkPattern("/base:output_ext", "/a/b/base.md", d)
assert.Equal(t, "/base.html", p)
p, _ = expandPermalinkPattern("/base:output_ext", "/a/b/base.markdown", d)
assert.Equal(t, "/base.html", p)
2017-06-13 08:51:58 -04:00
})
2017-06-11 16:00:03 -04:00
t.Run(":name", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/name/:name", path, d)
2017-06-15 09:01:42 -04:00
assert.Equal(t, "/name/base", p)
2017-06-11 16:00:03 -04:00
})
t.Run(":path", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/prefix:path/post", path, d)
2017-06-15 09:01:42 -04:00
assert.Equal(t, "/prefix/a/b/base.html/post", p)
2017-06-11 16:00:03 -04:00
})
t.Run(":title", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/title/:title.html", path, d)
2017-06-15 09:01:42 -04:00
assert.Equal(t, "/title/base.html", p)
})
t.Run("invalid template variable", func(t *testing.T) {
_, err := expandPermalinkPattern("/:invalid", path, d)
assert.Error(t, err)
2017-06-11 16:00:03 -04:00
})
d["collection"] = "c"
path = "/_c/a/b/c.d"
t.Run(":path", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/prefix:path/post", path, d)
2017-06-11 16:00:03 -04:00
assert.Equal(t, "/prefix/a/b/c.d/post", p)
})
}