| 1 |
package config |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/stretchr/testify/assert" |
| 7 |
) |
| 8 |
|
| 9 |
func init() { |
| 10 |
InitRuntimeFiles(false) |
| 11 |
} |
| 12 |
|
| 13 |
func TestAddFile(t *testing.T) { |
| 14 |
AddRuntimeFile(RTPlugin, memoryFile{"foo.lua", []byte("hello world\n")}) |
| 15 |
AddRuntimeFile(RTSyntax, memoryFile{"bar", []byte("some syntax file\n")}) |
| 16 |
|
| 17 |
f1 := FindRuntimeFile(RTPlugin, "foo.lua") |
| 18 |
assert.NotNil(t, f1) |
| 19 |
assert.Equal(t, "foo.lua", f1.Name()) |
| 20 |
data, err := f1.Data() |
| 21 |
assert.Nil(t, err) |
| 22 |
assert.Equal(t, []byte("hello world\n"), data) |
| 23 |
|
| 24 |
f2 := FindRuntimeFile(RTSyntax, "bar") |
| 25 |
assert.NotNil(t, f2) |
| 26 |
assert.Equal(t, "bar", f2.Name()) |
| 27 |
data, err = f2.Data() |
| 28 |
assert.Nil(t, err) |
| 29 |
assert.Equal(t, []byte("some syntax file\n"), data) |
| 30 |
} |
| 31 |
|
| 32 |
func TestFindFile(t *testing.T) { |
| 33 |
f := FindRuntimeFile(RTSyntax, "go") |
| 34 |
assert.NotNil(t, f) |
| 35 |
assert.Equal(t, "go", f.Name()) |
| 36 |
data, err := f.Data() |
| 37 |
assert.Nil(t, err) |
| 38 |
assert.Equal(t, []byte("filetype: go"), data[:12]) |
| 39 |
|
| 40 |
e := FindRuntimeFile(RTSyntax, "foobar") |
| 41 |
assert.Nil(t, e) |
| 42 |
} |