c5d32f625b
When initializing runtime files (syntax files etc) in tests, initialize built-in runtime files only, to ensure that the tests are not affected by whatever is in ~/.config/micro/ on the test machine. micro_test.go already ensures that, by using its own temporary directory as an (empty) config directory. So we only need to fix buffer_test.go and rtfiles_test.go. In those tests, don't repeat the same dance with a temporary directory, instead just ignore the config directory.
43 lines
981 B
Go
43 lines
981 B
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func init() {
|
|
InitRuntimeFiles(false)
|
|
}
|
|
|
|
func TestAddFile(t *testing.T) {
|
|
AddRuntimeFile(RTPlugin, memoryFile{"foo.lua", []byte("hello world\n")})
|
|
AddRuntimeFile(RTSyntax, memoryFile{"bar", []byte("some syntax file\n")})
|
|
|
|
f1 := FindRuntimeFile(RTPlugin, "foo.lua")
|
|
assert.NotNil(t, f1)
|
|
assert.Equal(t, "foo.lua", f1.Name())
|
|
data, err := f1.Data()
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, []byte("hello world\n"), data)
|
|
|
|
f2 := FindRuntimeFile(RTSyntax, "bar")
|
|
assert.NotNil(t, f2)
|
|
assert.Equal(t, "bar", f2.Name())
|
|
data, err = f2.Data()
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, []byte("some syntax file\n"), data)
|
|
}
|
|
|
|
func TestFindFile(t *testing.T) {
|
|
f := FindRuntimeFile(RTSyntax, "go")
|
|
assert.NotNil(t, f)
|
|
assert.Equal(t, "go", f.Name())
|
|
data, err := f.Data()
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, []byte("filetype: go"), data[:12])
|
|
|
|
e := FindRuntimeFile(RTSyntax, "foobar")
|
|
assert.Nil(t, e)
|
|
}
|