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

52 lines
1.3 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-14 17:41:15 -04:00
d = VariableMap{}
2017-06-13 08:51:58 -04:00
path = "/a/b/c.d"
mdPath = "/a/b/c.md"
)
t.Run(":ext", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/ext/:ext", path, d)
2017-06-13 08:51:58 -04:00
assert.Equal(t, "/ext/d", p)
})
t.Run(":ext", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/ext/:ext", mdPath, d)
2017-06-13 08:51:58 -04:00
assert.Equal(t, "/ext/md", p)
})
t.Run(":output_ext", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/ext/:output_ext", path, d)
2017-06-13 08:51:58 -04:00
assert.Equal(t, "/ext/d", p)
})
t.Run(":output_ext", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/ext/:output_ext", mdPath, d)
2017-06-13 08:51:58 -04:00
assert.Equal(t, "/ext/html", p)
})
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-13 08:51:58 -04:00
assert.Equal(t, "/name/c", 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-11 16:00:03 -04:00
assert.Equal(t, "/prefix/a/b/c.d/post", p)
})
t.Run(":title", func(t *testing.T) {
2017-06-14 13:20:52 -04:00
p, _ := expandPermalinkPattern("/title/:title.html", path, d)
assert.Equal(t, "/title/c.html", p)
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)
})
}