micro/internal/config/rtfiles_test.go
Dmytro Maluka c5d32f625b Ignore user-defined runtime files in buffer test and rtfiles test
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.
2024-04-03 03:44:15 +02:00

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)
}