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

63 lines
1.8 KiB
Go
Raw Normal View History

package gojekyll
2017-06-11 16:00:03 -04:00
import (
"testing"
"github.com/stretchr/testify/require"
2017-06-11 16:00:03 -04:00
)
func TestExpandPermalinkPattern(t *testing.T) {
2017-06-13 08:51:58 -04:00
var (
2017-06-16 22:09:25 -04:00
site = NewSite()
2017-06-15 09:01:42 -04:00
d = VariableMap{}
path = "/a/b/base.html"
2017-06-13 08:51:58 -04:00
)
testPermalinkPattern := func(pattern, path string, data VariableMap) (string, error) {
vs := MergeVariableMaps(data, VariableMap{"permalink": pattern})
2017-06-16 20:06:55 -04:00
p := pageFields{site: site, relpath: path, frontMatter: vs}
return p.expandPermalink()
}
2017-06-13 08:51:58 -04:00
t.Run(":output_ext", func(t *testing.T) {
p, err := testPermalinkPattern("/base:output_ext", path, d)
require.NoError(t, err)
require.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, err := testPermalinkPattern("/base:output_ext", "/a/b/base.md", d)
require.NoError(t, err)
require.Equal(t, "/base.html", p)
p, err = testPermalinkPattern("/base:output_ext", "/a/b/base.markdown", d)
require.NoError(t, err)
require.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) {
p, err := testPermalinkPattern("/name/:name", path, d)
require.NoError(t, err)
require.Equal(t, "/name/base", p)
2017-06-11 16:00:03 -04:00
})
t.Run(":path", func(t *testing.T) {
p, err := testPermalinkPattern("/prefix:path/post", path, d)
require.NoError(t, err)
require.Equal(t, "/prefix/a/b/base/post", p)
2017-06-11 16:00:03 -04:00
})
t.Run(":title", func(t *testing.T) {
p, err := testPermalinkPattern("/title/:title.html", path, d)
require.NoError(t, err)
require.Equal(t, "/title/base.html", p)
2017-06-15 09:01:42 -04:00
})
t.Run("invalid template variable", func(t *testing.T) {
_, err := testPermalinkPattern("/:invalid", path, d)
require.Error(t, err)
2017-06-11 16:00:03 -04:00
})
2017-06-16 20:19:46 -04:00
// d["collection"] = "c"
// path = "_c/a/b/c.d"
// t.Run(":path", func(t *testing.T) {
// p, err := testPermalinkPattern("/prefix:path/post", path, d)
// require.NoError(t, err)
// require.Equal(t, "/prefix/a/b/c/post", p)
// })
2017-06-11 16:00:03 -04:00
}