github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/edit/insert_api_test.go (about) 1 package edit 2 3 import ( 4 "testing" 5 6 "src.elv.sh/pkg/cli/term" 7 ) 8 9 func TestInsert_Abbr(t *testing.T) { 10 f := setup() 11 defer f.Cleanup() 12 13 evals(f.Evaler, `edit:abbr = [&x=full]`) 14 f.TTYCtrl.Inject(term.K('x'), term.K('\n')) 15 16 if code := <-f.codeCh; code != "full" { 17 t.Errorf("abbreviation expanded to %q, want %q", code, "full") 18 } 19 } 20 21 func TestInsert_Binding(t *testing.T) { 22 f := setup() 23 defer f.Cleanup() 24 25 evals(f.Evaler, 26 `called = 0`, 27 `edit:insert:binding[x] = { called = (+ $called 1) }`) 28 29 f.TTYCtrl.Inject(term.K('x'), term.K('\n')) 30 31 if code := <-f.codeCh; code != "" { 32 t.Errorf("code = %q, want %q", code, "") 33 } 34 if called, _ := f.Evaler.Global().Index("called"); called != 1 { 35 t.Errorf("called = %v, want 1", called) 36 } 37 } 38 39 func TestInsert_QuotePaste(t *testing.T) { 40 f := setup() 41 defer f.Cleanup() 42 43 evals(f.Evaler, `edit:insert:quote-paste = $true`) 44 45 f.TTYCtrl.Inject( 46 term.PasteSetting(true), 47 term.K('>'), 48 term.PasteSetting(false), 49 term.K('\n')) 50 51 wantCode := `'>'` 52 if code := <-f.codeCh; code != wantCode { 53 t.Errorf("Got code %q, want %q", code, wantCode) 54 } 55 } 56 57 func TestToggleQuotePaste(t *testing.T) { 58 f := setup() 59 defer f.Cleanup() 60 61 evals(f.Evaler, 62 `v0 = $edit:insert:quote-paste`, 63 `edit:toggle-quote-paste`, 64 `v1 = $edit:insert:quote-paste`, 65 `edit:toggle-quote-paste`, 66 `v2 = $edit:insert:quote-paste`) 67 68 v0 := getGlobal(f.Evaler, "v0").(bool) 69 v1 := getGlobal(f.Evaler, "v1").(bool) 70 v2 := getGlobal(f.Evaler, "v2").(bool) 71 if v1 == v0 { 72 t.Errorf("got v1 = v0") 73 } 74 if v2 == v1 { 75 t.Errorf("got v2 = v1") 76 } 77 }