Skip to content

Commit

Permalink
chore(test): add mouse, copy, and hyperlink tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jan 31, 2023
1 parent 7fdb086 commit b4a0113
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion screen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ import (
"testing"
)

type testEnv struct {}

func (te testEnv) Environ() []string {
return []string{"TERM=xterm-256color"}
}

func (te testEnv) Getenv(key string) string {
if key == "TERM" {
return "xterm-256color"
}
return ""
}

func tempOutput(t *testing.T) *Output {
t.Helper()

Expand All @@ -16,7 +29,7 @@ func tempOutput(t *testing.T) *Output {
t.Fatal(err)
}

return NewOutput(f, WithProfile(TrueColor))
return NewOutput(f, WithEnvironment(testEnv{}), WithProfile(TrueColor))
}

func verify(t *testing.T, o *Output, exp string) {
Expand Down Expand Up @@ -263,8 +276,50 @@ func TestDisableMouseAllMotion(t *testing.T) {
verify(t, o, "\x1b[?1003l")
}

func TestEnableMouseExtendedMode(t *testing.T) {
o := tempOutput(t)
o.EnableMouseExtendedMode()
verify(t, o, "\x1b[?1006h")
}

func TestDisableMouseExtendedMode(t *testing.T) {
o := tempOutput(t)
o.DisableMouseExtendedMode()
verify(t, o, "\x1b[?1006l")
}

func TestEnableMousePixelsMode(t *testing.T) {
o := tempOutput(t)
o.EnableMousePixelsMode()
verify(t, o, "\x1b[?1016h")
}

func TestDisableMousePixelsMode(t *testing.T) {
o := tempOutput(t)
o.DisableMousePixelsMode()
verify(t, o, "\x1b[?1016l")
}

func TestSetWindowTitle(t *testing.T) {
o := tempOutput(t)
o.SetWindowTitle("test")
verify(t, o, "\x1b]2;test\a")
}

func TestCopyClipboard(t *testing.T) {
o := tempOutput(t)
o.Copy("hello")
verify(t, o, "\x1b]52;c;aGVsbG8=\a")
}

func TestCopyPrimary(t *testing.T) {
o := tempOutput(t)
o.CopyPrimary("hello")
verify(t, o, "\x1b]52;p;aGVsbG8=\a")
}

func TestHyperlink(t *testing.T) {
o := tempOutput(t)
o.WriteString(o.Hyperlink("http://example.com", "example"))
verify(t, o, "\x1b]8;;http://example.com\x1b\\example\x1b]8;;\x1b\\")
}

0 comments on commit b4a0113

Please sign in to comment.