diff --git a/internal/core/notebook_test.go b/internal/core/notebook_test.go new file mode 100644 index 00000000..f353cd83 --- /dev/null +++ b/internal/core/notebook_test.go @@ -0,0 +1,47 @@ +package core + +import ( + "testing" + + "github.com/zk-org/zk/internal/util" + "github.com/zk-org/zk/internal/util/test/assert" +) + +// TestRelPathResolvesInsideNotebook tests that Notebook.RelPath() resolves +// relative paths relative to the notebook directory. +func TestRelPathResolvesInsideNotebook(t *testing.T) { + notebookPath := "/notebook" + workingDir := "/notebook" + + fs := newFileStorageMock(workingDir, []string{notebookPath}) + + notebook := NewNotebook(notebookPath, NewDefaultConfig(), NotebookPorts{ + FS: fs, + Logger: &util.NullLogger, + }) + + relPath, err := notebook.RelPath("inbox/note.md") + + assert.Nil(t, err) + assert.Equal(t, relPath, "inbox/note.md") +} + +// TestRelPathResolvesOutsideNotebook tests that Notebook.RelPath() resolves +// relative paths relative to the notebook directory, not the current working +// directory. +func TestRelPathResolvesOutsideNotebook(t *testing.T) { + notebookPath := "/notebook" + workingDir := "/other/dir" + + fs := newFileStorageMock(workingDir, []string{notebookPath}) + + notebook := NewNotebook(notebookPath, NewDefaultConfig(), NotebookPorts{ + FS: fs, + Logger: &util.NullLogger, + }) + + relPath, err := notebook.RelPath("inbox/note.md") + + assert.Nil(t, err) + assert.Equal(t, relPath, "inbox/note.md") +} diff --git a/tests/linked-by-hierarchical-path.tesh b/tests/linked-by-hierarchical-path.tesh new file mode 100644 index 00000000..b65f8c07 --- /dev/null +++ b/tests/linked-by-hierarchical-path.tesh @@ -0,0 +1,13 @@ +# XXX: untested, can't get tesh to work + +# Running from notebook directory. +$ cd full-sample +$ zk list -qf\{{title}} --linked-by inbox/er4k.md +>Channel +>Ownership in Rust + +# Running from outside notebook with --notebook-dir. +$ cd .. +$ zk list --notebook-dir=full-sample -qf\{{title}} --linked-by inbox/er4k.md +>Channel +>Ownership in Rust