@@ -2004,40 +2004,100 @@ func Test_search_offset()
2004
2004
call assert_equal([1, 7], [line('.'), col('.')])
2005
2005
2006
2006
" with cursor at the beginning of the file, use /s+1
2007
-
call cursor(1, 1)
2008
-
exe "normal /two/s+1\<CR>"
2009
-
call assert_equal([1, 6], [line('.'), col('.')])
2007
+
" '+' without a digit is the same as +1, and 'b' is an alias for 's'
2008
+
for searchcmd in ['/two/s+1', '/two/s+', '/two/b+1', '/two/b+', '/']
2009
+
call cursor(1, 1)
2010
+
exe $"normal {searchcmd}\<CR>"
2011
+
call assert_equal([1, 6], [line('.'), col('.')], searchcmd)
2012
+
call assert_equal('/two/s+1', Screenline(&lines)->trim(), searchcmd)
2013
+
endfor
2014
+
2015
+
" repeat the same search pattern with different offsets
2016
+
for [offset, col] in [['s', 5], ['e-1', 6], ['s+2', 7], ['s-2', 3], ['', 5]]
2017
+
let searchcmd = $'//{offset}'
2018
+
call cursor(1, 1)
2019
+
exe $"normal {searchcmd}\<CR>"
2020
+
call assert_equal([1, col], [line('.'), col('.')], searchcmd)
2021
+
call assert_equal(col == 5 ? '/two' : $'/two/{offset}',
2022
+
\ Screenline(&lines)->trim(), searchcmd)
2023
+
endfor
2010
2024
2011
2025
" with cursor at the end of the file, use /e-1
2012
-
call cursor(2, 10)
2013
-
exe "normal ?three?e-1\<CR>"
2014
-
call assert_equal([2, 4], [line('.'), col('.')])
2026
+
" '-' without a digit is the same as -1
2027
+
for searchcmd in ['?three?e-1', '?three?e-', '?']
2028
+
call cursor(2, 10)
2029
+
exe $"normal {searchcmd}\<CR>"
2030
+
call assert_equal([2, 4], [line('.'), col('.')], searchcmd)
2031
+
call assert_equal('?three?e-1', Screenline(&lines)->trim(), searchcmd)
2032
+
endfor
2033
+
2034
+
" repeat the same search pattern with different offsets
2035
+
for [offset, col] in [['e', 5], ['s+1', 2], ['e-2', 3], ['e+2', 7], ['', 1]]
2036
+
let searchcmd = $'??{offset}'
2037
+
call cursor(2, 10)
2038
+
exe $"normal {searchcmd}\<CR>"
2039
+
call assert_equal([2, col], [line('.'), col('.')], searchcmd)
2040
+
call assert_equal(col == 1 ? '?three' : $'?three?{offset}',
2041
+
\ Screenline(&lines)->trim(), searchcmd)
2042
+
endfor
2015
2043
2016
2044
" line offset - after the last line
2017
-
call cursor(1, 1)
2018
-
exe "normal /three/+1\<CR>"
2019
-
call assert_equal([2, 1], [line('.'), col('.')])
2045
+
" '+' without a digit and '1' without a sign are the same as +1
2046
+
for searchcmd in ['/three/+1', '/three/+', '/three/1', '/']
2047
+
call cursor(1, 1)
2048
+
exe $"normal {searchcmd}\<CR>"
2049
+
call assert_equal([2, 1], [line('.'), col('.')], searchcmd)
2050
+
call assert_equal('/three/+1', Screenline(&lines)->trim(), searchcmd)
2051
+
endfor
2052
+
2053
+
" repeat the same search pattern with different line offsets
2054
+
for [offset, lnum] in [['+0', 2], ['-1', 1], ['+2', 2], ['-2', 1]]
2055
+
let searchcmd = $'//{offset}'
2056
+
call cursor(1, 1)
2057
+
exe $"normal {searchcmd}\<CR>"
2058
+
call assert_equal([lnum, 1], [line('.'), col('.')], searchcmd)
2059
+
call assert_equal($'/three/{offset}',
2060
+
\ Screenline(&lines)->trim(), searchcmd)
2061
+
endfor
2020
2062
2021
2063
" line offset - before the first line
2022
-
call cursor(2, 1)
2023
-
exe "normal ?one?-1\<CR>"
2024
-
call assert_equal([1, 1], [line('.'), col('.')])
2064
+
" '-' without a digit is the same as -1
2065
+
for searchcmd in ['?one?-1', '?one?-', '?']
2066
+
call cursor(2, 1)
2067
+
exe $"normal {searchcmd}\<CR>"
2068
+
call assert_equal([1, 1], [line('.'), col('.')], searchcmd)
2069
+
call assert_equal('?one?-1', Screenline(&lines)->trim(), searchcmd)
2070
+
endfor
2071
+
2072
+
" repeat the same search pattern with different line offsets
2073
+
for [offset, lnum] in [['+0', 1], ['+1', 2], ['-2', 1], ['+2', 2]]
2074
+
let searchcmd = $'??{offset}'
2075
+
call cursor(2, 1)
2076
+
exe $"normal {searchcmd}\<CR>"
2077
+
call assert_equal([lnum, 1], [line('.'), col('.')], searchcmd)
2078
+
call assert_equal($'?one?{offset}',
2079
+
\ Screenline(&lines)->trim(), searchcmd)
2080
+
endfor
2025
2081
2026
2082
" character offset - before the first character in the file
2027
2083
call cursor(2, 1)
2028
2084
exe "normal ?one?s-1\<CR>"
2029
2085
call assert_equal([1, 1], [line('.'), col('.')])
2086
+
call assert_equal('?one?s-1', Screenline(&lines)->trim())
2030
2087
call cursor(2, 1)
2031
2088
exe "normal ?one?e-3\<CR>"
2032
2089
call assert_equal([1, 1], [line('.'), col('.')])
2090
+
call assert_equal('?one?e-3', Screenline(&lines)->trim())
2033
2091
2034
2092
" character offset - after the last character in the file
2035
2093
call cursor(1, 1)
2036
2094
exe "normal /four/s+4\<CR>"
2037
2095
call assert_equal([2, 10], [line('.'), col('.')])
2096
+
call assert_equal('/four/s+4', Screenline(&lines)->trim())
2038
2097
call cursor(1, 1)
2039
2098
exe "normal /four/e+1\<CR>"
2040
2099
call assert_equal([2, 10], [line('.'), col('.')])
2100
+
call assert_equal('/four/e+1', Screenline(&lines)->trim())
2041
2101
2042
2102
bw!
2043
2103
endfunc
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4