Fix failing unit tests on ANSI attributes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent 1fc5659 · Browse files · 2 files·+21 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+21 added−11 removed
- other:+21 added−11 removed
Provenance
- Commit
3b5ae0f- Tree
ef25de8- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
1fc5659
2 files changed+21 added−11 removed
modified:src/ansi_test.go+11 added-5 removed
1 unmodified line2 3 import (4 "fmt"5 "testing"6+7+ "github.com/junegunn/fzf/src/curses"8 )9 10 func TestExtractColor(t *testing.T) {11 assert := func(offset ansiOffset, b int32, e int32, fg int, bg int, bold bool) {12+ var attr curses.Attr13+ if bold {14+ attr = curses.Bold15+ }16 if offset.offset[0] != b || offset.offset[1] != e ||11- offset.color.fg != fg || offset.color.bg != bg || offset.color.bold != bold {12- t.Error(offset, b, e, fg, bg, bold)17+ offset.color.fg != fg || offset.color.bg != bg || offset.color.attr != attr {18+ t.Error(offset, b, e, fg, bg, attr)19 }20 }21 22 src := "hello world"103 unmodified lines126 check(func(offsets *[]ansiOffset, state *ansiState) {127 if len(*offsets) != 1 {128 t.Fail()129 }124- if state.fg != 2 || state.bg != -1 || !state.bold {130+ if state.fg != 2 || state.bg != -1 || state.attr == 0 {131 t.Fail()132 }133 assert((*offsets)[0], 6, 11, 2, -1, true)134 })2 unmodified lines137 check(func(offsets *[]ansiOffset, state *ansiState) {138 if len(*offsets) != 1 {139 t.Fail()140 }135- if state.fg != 2 || state.bg != -1 || !state.bold {141+ if state.fg != 2 || state.bg != -1 || state.attr == 0 {142 t.Fail()143 }144 assert((*offsets)[0], 0, 11, 2, -1, true)145 })2 unmodified lines148 check(func(offsets *[]ansiOffset, state *ansiState) {149 if len(*offsets) != 2 {150 t.Fail()151 }146- if state.fg != 200 || state.bg != 100 || state.bold {152+ if state.fg != 200 || state.bg != 100 || state.attr > 0 {153 t.Fail()154 }155 assert((*offsets)[0], 0, 6, 2, -1, true)156 assert((*offsets)[1], 6, 11, 200, 100, false)2 unmodified linesmodified:src/result_test.go+10 added-6 removed
95 unmodified lines96 offsets := []Offset{Offset{5, 15}, Offset{25, 35}}97 item := Result{98 item: &Item{99 colors: &[]ansiOffset{100- ansiOffset{[2]int32{0, 20}, ansiState{1, 5, false}},101- ansiOffset{[2]int32{22, 27}, ansiState{2, 6, true}},102- ansiOffset{[2]int32{30, 32}, ansiState{3, 7, false}},103- ansiOffset{[2]int32{33, 40}, ansiState{4, 8, true}}}}}100+ ansiOffset{[2]int32{0, 20}, ansiState{1, 5, 0}},101+ ansiOffset{[2]int32{22, 27}, ansiState{2, 6, curses.Bold}},102+ ansiOffset{[2]int32{30, 32}, ansiState{3, 7, 0}},103+ ansiOffset{[2]int32{33, 40}, ansiState{4, 8, curses.Bold}}}}}104 // [{[0 5] 9 false} {[5 15] 99 false} {[15 20] 9 false} {[22 25] 10 true} {[25 35] 99 false} {[35 40] 11 true}]105 106- colors := item.colorOffsets(offsets, 99, false, true)106+ colors := item.colorOffsets(offsets, 99, 0, true)107 assert := func(idx int, b int32, e int32, c int, bold bool) {108+ var attr curses.Attr109+ if bold {110+ attr = curses.Bold111+ }112 o := colors[idx]109- if o.offset[0] != b || o.offset[1] != e || o.color != c || o.bold != bold {113+ if o.offset[0] != b || o.offset[1] != e || o.color != c || o.attr != attr {114 t.Error(o)115 }116 }117 assert(0, 0, 5, curses.ColUser, false)6 unmodified lines