diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2015-07-22 14:19:45 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-07-22 14:19:45 +0900 |
| commit | 5e3cb3a4eaa557b03d0d18a36f983cc6acec6ad1 (patch) | |
| tree | 3205662fa6d6616d036996864ebff7b5623ac599 /src/ansi_test.go | |
| parent | f71ea5f3ea469489fc979ee3c0cd2622d011befd (diff) | |
| download | fzf-5e3cb3a4eaa557b03d0d18a36f983cc6acec6ad1.tar.gz | |
Fix ANSI processor to handle multi-line regions
Diffstat (limited to 'src/ansi_test.go')
| -rw-r--r-- | src/ansi_test.go | 71 |
1 files changed, 58 insertions, 13 deletions
diff --git a/src/ansi_test.go b/src/ansi_test.go index 9f628409..d4d3ca1e 100644 --- a/src/ansi_test.go +++ b/src/ansi_test.go @@ -14,79 +14,89 @@ func TestExtractColor(t *testing.T) { } src := "hello world" + var state *ansiState clean := "\x1b[0m" - check := func(assertion func(ansiOffsets []ansiOffset)) { - output, ansiOffsets := extractColor(&src) + check := func(assertion func(ansiOffsets []ansiOffset, state *ansiState)) { + output, ansiOffsets, newState := extractColor(&src, state) + state = newState if *output != "hello world" { t.Errorf("Invalid output: {}", output) } fmt.Println(src, ansiOffsets, clean) - assertion(ansiOffsets) + assertion(ansiOffsets, state) } - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) > 0 { t.Fail() } }) + state = nil src = "\x1b[0mhello world" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) > 0 { t.Fail() } }) + state = nil src = "\x1b[1mhello world" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) != 1 { t.Fail() } assert(offsets[0], 0, 11, -1, -1, true) }) + state = nil src = "\x1b[1mhello \x1b[mworld" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) != 1 { t.Fail() } assert(offsets[0], 0, 6, -1, -1, true) }) + state = nil src = "\x1b[1mhello \x1b[Kworld" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) != 1 { t.Fail() } assert(offsets[0], 0, 11, -1, -1, true) }) + state = nil src = "hello \x1b[34;45;1mworld" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) != 1 { t.Fail() } assert(offsets[0], 6, 11, 4, 5, true) }) + state = nil src = "hello \x1b[34;45;1mwor\x1b[34;45;1mld" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) != 1 { t.Fail() } assert(offsets[0], 6, 11, 4, 5, true) }) + state = nil src = "hello \x1b[34;45;1mwor\x1b[0mld" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) != 1 { t.Fail() } assert(offsets[0], 6, 9, 4, 5, true) }) + state = nil src = "hello \x1b[34;48;5;233;1mwo\x1b[38;5;161mr\x1b[0ml\x1b[38;5;161md" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) != 3 { t.Fail() } @@ -96,12 +106,47 @@ func TestExtractColor(t *testing.T) { }) // {38,48};5;{38,48} + state = nil src = "hello \x1b[38;5;38;48;5;48;1mwor\x1b[38;5;48;48;5;38ml\x1b[0md" - check(func(offsets []ansiOffset) { + check(func(offsets []ansiOffset, state *ansiState) { if len(offsets) != 2 { t.Fail() } assert(offsets[0], 6, 9, 38, 48, true) assert(offsets[1], 9, 10, 48, 38, true) }) + + src = "hello \x1b[32;1mworld" + check(func(offsets []ansiOffset, state *ansiState) { + if len(offsets) != 1 { + t.Fail() + } + if state.fg != 2 || state.bg != -1 || !state.bold { + t.Fail() + } + assert(offsets[0], 6, 11, 2, -1, true) + }) + + src = "hello world" + check(func(offsets []ansiOffset, state *ansiState) { + if len(offsets) != 1 { + t.Fail() + } + if state.fg != 2 || state.bg != -1 || !state.bold { + t.Fail() + } + assert(offsets[0], 0, 11, 2, -1, true) + }) + + src = "hello \x1b[0;38;5;200;48;5;100mworld" + check(func(offsets []ansiOffset, state *ansiState) { + if len(offsets) != 2 { + t.Fail() + } + if state.fg != 200 || state.bg != 100 || state.bold { + t.Fail() + } + assert(offsets[0], 0, 6, 2, -1, true) + assert(offsets[1], 6, 11, 200, 100, false) + }) } |
