| 1 |
package ansi_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/charmbracelet/x/ansi" |
| 7 |
) |
| 8 |
|
| 9 |
var passthroughCases = []struct { |
| 10 |
name string |
| 11 |
seq string |
| 12 |
limit int |
| 13 |
screen string |
| 14 |
tmux string |
| 15 |
}{ |
| 16 |
{ |
| 17 |
name: "empty", |
| 18 |
seq: "", |
| 19 |
screen: "\x1bP\x1b\\", |
| 20 |
tmux: "\x1bPtmux;\x1b\\", |
| 21 |
}, |
| 22 |
{ |
| 23 |
name: "short", |
| 24 |
seq: "hello", |
| 25 |
screen: "\x1bPhello\x1b\\", |
| 26 |
tmux: "\x1bPtmux;hello\x1b\\", |
| 27 |
}, |
| 28 |
{ |
| 29 |
name: "limit", |
| 30 |
seq: "foobarbaz", |
| 31 |
limit: 3, |
| 32 |
screen: "\x1bPfoo\x1b\\\x1bPbar\x1b\\\x1bPbaz\x1b\\", |
| 33 |
tmux: "\x1bPtmux;foobarbaz\x1b\\", |
| 34 |
}, |
| 35 |
{ |
| 36 |
name: "escaped", |
| 37 |
seq: "\x1b]52;c;Zm9vYmFy\x07", |
| 38 |
screen: "\x1bP\x1b]52;c;Zm9vYmFy\x07\x1b\\", |
| 39 |
tmux: "\x1bPtmux;\x1b\x1b]52;c;Zm9vYmFy\x07\x1b\\", |
| 40 |
}, |
| 41 |
} |
| 42 |
|
| 43 |
func TestScreenPassthrough(t *testing.T) { |
| 44 |
for i, tt := range passthroughCases { |
| 45 |
t.Run(tt.name, func(t *testing.T) { |
| 46 |
got := ansi.ScreenPassthrough(tt.seq, tt.limit) |
| 47 |
if got != tt.screen { |
| 48 |
t.Errorf("case: %d, ScreenPassthrough() = %q, want %q", i+1, got, tt.screen) |
| 49 |
} |
| 50 |
}) |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
func TestTmuxPassthrough(t *testing.T) { |
| 55 |
for i, tt := range passthroughCases { |
| 56 |
t.Run(tt.name, func(t *testing.T) { |
| 57 |
got := ansi.TmuxPassthrough(tt.seq) |
| 58 |
if got != tt.tmux { |
| 59 |
t.Errorf("case: %d, TmuxPassthrough() = %q, want %q", i+1, got, tt.tmux) |
| 60 |
} |
| 61 |
}) |
| 62 |
} |
| 63 |
} |