summaryrefslogtreecommitdiffstats
path: root/src/item_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-03-19 01:59:14 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-03-19 01:59:14 +0900
commite70a2a5817586e4e7df0ee1446f609bbd859164a (patch)
tree24ea4cb8865233ec89e2e2828a66727cf0b129f4 /src/item_test.go
parentd80a41bb6d1a507d65885d553a30d4e7dc7d0453 (diff)
Add support for ANSI color codes
Diffstat (limited to 'src/item_test.go')
-rw-r--r--src/item_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/item_test.go b/src/item_test.go
index 372ab4ae..0249edfa 100644
--- a/src/item_test.go
+++ b/src/item_test.go
@@ -3,6 +3,8 @@ package fzf
import (
"sort"
"testing"
+
+ "github.com/junegunn/fzf/src/curses"
)
func TestOffsetSort(t *testing.T) {
@@ -72,3 +74,31 @@ func TestItemRank(t *testing.T) {
t.Error(items)
}
}
+
+func TestColorOffset(t *testing.T) {
+ // ------------ 20 ---- -- ----
+ // ++++++++ ++++++++++
+ // --++++++++-- --++++++++++---
+ item := Item{
+ offsets: []Offset{Offset{5, 15}, Offset{25, 35}},
+ colors: []AnsiOffset{
+ AnsiOffset{[2]int32{0, 20}, ansiState{1, 5, false}},
+ AnsiOffset{[2]int32{22, 27}, ansiState{2, 6, true}},
+ AnsiOffset{[2]int32{30, 32}, ansiState{3, 7, false}},
+ AnsiOffset{[2]int32{33, 40}, ansiState{4, 8, true}}}}
+ // [{[0 5] 9 false} {[5 15] 99 false} {[15 20] 9 false} {[22 25] 10 true} {[25 35] 99 false} {[35 40] 11 true}]
+
+ offsets := item.ColorOffsets(99, false, true)
+ assert := func(idx int, b int32, e int32, c int, bold bool) {
+ o := offsets[idx]
+ if o.offset[0] != b || o.offset[1] != e || o.color != c || o.bold != bold {
+ t.Error(o)
+ }
+ }
+ assert(0, 0, 5, curses.ColUser, false)
+ assert(1, 5, 15, 99, false)
+ assert(2, 15, 20, curses.ColUser, false)
+ assert(3, 22, 25, curses.ColUser+1, true)
+ assert(4, 25, 35, 99, false)
+ assert(5, 35, 40, curses.ColUser+2, true)
+}