Neovim sign gutter, designed to be mostly VCS agnostic
at experimental_diffthis 161 lines 4.4 kB view raw
1local M = {} 2 3local hunkops = require "vcsigns.hunkops" 4 5-- Minus part doesn't matter for the hunk navigation tests. 6-- 1 7-- 2 A 8-- 3 A 9-- 4 10-- 5 B 11-- 6 B 12-- 7 B 13-- 8 14-- 9 15-- 10 C 16-- 11 17local navigation_test_hunks = { 18 { plus_start = 2, plus_count = 2, minus_start = -1, minus_count = -1 }, 19 { plus_start = 5, plus_count = 3, minus_start = -1, minus_count = -1 }, 20 { plus_start = 10, plus_count = 1, minus_start = -1, minus_count = -1 }, 21} 22 23M.next_hunk = { 24 test_cases = { 25 { lnum = 1, expected_target = 2 }, 26 { lnum = 2, expected_target = 5 }, 27 { lnum = 3, expected_target = 5 }, 28 { lnum = 4, expected_target = 5 }, 29 { lnum = 5, expected_target = 10 }, 30 { lnum = 6, expected_target = 10 }, 31 { lnum = 7, expected_target = 10 }, 32 { lnum = 8, expected_target = 10 }, 33 { lnum = 9, expected_target = 10 }, 34 { lnum = 10, expected_target = nil }, 35 { lnum = 11, expected_target = nil }, 36 { lnum = 1, expected_target = 5, count = 2 }, 37 { lnum = 2, expected_target = 10, count = 2 }, 38 { lnum = 6, expected_target = 10, count = 2 }, 39 }, 40 test = function(case) 41 local hunk = 42 hunkops.next_hunk(case.lnum, navigation_test_hunks, case.count or 1) 43 if not hunk then 44 if case.expected_target == nil then 45 return -- This is expected, no hunk found. 46 end 47 error "No hunk found" 48 end 49 assert( 50 hunk.plus_start == case.expected_target, 51 string.format( 52 "Expected hunk at %d, got %d", 53 case.expected_target, 54 hunk.plus_start 55 ) 56 ) 57 end, 58} 59 60M.prev_hunk = { 61 test_cases = { 62 { lnum = 1, expected_target = nil }, 63 { lnum = 2, expected_target = nil }, 64 { lnum = 3, expected_target = nil }, 65 { lnum = 4, expected_target = 2 }, 66 { lnum = 5, expected_target = 2 }, 67 { lnum = 6, expected_target = 2 }, 68 { lnum = 7, expected_target = 2 }, 69 { lnum = 8, expected_target = 5 }, 70 { lnum = 9, expected_target = 5 }, 71 { lnum = 10, expected_target = 5 }, 72 { lnum = 11, expected_target = 10 }, 73 { lnum = 11, expected_target = 5, count = 2 }, 74 { lnum = 10, expected_target = 2, count = 2 }, 75 { lnum = 4, expected_target = 2, count = 2 }, 76 }, 77 test = function(case) 78 local hunk = 79 hunkops.prev_hunk(case.lnum, navigation_test_hunks, case.count or 1) 80 if not hunk then 81 if case.expected_target == nil then 82 return -- This is expected, no hunk found. 83 end 84 error "No hunk found" 85 end 86 assert( 87 hunk.plus_start == case.expected_target, 88 string.format( 89 "Expected hunk at %d, got %d", 90 case.expected_target, 91 hunk.plus_start 92 ) 93 ) 94 end, 95} 96 97M.cur_hunk = { 98 test_cases = { 99 { lnum = 2, expected_target = 2 }, 100 { lnum = 3, expected_target = 2 }, 101 { lnum = 4, expected_target = nil }, 102 { lnum = 5, expected_target = 5 }, 103 { lnum = 6, expected_target = 5 }, 104 { lnum = 7, expected_target = 5 }, 105 { lnum = 8, expected_target = nil }, 106 { lnum = 9, expected_target = nil }, 107 { lnum = 10, expected_target = 10 }, 108 { lnum = 11, expected_target = nil }, 109 }, 110 test = function(case) 111 local hunk = hunkops.cur_hunk(case.lnum, navigation_test_hunks) 112 if not hunk then 113 if case.expected_target == nil then 114 return -- This is expected, no hunk found. 115 end 116 error "No hunk found" 117 end 118 assert( 119 hunk.plus_start == case.expected_target, 120 string.format( 121 "Expected hunk at %d, got %d", 122 case.expected_target, 123 hunk.plus_start 124 ) 125 ) 126 end, 127} 128 129local deletion_test_hunks = { 130 { plus_start = 0, plus_count = 0, minus_start = -1, minus_count = -1 }, 131 { plus_start = 4, plus_count = 0, minus_start = -1, minus_count = -1 }, 132} 133 134M.cur_hunk_deletions = { 135 test_cases = { 136 { lnum = 1, expected_target = 0 }, 137 { lnum = 2, expected_target = nil }, 138 { lnum = 3, expected_target = nil }, 139 { lnum = 4, expected_target = 4 }, 140 { lnum = 5, expected_target = nil }, 141 }, 142 test = function(case) 143 local hunk = hunkops.cur_hunk(case.lnum, deletion_test_hunks) 144 if not hunk then 145 if case.expected_target == nil then 146 return -- This is expected, no hunk found. 147 end 148 error "No hunk found" 149 end 150 assert( 151 hunk.plus_start == case.expected_target, 152 string.format( 153 "Expected hunk at %d, got %d", 154 case.expected_target, 155 hunk.plus_start 156 ) 157 ) 158 end, 159} 160 161return M