diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2019-03-06 19:05:05 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2019-03-06 19:05:05 +0900 |
| commit | ef577a65094a38f82b2c18dfd3e524eb50748503 (patch) | |
| tree | 54b4cb94db71b31e781ab2405732f812e6dd0df2 /src/ansi_test.go | |
| parent | b7c6838e4574fc07699fd7ea52e893021853cb42 (diff) | |
| download | fzf-ef577a65094a38f82b2c18dfd3e524eb50748503.tar.gz | |
Preserve the original color of each token when using --with-nth with --ansi
Close #1500
Diffstat (limited to 'src/ansi_test.go')
| -rw-r--r-- | src/ansi_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ansi_test.go b/src/ansi_test.go index d94ae931..5acbc131 100644 --- a/src/ansi_test.go +++ b/src/ansi_test.go @@ -2,6 +2,7 @@ package fzf import ( "fmt" + "strings" "testing" "github.com/junegunn/fzf/src/tui" @@ -156,3 +157,31 @@ func TestExtractColor(t *testing.T) { assert((*offsets)[1], 6, 11, 200, 100, false) }) } + +func TestAnsiCodeStringConversion(t *testing.T) { + assert := func(code string, prevState *ansiState, expected string) { + state := interpretCode(code, prevState) + if expected != state.ToString() { + t.Errorf("expected: %s, actual: %s", + strings.Replace(expected, "\x1b[", "\\x1b[", -1), + strings.Replace(state.ToString(), "\x1b[", "\\x1b[", -1)) + } + } + assert("\x1b[m", nil, "\x1b[m") + assert("\x1b[m", &ansiState{attr: tui.Blink}, "\x1b[m") + + assert("\x1b[31m", nil, "\x1b[31;49m") + assert("\x1b[41m", nil, "\x1b[39;41m") + + assert("\x1b[92m", nil, "\x1b[92;49m") + assert("\x1b[102m", nil, "\x1b[39;102m") + + assert("\x1b[31m", &ansiState{fg: 4, bg: 4}, "\x1b[31;44m") + assert("\x1b[1;2;31m", &ansiState{fg: 2, bg: -1, attr: tui.Reverse}, "\x1b[1;2;7;31;49m") + assert("\x1b[38;5;100;48;5;200m", nil, "\x1b[38;5;100;48;5;200m") + assert("\x1b[48;5;100;38;5;200m", nil, "\x1b[38;5;200;48;5;100m") + assert("\x1b[48;5;100;38;2;10;20;30;1m", nil, "\x1b[1;38;2;10;20;30;48;5;100m") + assert("\x1b[48;5;100;38;2;10;20;30;7m", + &ansiState{attr: tui.Dim | tui.Italic, fg: 1, bg: 1}, + "\x1b[2;3;7;38;2;10;20;30;48;5;100m") +} |
