-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c741398
commit 46b4a83
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local workspace = require "obsidian.workspace" | ||
|
||
local opts = { | ||
workspaces = { | ||
{ | ||
name = "work", | ||
path = "~/notes/work", | ||
}, | ||
{ | ||
name = "personal", | ||
path = "~/notes/personal", | ||
}, | ||
{ | ||
name = "cwd_workspace", | ||
path = os.getenv "PWD", | ||
}, | ||
}, | ||
detect_cwd = false, | ||
} | ||
|
||
describe("Workspace", function() | ||
it("should be able to initialize a workspace", function() | ||
local ws = workspace.new("test_workspace", "/tmp/obsidian_test_workspace") | ||
assert.equals("test_workspace", ws.name) | ||
assert.equals("/tmp/obsidian_test_workspace", ws.path) | ||
end) | ||
|
||
it("should be able to initialize from cwd", function() | ||
local ws = workspace.new_from_cwd() | ||
local cwd = os.getenv "PWD" | ||
assert.equals(".", ws.name) | ||
assert.equals(cwd, ws.path) | ||
end) | ||
|
||
it("should be able to retrieve the default workspace", function() | ||
local ws = workspace.get_default_workspace(opts.workspaces) | ||
assert.is_not(ws, nil) | ||
assert.equals(opts.workspaces[1].name, ws.name) | ||
assert.equals(opts.workspaces[1].path, ws.path) | ||
end) | ||
|
||
it("should initialize workspace from cwd", function() | ||
local ws = workspace.get_workspace_from_cwd(opts.workspaces) | ||
assert.equals(opts.workspaces[3].name, ws.name) | ||
assert.equals(opts.workspaces[3].path, ws.path) | ||
end) | ||
|
||
it("should return cwd workspace when detect_cwd is true", function() | ||
local old_cwd = opts.detect_cwd | ||
opts.detect_cwd = true | ||
local ws = workspace.get_from_opts(opts) | ||
assert.equals(opts.workspaces[3].name, ws.name) | ||
assert.equals(opts.workspaces[3].path, ws.path) | ||
opts.detect_cwd = old_cwd | ||
end) | ||
it("should return default workspace when detect_cwd is false", function() | ||
local old_cwd = opts.detect_cwd | ||
opts.detect_cwd = false | ||
local ws = workspace.get_from_opts(opts) | ||
assert.equals(opts.workspaces[1].name, ws.name) | ||
assert.equals(opts.workspaces[1].path, ws.path) | ||
opts.detect_cwd = old_cwd | ||
end) | ||
end) |