d67ce731ed
Adding InitPlugins() to tests has caused noisy error logs when running the buffer_test.go test (although the test result is still PASS): 2024/03/23 15:14:30 Plugin does not exist: autoclose at autoclose : &{autoclose autoclose <nil> [runtime/plugins/autoclose/autoclose.lua] false true} 2024/03/23 15:14:30 Plugin does not exist: comment at comment : &{comment comment <nil> [runtime/plugins/comment/comment.lua] false true} 2024/03/23 15:14:30 Plugin does not exist: diff at diff : &{diff diff <nil> [runtime/plugins/diff/diff.lua] false true} 2024/03/23 15:14:30 Plugin does not exist: ftoptions at ftoptions : &{ftoptions ftoptions <nil> [runtime/plugins/ftoptions/ftoptions.lua] false true} ... These errors are caused simply by the fact that plugins are initialized but not loaded. Adding config.LoadAllPlugins() to buffer_test.go "fixes" this problem. However, at the moment it doesn't seem a good idea to load plugins in buffer_test.go, since buffer_test.go doesn't properly initialize Lua. It only does ulua.L = lua.NewState() but doesn't do the other stuff that init() in cmd/micro/initlua.go does. As a result, plugins will not be able to do anything correctly. So in order to initialize Lua correctly we need to be inside cmd/micro/, so we cannot do it in buffer_test.go or any other tests except micro_test.go.
43 lines
976 B
Go
43 lines
976 B
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func init() {
|
|
InitRuntimeFiles()
|
|
}
|
|
|
|
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)
|
|
}
|