Fix tests for Abs(path)

pull/60/head
Peter Stuifzand 3 years ago
parent 4d893b9bd6
commit cd471f28a4

@ -23,7 +23,10 @@ func newNoteFormatter(basePath string, template Template, linkFormatter LinkForm
return "", err
}
fullPath := filepath.Join(basePath, note.Path)
fullPath, err := fs.Abs(filepath.Join(basePath, note.Path))
if err != nil {
return "", err
}
snippets := make([]string, 0)
for _, snippet := range note.Snippets {

@ -71,6 +71,7 @@ func TestNewNoteFormatter(t *testing.T) {
assert.Equal(t, test.template.Contexts, []interface{}{
noteFormatRenderContext{
Path: "note1",
FullPath: "/notebook/note1",
Title: "Note 1",
Link: opt.NewString("[Note 1](note1)"),
Lead: "Lead 1",
@ -89,6 +90,7 @@ func TestNewNoteFormatter(t *testing.T) {
},
noteFormatRenderContext{
Path: "dir/note2",
FullPath: "/notebook/dir/note2",
Title: "Note 2",
Link: opt.NewString("[Note 2](dir/note2)"),
Lead: "Lead 2",
@ -106,7 +108,7 @@ func TestNewNoteFormatter(t *testing.T) {
}
func TestNoteFormatterMakesPathRelative(t *testing.T) {
test := func(basePath, currentPath, path string, expected string) {
test := func(basePath, currentPath, path string, expected, expectedFull string) {
test := formatTest{
rootDir: basePath,
workingDir: currentPath,
@ -121,6 +123,7 @@ func TestNoteFormatterMakesPathRelative(t *testing.T) {
assert.Equal(t, test.template.Contexts, []interface{}{
noteFormatRenderContext{
Path: expected,
FullPath: expectedFull,
Link: opt.NewString("[](" + paths.DropExt(expected) + ")"),
Snippets: []string{},
},
@ -128,14 +131,14 @@ func TestNoteFormatterMakesPathRelative(t *testing.T) {
}
// Check that the path is relative to the current directory.
test("", "", "note.md", "note.md")
test("", "", "dir/note.md", "dir/note.md")
test("/abs/zk", "/abs/zk", "note.md", "note.md")
test("/abs/zk", "/abs/zk", "dir/note.md", "dir/note.md")
test("/abs/zk", "/abs/zk/dir", "note.md", "../note.md")
test("/abs/zk", "/abs/zk/dir", "dir/note.md", "note.md")
test("/abs/zk", "/abs", "note.md", "zk/note.md")
test("/abs/zk", "/abs", "dir/note.md", "zk/dir/note.md")
test("", "", "note.md", "note.md", "/notebook/note.md")
test("", "", "dir/note.md", "dir/note.md", "/notebook/dir/note.md")
test("/abs/zk", "/abs/zk", "note.md", "note.md", "/abs/zk/note.md")
test("/abs/zk", "/abs/zk", "dir/note.md", "dir/note.md", "/abs/zk/dir/note.md")
test("/abs/zk", "/abs/zk/dir", "note.md", "../note.md", "/abs/zk/note.md")
test("/abs/zk", "/abs/zk/dir", "dir/note.md", "note.md", "/abs/zk/dir/note.md")
test("/abs/zk", "/abs", "note.md", "zk/note.md", "/abs/zk/note.md")
test("/abs/zk", "/abs", "dir/note.md", "zk/dir/note.md", "/abs/zk/dir/note.md")
}
func TestNoteFormatterStylesSnippetTerm(t *testing.T) {
@ -151,6 +154,7 @@ func TestNoteFormatterStylesSnippetTerm(t *testing.T) {
assert.Equal(t, test.template.Contexts, []interface{}{
noteFormatRenderContext{
Path: ".",
FullPath: "/notebook",
Link: opt.NewString("[]()"),
Snippets: []string{expected},
},

Loading…
Cancel
Save