File: vim_test.go

package info (click to toggle)
golang-github-gcla-gowid 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,456 kB
  • sloc: makefile: 4
file content (64 lines) | stat: -rw-r--r-- 1,589 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2019-2022 Graham Clark. All rights reserved.  Use of this source
// code is governed by the MIT license that can be found in the LICENSE
// file.

package vim

import (
	"fmt"
	"strings"
	"testing"

	tcell "github.com/gdamore/tcell/v2"
	"github.com/stretchr/testify/assert"
)

type keytest struct {
	str string
	key KeyPress
}

func TestVim1(t *testing.T) {

	for _, kt := range []keytest{
		{"<Up>", KeyPressUp},
		{"<Down>", KeyPressDown},
		{"Z", NewSimpleKeyPress('Z')},
		{"z", NewSimpleKeyPress('z')},
		{"<C-f>", NewKeyPress(tcell.KeyRune, 'f', tcell.ModCtrl)},
		{"<A-|>", NewKeyPress(tcell.KeyRune, '|', tcell.ModAlt)},
		{"<S-\">", NewKeyPress(tcell.KeyRune, '"', tcell.ModShift)},
		{"<S-`>", NewKeyPress(tcell.KeyRune, '`', tcell.ModShift)},
		{"`", NewSimpleKeyPress('`')},
		{"<Space>", NewSimpleKeyPress(' ')},
		{"<Esc>", KeyPressEscape},
		{"<Right>", KeyPressRight},
		{"<PgDn>", KeyPressPgDn},
		{"<Esc>", KeyPressEscape},
		{"<F4>", KeyPressF4},
		{"<F12>", KeyPressF12},
		{"<Lt>", NewKeyPress(tcell.KeyRune, '<', 0)},
	} {
		res := VimStringToKeys(kt.str)
		assert.Equal(t, 1, len(res))
		assert.Equal(t, kt.key, res[0])

		str := fmt.Sprintf("%v", kt.key)
		assert.Equal(t, kt.str, str)

		if strings.Contains(kt.str, "<") {
			res = VimStringToKeys(strings.ToLower(kt.str))
			assert.Equal(t, 1, len(res))
			assert.Equal(t, kt.key, res[0])

			str = fmt.Sprintf("%v", kt.key)
			assert.Equal(t, kt.str, str)
		}
	}
}

//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: