File: insert_api_test.go

package info (click to toggle)
elvish 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,372 kB
  • sloc: javascript: 236; sh: 130; python: 104; makefile: 88; xml: 9
file content (73 lines) | stat: -rw-r--r-- 1,526 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
package edit

import (
	"testing"

	"src.elv.sh/pkg/cli/term"
)

func TestInsert_Abbr(t *testing.T) {
	f := setup(t)

	evals(f.Evaler, `set edit:abbr = [&x=full]`)
	f.TTYCtrl.Inject(term.K('x'), term.K('\n'))

	if code := <-f.codeCh; code != "full" {
		t.Errorf("abbreviation expanded to %q, want %q", code, "full")
	}
}

func TestInsert_Binding(t *testing.T) {
	f := setup(t)

	evals(f.Evaler,
		`var called = 0`,
		`set edit:insert:binding[x] = { set called = (+ $called 1) }`)

	f.TTYCtrl.Inject(term.K('x'), term.K('\n'))

	if code := <-f.codeCh; code != "" {
		t.Errorf("code = %q, want %q", code, "")
	}
	if called, _ := f.Evaler.Global().Index("called"); called != 1 {
		t.Errorf("called = %v, want 1", called)
	}
}

func TestInsert_QuotePaste(t *testing.T) {
	f := setup(t)

	evals(f.Evaler, `set edit:insert:quote-paste = $true`)

	f.TTYCtrl.Inject(
		term.PasteSetting(true),
		term.K('>'),
		term.PasteSetting(false),
		term.K('\n'))

	wantCode := `'>'`
	if code := <-f.codeCh; code != wantCode {
		t.Errorf("Got code %q, want %q", code, wantCode)
	}
}

func TestToggleQuotePaste(t *testing.T) {
	f := setup(t)

	evals(f.Evaler,
		`var v0 = $edit:insert:quote-paste`,
		`edit:toggle-quote-paste`,
		`var v1 = $edit:insert:quote-paste`,
		`edit:toggle-quote-paste`,
		`var v2 = $edit:insert:quote-paste`)

	v0 := getGlobal(f.Evaler, "v0").(bool)
	v1 := getGlobal(f.Evaler, "v1").(bool)
	v2 := getGlobal(f.Evaler, "v2").(bool)
	if v1 == v0 {
		t.Errorf("got v1 = v0")
	}
	if v2 == v1 {
		t.Errorf("got v2 = v1")
	}
}