Skip to content
Myr

Add mouse wheel tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jason Han · committed by Junegunn Choi · parent 9e4f8e7 · Browse files · 1 file+69 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+69 added−0 removed

  • other:+69 added−0 removed

1 file+69 added−0 removed

modified:src/tui/light_test.go+69 added
1 unmodified line
23import (4 "fmt"5 "os"6 "strings"7 "testing"8 "unicode"9)10
339 unmodified lines
350 assertEscSequence("\x1b[13~", "f3")351 assertEscSequence("\x1b[14~", "f4")352353}354355func TestLightRendererScrollWheel(t *testing.T) {356 tty_file, _ := os.Open("")357 renderer, _ := NewLightRenderer(358 "", tty_file, &ColorTheme{}, true, true, 0, false, true,359 func(h int) int { return h })360361 light_renderer := renderer.(*LightRenderer)362363 assertScroll := func(sequence string, scroll int, mods string) {364 bytes := []byte(sequence)365 light_renderer.buffer = bytes366367 sz := 1368 event := light_renderer.escSequence(&sz)369 me := event.MouseEvent370 if event.Type != Mouse || me == nil {371 t.Errorf("sequence: %q | got %s, want a Mouse event", sequence, event.Type.String())372 return373 }374 got := ""375 if me.Ctrl {376 got += "ctrl-"377 }378 if me.Alt {379 got += "alt-"380 }381 if me.Shift {382 got += "shift-"383 }384 got = strings.TrimSuffix(got, "-")385 if me.S != scroll || got != mods || me.Down {386 t.Errorf(387 "sequence: %q | scroll=%d mods=%q down=%v != scroll=%d mods=%q down=false",388 sequence, me.S, got, me.Down, scroll, mods)389 }390 }391392 assertScroll("\x1b[<64;1;1M", 1, "") // up393 assertScroll("\x1b[<65;1;1M", -1, "") // down394 assertScroll("\x1b[<66;1;1M", 0, "") // left (ignored)395 assertScroll("\x1b[<67;1;1M", 0, "") // right (ignored)396397 assertScroll("\x1b[<68;1;1M", 1, "shift") // shift + up398 assertScroll("\x1b[<69;1;1M", -1, "shift") // shift + down399 assertScroll("\x1b[<70;1;1M", 0, "shift") // shift + left (ignored)400 assertScroll("\x1b[<71;1;1M", 0, "shift") // shift + right (ignored)401402 assertScroll("\x1b[<72;1;1M", 1, "alt") // alt + up403 assertScroll("\x1b[<73;1;1M", -1, "alt") // alt + down404 assertScroll("\x1b[<74;1;1M", 0, "alt") // alt + left (ignored)405 assertScroll("\x1b[<75;1;1M", 0, "alt") // alt + right (ignored)406407 assertScroll("\x1b[<80;1;1M", 1, "ctrl") // ctrl + up408 assertScroll("\x1b[<81;1;1M", -1, "ctrl") // ctrl + down409 assertScroll("\x1b[<82;1;1M", 0, "ctrl") // ctrl + left (ignored)410 assertScroll("\x1b[<83;1;1M", 0, "ctrl") // ctrl + right (ignored)411412 assertScroll("\x1b[<84;1;1M", 1, "ctrl-shift") // ctrl+shift + up413 assertScroll("\x1b[<85;1;1M", -1, "ctrl-shift") // ctrl+shift + down414 assertScroll("\x1b[<86;1;1M", 0, "ctrl-shift") // ctrl+shift + left (ignored)415 assertScroll("\x1b[<87;1;1M", 0, "ctrl-shift") // ctrl+shift + right (ignored)416417 assertScroll("\x1b[<92;1;1M", 1, "ctrl-alt-shift") // ctrl+alt+shift + up418 assertScroll("\x1b[<93;1;1M", -1, "ctrl-alt-shift") // ctrl+alt+shift + down419 assertScroll("\x1b[<94;1;1M", 0, "ctrl-alt-shift") // ctrl+alt+shift + left (ignored)420 assertScroll("\x1b[<95;1;1M", 0, "ctrl-alt-shift") // ctrl+alt+shift + right (ignored)421}