erm/app/darktile/hinters/hint_perms_test.go

56 lines
1.3 KiB
Go
Raw Normal View History

2021-07-30 22:29:20 +00:00
package hinters
import (
"testing"
2023-01-16 02:11:07 +00:00
"tuxpa.in/t/erm/app/darktile/termutil"
2021-07-30 22:29:20 +00:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_converter(t *testing.T) {
tests := map[string]string{
"dr-xr-xr-x": "0555",
"-r-xr-xr-x": "0555",
"drwxr-xr-x": "0755",
"-rwxr-xr-x": "0755",
"-r--------": "0400",
"-rw-------": "0600",
}
for perm, octet := range tests {
perm, err := getPermsFromString(perm)
require.NoError(t, err)
assert.Equal(t, octet, perm)
}
}
func Test_perm_hinter_resolves_from_string_and_correctly_activates(t *testing.T) {
hinter := &PermsHinter{}
api := &TestAPI{}
input := "dr-xr-xr-x"
match, offset, length := hinter.Match(input, 3)
assert.Equal(t, true, match)
hinter.Activate(api, input[offset:offset+length], termutil.Position{}, termutil.Position{})
assert.Equal(t, "0555", api.highlighted)
}
func Test_perm_hinter_resolves_from_string_and_correctly_activates_then_cleared(t *testing.T) {
hinter := &PermsHinter{}
api := &TestAPI{}
input := "drwxr-xr-x"
match, offset, length := hinter.Match(input, 3)
assert.Equal(t, true, match)
hinter.Activate(api, input[offset:offset+length], termutil.Position{}, termutil.Position{})
assert.Equal(t, "0755", api.highlighted)
hinter.Deactivate(api)
assert.Equal(t, "", api.highlighted)
}