Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions internal/core/notebook_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
13 changes: 13 additions & 0 deletions tests/linked-by-hierarchical-path.tesh
Original file line number Diff line number Diff line change
@@ -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
Loading