Skip to content

Commit

Permalink
chore: add workspace tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weskoerber committed Oct 16, 2023
1 parent c741398 commit 46b4a83
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/obsidian/workspace_spec.lua
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)

0 comments on commit 46b4a83

Please sign in to comment.