Skip to content
Myr

Add test cases for header and fix corner cases

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 f469c25 · Browse files · 3 files+71 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+71 added−6 removed

  • tests:+55 added−0 removed
  • other:+16 added−6 removed

3 files+71 added−6 removed

modified:src/options.go+4 added
782 unmodified lines
783 }784 }785 }786787 if opts.HeaderLines < 0 {788 errorExit("header lines must be a non-negative integer")789 }790791 // Change default actions for CTRL-N / CTRL-P when --history is used792 if opts.History != nil {793 if _, prs := keymap[curses.CtrlP]; !prs {794 keymap[curses.CtrlP] = actPreviousHistory
35 unmodified lines
modified:src/terminal.go+12 added-6 removed
375 unmodified lines
376func (t *Terminal) printHeader() {377 if len(t.header) == 0 {378 return379 }380 max := C.MaxY()381 for idx, lineStr := range t.header {382 if !t.reverse {383 idx = len(t.header) - idx - 1384 }385 line := idx + 2386 if t.inlineInfo {387 line -= 1388 }389 if line >= max {390 break391 }392 trimmed, colors := extractColor(&lineStr)393 item := &Item{394 text: trimmed,395 index: 0,396 colors: colors,397 rank: Rank{0, 0, 0}}398391 line := idx + 2392 if t.inlineInfo {393 line -= 1394 }399 t.move(line, 2, true)400 t.printHighlighted(item, false, C.ColHeader, 0, false)401 }402}
593 unmodified lines
996 if count-t.offset < height {997 t.offset = util.Max(0, count-height)998 t.cy = util.Constrain(t.offset+diffpos, 0, count-1)999 }1000 t.offset = util.Max(0, t.offset)1001}10021003func (t *Terminal) vmove(o int) {1004 if t.reverse {
20 unmodified lines
1025 return t.cy == o1026}10271028func (t *Terminal) maxItems() int {1029 max := C.MaxY() - 2 - len(t.header)1030 if t.inlineInfo {1025 return C.MaxY() - 1 - len(t.header)1031 max += 11032 }1027 return C.MaxY() - 2 - len(t.header)1033 return util.Max(max, 0)1034}
modified:test/test_go.rb+55 added
646 unmodified lines
647 tmux.send_keys :PgDn648 tmux.until { |lines| lines[-10].start_with? '>' }649 end650651 def test_header_lines652 tmux.send_keys "seq 100 | #{fzf '--header-lines=10 -q 5'}", :Enter653 2.times do654 tmux.until do |lines|655 lines[-2].include?('/90') &&656 lines[-3] == ' 1' &&657 lines[-4] == ' 2' &&658 lines[-13] == '> 15'659 end660 tmux.send_keys :Down661 end662 tmux.send_keys :Enter663 assert_equal '15', readonce.chomp664 end665666 def test_header_lines_reverse667 tmux.send_keys "seq 100 | #{fzf '--header-lines=10 -q 5 --reverse'}", :Enter668 2.times do669 tmux.until do |lines|670 lines[1].include?('/90') &&671 lines[2] == ' 1' &&672 lines[3] == ' 2' &&673 lines[12] == '> 15'674 end675 tmux.send_keys :Up676 end677 tmux.send_keys :Enter678 assert_equal '15', readonce.chomp679 end680681 def test_header_lines_overflow682 tmux.send_keys "seq 100 | #{fzf '--header-lines=200'}", :Enter683 tmux.until { |lines| lines[-2].include?('0/0') }684 tmux.send_keys :Enter685 assert_equal '', readonce.chomp686 end687688 def test_header_file689 tmux.send_keys "seq 100 | #{fzf "--header-file <(head -5 #{__FILE__})"}", :Enter690 header = File.readlines(__FILE__).take(5).map(&:strip)691 tmux.until do |lines|692 lines[-2].include?('100/100') &&693 lines[-7..-3].map(&:strip) == header694 end695 end696697 def test_header_file_reverse698 tmux.send_keys "seq 100 | #{fzf "--header-file <(head -5 #{__FILE__}) --reverse"}", :Enter699 header = File.readlines(__FILE__).take(5).map(&:strip)700 tmux.until do |lines|701 lines[1].include?('100/100') &&702 lines[2..6].map(&:strip) == header703 end704 end705706private707 def writelines path, lines708 File.unlink path while File.exists? path709 File.open(path, 'w') { |f| f << lines.join($/) }
237 unmodified lines