Files
oddmu/replace_cmd_test.go
Alex Schroeder 99a863771f Refactored tests
Each test now uses a separate directory in testdata. When cleaning up
the directory, all the index entries are properly removed, too.
2023-09-26 18:17:15 +02:00

39 lines
822 B
Go

package main
import (
"bytes"
"github.com/google/subcommands"
"github.com/stretchr/testify/assert"
"testing"
)
func TestReplaceCmd(t *testing.T) {
cleanup(t, "testdata/replace")
index.load()
p := &Page{Name: "testdata/replace/pluto", Body: []byte(`# Pluto
Out there is a rock
And more rocks uncountable
You are no planet`)}
p.save()
r := `--- testdata/replace/pluto.md~
+++ testdata/replace/pluto.md
@@ -1,4 +1,4 @@
# Pluto
Out there is a rock
And more rocks uncountable
-You are no planet
\ No newline at end of file
+You are planetoid
\ No newline at end of file
1 change was made.
This is a dry run. Use -confirm to make it happen.
`
b := new(bytes.Buffer)
s := replaceCli(b, false, []string{`\bno planet`, `planetoid`})
assert.Equal(t, subcommands.ExitSuccess, s)
assert.Equal(t, r, b.String())
}