Skip to content

Commit

Permalink
Add unit tests for state.NewDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
wedaly committed Dec 23, 2023
1 parent 4d2e19a commit 62dc3a9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions state/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,23 @@ func TestDeduplicateCustomMenuItems(t *testing.T) {
text := state.DocumentBuffer().TextTree().String()
assert.Equal(t, text, "foo2\n")
}

func TestNewDocument(t *testing.T) {
tmpDir := t.TempDir()
path := filepath.Join(tmpDir, "test.txt")

state := NewEditorState(100, 100, nil, nil)
err := NewDocument(state, path)
require.NoError(t, err)

assert.Equal(t, path, state.FileWatcher().Path())
}

func TestNewDocumentFileAlreadyExists(t *testing.T) {
path, cleanup := createTestFile(t, "abcd")
defer cleanup()

state := NewEditorState(100, 100, nil, nil)
err := NewDocument(state, path)
assert.ErrorContains(t, err, "File already exists")
}

0 comments on commit 62dc3a9

Please sign in to comment.