Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 1 | " Tests for various functions. |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame] | 2 | source shared.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 4 | source term_util.vim |
Bram Moolenaar | 4132eb5 | 2020-02-14 16:53:00 +0100 | [diff] [blame] | 5 | source screendump.vim |
Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 6 | |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 7 | " Must be done first, since the alternate buffer must be unset. |
| 8 | func Test_00_bufexists() |
| 9 | call assert_equal(0, bufexists('does_not_exist')) |
| 10 | call assert_equal(1, bufexists(bufnr('%'))) |
| 11 | call assert_equal(0, bufexists(0)) |
| 12 | new Xfoo |
| 13 | let bn = bufnr('%') |
| 14 | call assert_equal(1, bufexists(bn)) |
| 15 | call assert_equal(1, bufexists('Xfoo')) |
| 16 | call assert_equal(1, bufexists(getcwd() . '/Xfoo')) |
| 17 | call assert_equal(1, bufexists(0)) |
| 18 | bw |
| 19 | call assert_equal(0, bufexists(bn)) |
| 20 | call assert_equal(0, bufexists('Xfoo')) |
| 21 | endfunc |
| 22 | |
Bram Moolenaar | 7929651 | 2020-03-22 16:17:14 +0100 | [diff] [blame] | 23 | func Test_has() |
| 24 | call assert_equal(1, has('eval')) |
| 25 | call assert_equal(1, has('eval', 1)) |
| 26 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 27 | if has('unix') |
| 28 | call assert_equal(1, or(has('ttyin'), 1)) |
| 29 | call assert_equal(0, and(has('ttyout'), 0)) |
| 30 | call assert_equal(1, has('multi_byte_encoding')) |
| 31 | endif |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 32 | call assert_equal(1, has('vcon', 1)) |
| 33 | call assert_equal(1, has('mouse_gpm_enabled', 1)) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 34 | |
Bram Moolenaar | 7929651 | 2020-03-22 16:17:14 +0100 | [diff] [blame] | 35 | call assert_equal(0, has('nonexistent')) |
| 36 | call assert_equal(0, has('nonexistent', 1)) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 37 | |
| 38 | " Will we ever have patch 9999? |
| 39 | let ver = 'patch-' .. v:version / 100 .. '.' .. v:version % 100 .. '.9999' |
| 40 | call assert_equal(0, has(ver)) |
Bram Moolenaar | 7929651 | 2020-03-22 16:17:14 +0100 | [diff] [blame] | 41 | endfunc |
| 42 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 43 | func Test_empty() |
| 44 | call assert_equal(1, empty('')) |
| 45 | call assert_equal(0, empty('a')) |
| 46 | |
| 47 | call assert_equal(1, empty(0)) |
| 48 | call assert_equal(1, empty(-0)) |
| 49 | call assert_equal(0, empty(1)) |
| 50 | call assert_equal(0, empty(-1)) |
| 51 | |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 52 | if has('float') |
| 53 | call assert_equal(1, empty(0.0)) |
| 54 | call assert_equal(1, empty(-0.0)) |
| 55 | call assert_equal(0, empty(1.0)) |
| 56 | call assert_equal(0, empty(-1.0)) |
| 57 | call assert_equal(0, empty(1.0/0.0)) |
| 58 | call assert_equal(0, empty(0.0/0.0)) |
| 59 | endif |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 60 | |
| 61 | call assert_equal(1, empty([])) |
| 62 | call assert_equal(0, empty(['a'])) |
| 63 | |
| 64 | call assert_equal(1, empty({})) |
| 65 | call assert_equal(0, empty({'a':1})) |
| 66 | |
| 67 | call assert_equal(1, empty(v:null)) |
| 68 | call assert_equal(1, empty(v:none)) |
| 69 | call assert_equal(1, empty(v:false)) |
| 70 | call assert_equal(0, empty(v:true)) |
| 71 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 72 | if has('channel') |
| 73 | call assert_equal(1, empty(test_null_channel())) |
| 74 | endif |
| 75 | if has('job') |
| 76 | call assert_equal(1, empty(test_null_job())) |
| 77 | endif |
| 78 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 79 | call assert_equal(0, empty(function('Test_empty'))) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 80 | call assert_equal(0, empty(function('Test_empty', [0]))) |
Bram Moolenaar | 7c215c5 | 2020-02-29 13:43:27 +0100 | [diff] [blame] | 81 | |
| 82 | call assert_fails("call empty(test_void())", 'E685:') |
| 83 | call assert_fails("call empty(test_unknown())", 'E685:') |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 84 | endfunc |
| 85 | |
Bram Moolenaar | dd58923 | 2020-02-29 17:38:12 +0100 | [diff] [blame] | 86 | func Test_test_void() |
| 87 | call assert_fails('echo 1 == test_void()', 'E685:') |
| 88 | if has('float') |
| 89 | call assert_fails('echo 1.0 == test_void()', 'E685:') |
| 90 | endif |
| 91 | call assert_fails('let x = json_encode(test_void())', 'E685:') |
| 92 | call assert_fails('let x = copy(test_void())', 'E685:') |
| 93 | call assert_fails('let x = copy([test_void()])', 'E685:') |
| 94 | endfunc |
| 95 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 96 | func Test_len() |
| 97 | call assert_equal(1, len(0)) |
| 98 | call assert_equal(2, len(12)) |
| 99 | |
| 100 | call assert_equal(0, len('')) |
| 101 | call assert_equal(2, len('ab')) |
| 102 | |
| 103 | call assert_equal(0, len([])) |
Bram Moolenaar | 08f4157 | 2020-04-20 16:50:00 +0200 | [diff] [blame] | 104 | call assert_equal(0, len(test_null_list())) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 105 | call assert_equal(2, len([2, 1])) |
| 106 | |
| 107 | call assert_equal(0, len({})) |
Bram Moolenaar | 08f4157 | 2020-04-20 16:50:00 +0200 | [diff] [blame] | 108 | call assert_equal(0, len(test_null_dict())) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 109 | call assert_equal(2, len({'a': 1, 'b': 2})) |
| 110 | |
| 111 | call assert_fails('call len(v:none)', 'E701:') |
| 112 | call assert_fails('call len({-> 0})', 'E701:') |
| 113 | endfunc |
| 114 | |
| 115 | func Test_max() |
| 116 | call assert_equal(0, max([])) |
| 117 | call assert_equal(2, max([2])) |
| 118 | call assert_equal(2, max([1, 2])) |
| 119 | call assert_equal(2, max([1, 2, v:null])) |
| 120 | |
| 121 | call assert_equal(0, max({})) |
| 122 | call assert_equal(2, max({'a':1, 'b':2})) |
| 123 | |
| 124 | call assert_fails('call max(1)', 'E712:') |
| 125 | call assert_fails('call max(v:none)', 'E712:') |
| 126 | endfunc |
| 127 | |
| 128 | func Test_min() |
| 129 | call assert_equal(0, min([])) |
| 130 | call assert_equal(2, min([2])) |
| 131 | call assert_equal(1, min([1, 2])) |
| 132 | call assert_equal(0, min([1, 2, v:null])) |
| 133 | |
| 134 | call assert_equal(0, min({})) |
| 135 | call assert_equal(1, min({'a':1, 'b':2})) |
| 136 | |
| 137 | call assert_fails('call min(1)', 'E712:') |
| 138 | call assert_fails('call min(v:none)', 'E712:') |
| 139 | endfunc |
| 140 | |
Bram Moolenaar | 42ab17b | 2018-05-20 14:11:10 +0200 | [diff] [blame] | 141 | func Test_strwidth() |
| 142 | for aw in ['single', 'double'] |
| 143 | exe 'set ambiwidth=' . aw |
| 144 | call assert_equal(0, strwidth('')) |
| 145 | call assert_equal(1, strwidth("\t")) |
| 146 | call assert_equal(3, strwidth('Vim')) |
| 147 | call assert_equal(4, strwidth(1234)) |
| 148 | call assert_equal(5, strwidth(-1234)) |
| 149 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 150 | call assert_equal(2, strwidth('😉')) |
| 151 | call assert_equal(17, strwidth('Eĥoŝanĝo ĉiuĵaŭde')) |
| 152 | call assert_equal((aw == 'single') ? 6 : 7, strwidth('Straße')) |
Bram Moolenaar | 42ab17b | 2018-05-20 14:11:10 +0200 | [diff] [blame] | 153 | |
| 154 | call assert_fails('call strwidth({->0})', 'E729:') |
| 155 | call assert_fails('call strwidth([])', 'E730:') |
| 156 | call assert_fails('call strwidth({})', 'E731:') |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 157 | if has('float') |
| 158 | call assert_fails('call strwidth(1.2)', 'E806:') |
| 159 | endif |
Bram Moolenaar | 42ab17b | 2018-05-20 14:11:10 +0200 | [diff] [blame] | 160 | endfor |
| 161 | |
| 162 | set ambiwidth& |
| 163 | endfunc |
| 164 | |
Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 165 | func Test_str2nr() |
| 166 | call assert_equal(0, str2nr('')) |
| 167 | call assert_equal(1, str2nr('1')) |
| 168 | call assert_equal(1, str2nr(' 1 ')) |
| 169 | |
| 170 | call assert_equal(1, str2nr('+1')) |
| 171 | call assert_equal(1, str2nr('+ 1')) |
| 172 | call assert_equal(1, str2nr(' + 1 ')) |
| 173 | |
| 174 | call assert_equal(-1, str2nr('-1')) |
| 175 | call assert_equal(-1, str2nr('- 1')) |
| 176 | call assert_equal(-1, str2nr(' - 1 ')) |
| 177 | |
| 178 | call assert_equal(123456789, str2nr('123456789')) |
| 179 | call assert_equal(-123456789, str2nr('-123456789')) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 180 | |
| 181 | call assert_equal(5, str2nr('101', 2)) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 182 | call assert_equal(5, '0b101'->str2nr(2)) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 183 | call assert_equal(5, str2nr('0B101', 2)) |
| 184 | call assert_equal(-5, str2nr('-101', 2)) |
| 185 | call assert_equal(-5, str2nr('-0b101', 2)) |
| 186 | call assert_equal(-5, str2nr('-0B101', 2)) |
| 187 | |
| 188 | call assert_equal(65, str2nr('101', 8)) |
| 189 | call assert_equal(65, str2nr('0101', 8)) |
| 190 | call assert_equal(-65, str2nr('-101', 8)) |
| 191 | call assert_equal(-65, str2nr('-0101', 8)) |
| 192 | |
| 193 | call assert_equal(11259375, str2nr('abcdef', 16)) |
| 194 | call assert_equal(11259375, str2nr('ABCDEF', 16)) |
| 195 | call assert_equal(-11259375, str2nr('-ABCDEF', 16)) |
| 196 | call assert_equal(11259375, str2nr('0xabcdef', 16)) |
| 197 | call assert_equal(11259375, str2nr('0Xabcdef', 16)) |
| 198 | call assert_equal(11259375, str2nr('0XABCDEF', 16)) |
| 199 | call assert_equal(-11259375, str2nr('-0xABCDEF', 16)) |
| 200 | |
Bram Moolenaar | 60a8de2 | 2019-09-15 14:33:22 +0200 | [diff] [blame] | 201 | call assert_equal(1, str2nr("1'000'000", 10, 0)) |
| 202 | call assert_equal(256, str2nr("1'0000'0000", 2, 1)) |
| 203 | call assert_equal(262144, str2nr("1'000'000", 8, 1)) |
| 204 | call assert_equal(1000000, str2nr("1'000'000", 10, 1)) |
Bram Moolenaar | ea8dcf8 | 2019-09-15 21:12:22 +0200 | [diff] [blame] | 205 | call assert_equal(1000, str2nr("1'000''000", 10, 1)) |
Bram Moolenaar | 60a8de2 | 2019-09-15 14:33:22 +0200 | [diff] [blame] | 206 | call assert_equal(65536, str2nr("1'00'00", 16, 1)) |
| 207 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 208 | call assert_equal(0, str2nr('0x10')) |
| 209 | call assert_equal(0, str2nr('0b10')) |
| 210 | call assert_equal(1, str2nr('12', 2)) |
| 211 | call assert_equal(1, str2nr('18', 8)) |
| 212 | call assert_equal(1, str2nr('1g', 16)) |
| 213 | |
| 214 | call assert_equal(0, str2nr(v:null)) |
| 215 | call assert_equal(0, str2nr(v:none)) |
| 216 | |
| 217 | call assert_fails('call str2nr([])', 'E730:') |
| 218 | call assert_fails('call str2nr({->2})', 'E729:') |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 219 | if has('float') |
| 220 | call assert_fails('call str2nr(1.2)', 'E806:') |
| 221 | endif |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 222 | call assert_fails('call str2nr(10, [])', 'E474:') |
| 223 | endfunc |
| 224 | |
| 225 | func Test_strftime() |
Bram Moolenaar | 10455d4 | 2019-11-21 15:36:18 +0100 | [diff] [blame] | 226 | CheckFunction strftime |
| 227 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 228 | " Format of strftime() depends on system. We assume |
| 229 | " that basic formats tested here are available and |
| 230 | " identical on all systems which support strftime(). |
| 231 | " |
| 232 | " The 2nd parameter of strftime() is a local time, so the output day |
| 233 | " of strftime() can be 17 or 18, depending on timezone. |
| 234 | call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512)) |
| 235 | " |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 236 | call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', '%Y-%m-%d %H:%M:%S'->strftime()) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 237 | |
| 238 | call assert_fails('call strftime([])', 'E730:') |
| 239 | call assert_fails('call strftime("%Y", [])', 'E745:') |
Bram Moolenaar | db51730 | 2019-06-18 22:53:24 +0200 | [diff] [blame] | 240 | |
| 241 | " Check that the time changes after we change the timezone |
| 242 | " Save previous timezone value, if any |
| 243 | if exists('$TZ') |
| 244 | let tz = $TZ |
| 245 | endif |
| 246 | |
| 247 | " Force EST and then UTC, save the current hour (24-hour clock) for each |
| 248 | let $TZ = 'EST' | let est = strftime('%H') |
| 249 | let $TZ = 'UTC' | let utc = strftime('%H') |
| 250 | |
| 251 | " Those hours should be two bytes long, and should not be the same; if they |
| 252 | " are, a tzset(3) call may have failed somewhere |
| 253 | call assert_equal(strlen(est), 2) |
| 254 | call assert_equal(strlen(utc), 2) |
Bram Moolenaar | 87652a7 | 2019-06-18 23:07:37 +0200 | [diff] [blame] | 255 | " TODO: this fails on MS-Windows |
| 256 | if has('unix') |
| 257 | call assert_notequal(est, utc) |
| 258 | endif |
Bram Moolenaar | db51730 | 2019-06-18 22:53:24 +0200 | [diff] [blame] | 259 | |
| 260 | " If we cached a timezone value, put it back, otherwise clear it |
| 261 | if exists('tz') |
| 262 | let $TZ = tz |
| 263 | else |
| 264 | unlet $TZ |
| 265 | endif |
Bram Moolenaar | 10455d4 | 2019-11-21 15:36:18 +0100 | [diff] [blame] | 266 | endfunc |
Bram Moolenaar | db51730 | 2019-06-18 22:53:24 +0200 | [diff] [blame] | 267 | |
Bram Moolenaar | 10455d4 | 2019-11-21 15:36:18 +0100 | [diff] [blame] | 268 | func Test_strptime() |
| 269 | CheckFunction strptime |
| 270 | |
| 271 | if exists('$TZ') |
| 272 | let tz = $TZ |
| 273 | endif |
| 274 | let $TZ = 'UTC' |
| 275 | |
Bram Moolenaar | 9a838fe | 2019-12-06 12:45:01 +0100 | [diff] [blame] | 276 | call assert_equal(1484653763, strptime('%Y-%m-%d %T', '2017-01-17 11:49:23')) |
Bram Moolenaar | 10455d4 | 2019-11-21 15:36:18 +0100 | [diff] [blame] | 277 | |
| 278 | call assert_fails('call strptime()', 'E119:') |
| 279 | call assert_fails('call strptime("xxx")', 'E119:') |
| 280 | call assert_equal(0, strptime("%Y", '')) |
| 281 | call assert_equal(0, strptime("%Y", "xxx")) |
| 282 | |
| 283 | if exists('tz') |
| 284 | let $TZ = tz |
| 285 | else |
| 286 | unlet $TZ |
| 287 | endif |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 288 | endfunc |
| 289 | |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 290 | func Test_resolve_unix() |
Bram Moolenaar | 2610990 | 2018-10-06 15:43:17 +0200 | [diff] [blame] | 291 | if !has('unix') |
| 292 | return |
| 293 | endif |
| 294 | |
| 295 | " Xlink1 -> Xlink2 |
| 296 | " Xlink2 -> Xlink3 |
| 297 | silent !ln -s -f Xlink2 Xlink1 |
| 298 | silent !ln -s -f Xlink3 Xlink2 |
| 299 | call assert_equal('Xlink3', resolve('Xlink1')) |
| 300 | call assert_equal('./Xlink3', resolve('./Xlink1')) |
| 301 | call assert_equal('Xlink3/', resolve('Xlink2/')) |
| 302 | " FIXME: these tests result in things like "Xlink2/" instead of "Xlink3/"?! |
| 303 | "call assert_equal('Xlink3/', resolve('Xlink1/')) |
| 304 | "call assert_equal('./Xlink3/', resolve('./Xlink1/')) |
| 305 | "call assert_equal(getcwd() . '/Xlink3/', resolve(getcwd() . '/Xlink1/')) |
| 306 | call assert_equal(getcwd() . '/Xlink3', resolve(getcwd() . '/Xlink1')) |
| 307 | |
| 308 | " Test resolve() with a symlink cycle. |
| 309 | " Xlink1 -> Xlink2 |
| 310 | " Xlink2 -> Xlink3 |
| 311 | " Xlink3 -> Xlink1 |
| 312 | silent !ln -s -f Xlink1 Xlink3 |
| 313 | call assert_fails('call resolve("Xlink1")', 'E655:') |
| 314 | call assert_fails('call resolve("./Xlink1")', 'E655:') |
| 315 | call assert_fails('call resolve("Xlink2")', 'E655:') |
| 316 | call assert_fails('call resolve("Xlink3")', 'E655:') |
| 317 | call delete('Xlink1') |
| 318 | call delete('Xlink2') |
| 319 | call delete('Xlink3') |
| 320 | |
| 321 | silent !ln -s -f Xdir//Xfile Xlink |
| 322 | call assert_equal('Xdir/Xfile', resolve('Xlink')) |
| 323 | call delete('Xlink') |
| 324 | |
| 325 | silent !ln -s -f Xlink2/ Xlink1 |
Bram Moolenaar | a0d1fef | 2019-09-04 22:29:14 +0200 | [diff] [blame] | 326 | call assert_equal('Xlink2', 'Xlink1'->resolve()) |
Bram Moolenaar | 2610990 | 2018-10-06 15:43:17 +0200 | [diff] [blame] | 327 | call assert_equal('Xlink2/', resolve('Xlink1/')) |
| 328 | call delete('Xlink1') |
| 329 | |
| 330 | silent !ln -s -f ./Xlink2 Xlink1 |
| 331 | call assert_equal('Xlink2', resolve('Xlink1')) |
| 332 | call assert_equal('./Xlink2', resolve('./Xlink1')) |
| 333 | call delete('Xlink1') |
| 334 | endfunc |
| 335 | |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 336 | func s:normalize_fname(fname) |
| 337 | let ret = substitute(a:fname, '\', '/', 'g') |
| 338 | let ret = substitute(ret, '//', '/', 'g') |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 339 | return ret->tolower() |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 340 | endfunc |
| 341 | |
| 342 | func Test_resolve_win32() |
| 343 | if !has('win32') |
| 344 | return |
| 345 | endif |
| 346 | |
| 347 | " test for shortcut file |
| 348 | if executable('cscript') |
| 349 | new Xfile |
| 350 | wq |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 351 | let lines =<< trim END |
| 352 | Set fs = CreateObject("Scripting.FileSystemObject") |
| 353 | Set ws = WScript.CreateObject("WScript.Shell") |
| 354 | Set shortcut = ws.CreateShortcut("Xlink.lnk") |
| 355 | shortcut.TargetPath = fs.BuildPath(ws.CurrentDirectory, "Xfile") |
| 356 | shortcut.Save |
| 357 | END |
| 358 | call writefile(lines, 'link.vbs') |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 359 | silent !cscript link.vbs |
| 360 | call delete('link.vbs') |
| 361 | call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk'))) |
| 362 | call delete('Xfile') |
| 363 | |
| 364 | call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk'))) |
| 365 | call delete('Xlink.lnk') |
| 366 | else |
| 367 | echomsg 'skipped test for shortcut file' |
| 368 | endif |
| 369 | |
| 370 | " remove files |
| 371 | call delete('Xlink') |
| 372 | call delete('Xdir', 'd') |
| 373 | call delete('Xfile') |
| 374 | |
| 375 | " test for symbolic link to a file |
| 376 | new Xfile |
| 377 | wq |
Bram Moolenaar | 4a792c8 | 2019-06-06 12:22:41 +0200 | [diff] [blame] | 378 | call assert_equal('Xfile', resolve('Xfile')) |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 379 | silent !mklink Xlink Xfile |
| 380 | if !v:shell_error |
| 381 | call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink'))) |
| 382 | call delete('Xlink') |
| 383 | else |
| 384 | echomsg 'skipped test for symbolic link to a file' |
| 385 | endif |
| 386 | call delete('Xfile') |
| 387 | |
| 388 | " test for junction to a directory |
| 389 | call mkdir('Xdir') |
| 390 | silent !mklink /J Xlink Xdir |
| 391 | if !v:shell_error |
| 392 | call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) |
| 393 | |
| 394 | call delete('Xdir', 'd') |
| 395 | |
| 396 | " test for junction already removed |
| 397 | call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) |
| 398 | call delete('Xlink') |
| 399 | else |
| 400 | echomsg 'skipped test for junction to a directory' |
| 401 | call delete('Xdir', 'd') |
| 402 | endif |
| 403 | |
| 404 | " test for symbolic link to a directory |
| 405 | call mkdir('Xdir') |
| 406 | silent !mklink /D Xlink Xdir |
| 407 | if !v:shell_error |
| 408 | call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) |
| 409 | |
| 410 | call delete('Xdir', 'd') |
| 411 | |
| 412 | " test for symbolic link already removed |
| 413 | call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) |
| 414 | call delete('Xlink') |
| 415 | else |
| 416 | echomsg 'skipped test for symbolic link to a directory' |
| 417 | call delete('Xdir', 'd') |
| 418 | endif |
| 419 | |
| 420 | " test for buffer name |
| 421 | new Xfile |
| 422 | wq |
| 423 | silent !mklink Xlink Xfile |
| 424 | if !v:shell_error |
| 425 | edit Xlink |
| 426 | call assert_equal('Xlink', bufname('%')) |
| 427 | call delete('Xlink') |
| 428 | bw! |
| 429 | else |
| 430 | echomsg 'skipped test for buffer name' |
| 431 | endif |
| 432 | call delete('Xfile') |
Bram Moolenaar | 1bbebab | 2019-05-29 20:36:54 +0200 | [diff] [blame] | 433 | |
| 434 | " test for reparse point |
| 435 | call mkdir('Xdir') |
Bram Moolenaar | 4a792c8 | 2019-06-06 12:22:41 +0200 | [diff] [blame] | 436 | call assert_equal('Xdir', resolve('Xdir')) |
Bram Moolenaar | 1bbebab | 2019-05-29 20:36:54 +0200 | [diff] [blame] | 437 | silent !mklink /D Xdirlink Xdir |
| 438 | if !v:shell_error |
| 439 | w Xdir/text.txt |
Bram Moolenaar | 4a792c8 | 2019-06-06 12:22:41 +0200 | [diff] [blame] | 440 | call assert_equal('Xdir/text.txt', resolve('Xdir/text.txt')) |
Bram Moolenaar | 1bbebab | 2019-05-29 20:36:54 +0200 | [diff] [blame] | 441 | call assert_equal(s:normalize_fname(getcwd() . '\Xdir\text.txt'), s:normalize_fname(resolve('Xdirlink\text.txt'))) |
| 442 | call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve('Xdirlink'))) |
Bram Moolenaar | 4a792c8 | 2019-06-06 12:22:41 +0200 | [diff] [blame] | 443 | call delete('Xdirlink') |
Bram Moolenaar | 1bbebab | 2019-05-29 20:36:54 +0200 | [diff] [blame] | 444 | else |
| 445 | echomsg 'skipped test for reparse point' |
| 446 | endif |
| 447 | |
| 448 | call delete('Xdir', 'rf') |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 449 | endfunc |
| 450 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 451 | func Test_simplify() |
| 452 | call assert_equal('', simplify('')) |
| 453 | call assert_equal('/', simplify('/')) |
| 454 | call assert_equal('/', simplify('/.')) |
| 455 | call assert_equal('/', simplify('/..')) |
| 456 | call assert_equal('/...', simplify('/...')) |
Bram Moolenaar | 7035fd9 | 2020-04-08 20:03:52 +0200 | [diff] [blame] | 457 | call assert_equal('./dir/file', './dir/file'->simplify()) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 458 | call assert_equal('./dir/file', simplify('.///dir//file')) |
| 459 | call assert_equal('./dir/file', simplify('./dir/./file')) |
| 460 | call assert_equal('./file', simplify('./dir/../file')) |
| 461 | call assert_equal('../dir/file', simplify('dir/../../dir/file')) |
| 462 | call assert_equal('./file', simplify('dir/.././file')) |
| 463 | |
| 464 | call assert_fails('call simplify({->0})', 'E729:') |
| 465 | call assert_fails('call simplify([])', 'E730:') |
| 466 | call assert_fails('call simplify({})', 'E731:') |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 467 | if has('float') |
| 468 | call assert_fails('call simplify(1.2)', 'E806:') |
| 469 | endif |
Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 470 | endfunc |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 471 | |
Bram Moolenaar | bfde0b4 | 2018-08-08 22:27:31 +0200 | [diff] [blame] | 472 | func Test_pathshorten() |
| 473 | call assert_equal('', pathshorten('')) |
| 474 | call assert_equal('foo', pathshorten('foo')) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 475 | call assert_equal('/foo', '/foo'->pathshorten()) |
Bram Moolenaar | bfde0b4 | 2018-08-08 22:27:31 +0200 | [diff] [blame] | 476 | call assert_equal('f/', pathshorten('foo/')) |
| 477 | call assert_equal('f/bar', pathshorten('foo/bar')) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 478 | call assert_equal('f/b/foobar', 'foo/bar/foobar'->pathshorten()) |
Bram Moolenaar | bfde0b4 | 2018-08-08 22:27:31 +0200 | [diff] [blame] | 479 | call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar')) |
| 480 | call assert_equal('.f/bar', pathshorten('.foo/bar')) |
| 481 | call assert_equal('~f/bar', pathshorten('~foo/bar')) |
| 482 | call assert_equal('~.f/bar', pathshorten('~.foo/bar')) |
| 483 | call assert_equal('.~f/bar', pathshorten('.~foo/bar')) |
| 484 | call assert_equal('~/f/bar', pathshorten('~/foo/bar')) |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 485 | call assert_fails('call pathshorten([])', 'E730:') |
Bram Moolenaar | bfde0b4 | 2018-08-08 22:27:31 +0200 | [diff] [blame] | 486 | endfunc |
| 487 | |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 488 | func Test_strpart() |
| 489 | call assert_equal('de', strpart('abcdefg', 3, 2)) |
| 490 | call assert_equal('ab', strpart('abcdefg', -2, 4)) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 491 | call assert_equal('abcdefg', 'abcdefg'->strpart(-2)) |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 492 | call assert_equal('fg', strpart('abcdefg', 5, 4)) |
| 493 | call assert_equal('defg', strpart('abcdefg', 3)) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 494 | call assert_equal('', strpart('abcdefg', 10)) |
| 495 | call assert_fails("let s=strpart('abcdef', [])", 'E745:') |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 496 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 497 | call assert_equal('lép', strpart('éléphant', 2, 4)) |
| 498 | call assert_equal('léphant', strpart('éléphant', 2)) |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 499 | endfunc |
| 500 | |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 501 | func Test_tolower() |
| 502 | call assert_equal("", tolower("")) |
| 503 | |
| 504 | " Test with all printable ASCII characters. |
| 505 | call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', |
| 506 | \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) |
| 507 | |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 508 | " Test with a few uppercase diacritics. |
| 509 | call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) |
| 510 | call assert_equal("bḃḇ", tolower("BḂḆ")) |
| 511 | call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ")) |
| 512 | call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ")) |
| 513 | call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ")) |
| 514 | call assert_equal("fḟ ", tolower("FḞ ")) |
| 515 | call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ")) |
| 516 | call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ")) |
| 517 | call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ")) |
| 518 | call assert_equal("jĵ", tolower("JĴ")) |
| 519 | call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ")) |
| 520 | call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ")) |
| 521 | call assert_equal("mḿṁ", tolower("MḾṀ")) |
| 522 | call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ")) |
| 523 | call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) |
| 524 | call assert_equal("pṕṗ", tolower("PṔṖ")) |
| 525 | call assert_equal("q", tolower("Q")) |
| 526 | call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ")) |
| 527 | call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ")) |
| 528 | call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ")) |
| 529 | call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) |
| 530 | call assert_equal("vṽ", tolower("VṼ")) |
| 531 | call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ")) |
| 532 | call assert_equal("xẋẍ", tolower("XẊẌ")) |
| 533 | call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ")) |
| 534 | call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ")) |
| 535 | |
| 536 | " Test with a few lowercase diacritics, which should remain unchanged. |
| 537 | call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả")) |
| 538 | call assert_equal("bḃḇ", tolower("bḃḇ")) |
| 539 | call assert_equal("cçćĉċč", tolower("cçćĉċč")) |
| 540 | call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ")) |
| 541 | call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ")) |
| 542 | call assert_equal("fḟ", tolower("fḟ")) |
| 543 | call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ")) |
| 544 | call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ")) |
| 545 | call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ")) |
| 546 | call assert_equal("jĵǰ", tolower("jĵǰ")) |
| 547 | call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ")) |
| 548 | call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ")) |
| 549 | call assert_equal("mḿṁ ", tolower("mḿṁ ")) |
| 550 | call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ")) |
| 551 | call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ")) |
| 552 | call assert_equal("pṕṗ", tolower("pṕṗ")) |
| 553 | call assert_equal("q", tolower("q")) |
| 554 | call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ")) |
| 555 | call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ")) |
| 556 | call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ")) |
| 557 | call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ")) |
| 558 | call assert_equal("vṽ", tolower("vṽ")) |
| 559 | call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ")) |
| 560 | call assert_equal("ẋẍ", tolower("ẋẍ")) |
| 561 | call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ")) |
| 562 | call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ")) |
| 563 | |
| 564 | " According to https://twitter.com/jifa/status/625776454479970304 |
| 565 | " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase |
| 566 | " in length (2 to 3 bytes) when lowercased. So let's test them. |
| 567 | call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) |
Bram Moolenaar | e6640ad | 2017-12-22 21:06:56 +0100 | [diff] [blame] | 568 | |
| 569 | " This call to tolower with invalid utf8 sequence used to cause access to |
| 570 | " invalid memory. |
| 571 | call tolower("\xC0\x80\xC0") |
| 572 | call tolower("123\xC0\x80\xC0") |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 573 | endfunc |
| 574 | |
| 575 | func Test_toupper() |
| 576 | call assert_equal("", toupper("")) |
| 577 | |
| 578 | " Test with all printable ASCII characters. |
| 579 | call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~', |
| 580 | \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) |
| 581 | |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 582 | " Test with a few lowercase diacritics. |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 583 | call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", "aàáâãäåāăąǎǟǡả"->toupper()) |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 584 | call assert_equal("BḂḆ", toupper("bḃḇ")) |
| 585 | call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) |
| 586 | call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) |
| 587 | call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ")) |
| 588 | call assert_equal("FḞ", toupper("fḟ")) |
| 589 | call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ")) |
| 590 | call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ")) |
| 591 | call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ")) |
| 592 | call assert_equal("JĴǰ", toupper("jĵǰ")) |
| 593 | call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ")) |
| 594 | call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ")) |
| 595 | call assert_equal("MḾṀ ", toupper("mḿṁ ")) |
| 596 | call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ")) |
| 597 | call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ")) |
| 598 | call assert_equal("PṔṖ", toupper("pṕṗ")) |
| 599 | call assert_equal("Q", toupper("q")) |
| 600 | call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ")) |
| 601 | call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ")) |
| 602 | call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ")) |
| 603 | call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ")) |
| 604 | call assert_equal("VṼ", toupper("vṽ")) |
| 605 | call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ")) |
| 606 | call assert_equal("ẊẌ", toupper("ẋẍ")) |
| 607 | call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ")) |
| 608 | call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ")) |
| 609 | |
| 610 | " Test that uppercase diacritics, which should remain unchanged. |
| 611 | call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) |
| 612 | call assert_equal("BḂḆ", toupper("BḂḆ")) |
| 613 | call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ")) |
| 614 | call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ")) |
| 615 | call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ")) |
| 616 | call assert_equal("FḞ ", toupper("FḞ ")) |
| 617 | call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ")) |
| 618 | call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ")) |
| 619 | call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ")) |
| 620 | call assert_equal("JĴ", toupper("JĴ")) |
| 621 | call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ")) |
| 622 | call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ")) |
| 623 | call assert_equal("MḾṀ", toupper("MḾṀ")) |
| 624 | call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ")) |
| 625 | call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) |
| 626 | call assert_equal("PṔṖ", toupper("PṔṖ")) |
| 627 | call assert_equal("Q", toupper("Q")) |
| 628 | call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ")) |
| 629 | call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ")) |
| 630 | call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ")) |
| 631 | call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) |
| 632 | call assert_equal("VṼ", toupper("VṼ")) |
| 633 | call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ")) |
| 634 | call assert_equal("XẊẌ", toupper("XẊẌ")) |
| 635 | call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ")) |
| 636 | call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ")) |
| 637 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 638 | call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ")) |
Bram Moolenaar | e6640ad | 2017-12-22 21:06:56 +0100 | [diff] [blame] | 639 | |
| 640 | " This call to toupper with invalid utf8 sequence used to cause access to |
| 641 | " invalid memory. |
| 642 | call toupper("\xC0\x80\xC0") |
| 643 | call toupper("123\xC0\x80\xC0") |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 644 | endfunc |
| 645 | |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 646 | func Test_tr() |
| 647 | call assert_equal('foo', tr('bar', 'bar', 'foo')) |
| 648 | call assert_equal('zxy', 'cab'->tr('abc', 'xyz')) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 649 | call assert_fails("let s=tr([], 'abc', 'def')", 'E730:') |
| 650 | call assert_fails("let s=tr('abc', [], 'def')", 'E730:') |
| 651 | call assert_fails("let s=tr('abc', 'abc', [])", 'E730:') |
| 652 | call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:') |
| 653 | set encoding=latin1 |
| 654 | call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:') |
| 655 | call assert_equal('hEllO', tr('hello', 'eo', 'EO')) |
| 656 | call assert_equal('hello', tr('hello', 'xy', 'ab')) |
| 657 | set encoding=utf8 |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 658 | endfunc |
| 659 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 660 | " Tests for the mode() function |
| 661 | let current_modes = '' |
Bram Moolenaar | ffea8c9 | 2017-03-13 20:37:15 +0100 | [diff] [blame] | 662 | func Save_mode() |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 663 | let g:current_modes = mode(0) . '-' . mode(1) |
| 664 | return '' |
| 665 | endfunc |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 666 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 667 | " Test for the mode() function |
Bram Moolenaar | ffea8c9 | 2017-03-13 20:37:15 +0100 | [diff] [blame] | 668 | func Test_mode() |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 669 | new |
| 670 | call append(0, ["Blue Ball Black", "Brown Band Bowl", ""]) |
| 671 | |
Bram Moolenaar | ffea8c9 | 2017-03-13 20:37:15 +0100 | [diff] [blame] | 672 | " Only complete from the current buffer. |
| 673 | set complete=. |
| 674 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 675 | inoremap <F2> <C-R>=Save_mode()<CR> |
| 676 | |
| 677 | normal! 3G |
| 678 | exe "normal i\<F2>\<Esc>" |
| 679 | call assert_equal('i-i', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 680 | " i_CTRL-P: Multiple matches |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 681 | exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u" |
| 682 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 683 | " i_CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 684 | exe "normal iBro\<C-P>\<F2>\<Esc>u" |
| 685 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 686 | " i_CTRL-X |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 687 | exe "normal iBa\<C-X>\<F2>\<Esc>u" |
| 688 | call assert_equal('i-ix', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 689 | " i_CTRL-X CTRL-P: Multiple matches |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 690 | exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u" |
| 691 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 692 | " i_CTRL-X CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 693 | exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u" |
| 694 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 695 | " i_CTRL-X CTRL-P + CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 696 | exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" |
| 697 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 698 | " i_CTRL-X CTRL-L: Multiple matches |
| 699 | exe "normal i\<C-X>\<C-L>\<F2>\<Esc>u" |
| 700 | call assert_equal('i-ic', g:current_modes) |
| 701 | " i_CTRL-X CTRL-L: Single match |
| 702 | exe "normal iBlu\<C-X>\<C-L>\<F2>\<Esc>u" |
| 703 | call assert_equal('i-ic', g:current_modes) |
| 704 | " i_CTRL-P: No match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 705 | exe "normal iCom\<C-P>\<F2>\<Esc>u" |
| 706 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 707 | " i_CTRL-X CTRL-P: No match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 708 | exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u" |
| 709 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 710 | " i_CTRL-X CTRL-L: No match |
| 711 | exe "normal iabc\<C-X>\<C-L>\<F2>\<Esc>u" |
| 712 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 713 | |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 714 | " R_CTRL-P: Multiple matches |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 715 | exe "normal RBa\<C-P>\<F2>\<Esc>u" |
| 716 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 717 | " R_CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 718 | exe "normal RBro\<C-P>\<F2>\<Esc>u" |
| 719 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 720 | " R_CTRL-X |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 721 | exe "normal RBa\<C-X>\<F2>\<Esc>u" |
| 722 | call assert_equal('R-Rx', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 723 | " R_CTRL-X CTRL-P: Multiple matches |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 724 | exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u" |
| 725 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 726 | " R_CTRL-X CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 727 | exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u" |
| 728 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 729 | " R_CTRL-X CTRL-P + CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 730 | exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" |
| 731 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 732 | " R_CTRL-X CTRL-L: Multiple matches |
| 733 | exe "normal R\<C-X>\<C-L>\<F2>\<Esc>u" |
| 734 | call assert_equal('R-Rc', g:current_modes) |
| 735 | " R_CTRL-X CTRL-L: Single match |
| 736 | exe "normal RBlu\<C-X>\<C-L>\<F2>\<Esc>u" |
| 737 | call assert_equal('R-Rc', g:current_modes) |
| 738 | " R_CTRL-P: No match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 739 | exe "normal RCom\<C-P>\<F2>\<Esc>u" |
| 740 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 741 | " R_CTRL-X CTRL-P: No match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 742 | exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u" |
| 743 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 744 | " R_CTRL-X CTRL-L: No match |
| 745 | exe "normal Rabc\<C-X>\<C-L>\<F2>\<Esc>u" |
| 746 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 747 | |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 748 | call assert_equal('n', 0->mode()) |
| 749 | call assert_equal('n', 1->mode()) |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 750 | |
Bram Moolenaar | 612cc38 | 2018-07-29 15:34:26 +0200 | [diff] [blame] | 751 | " i_CTRL-O |
| 752 | exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>" |
| 753 | call assert_equal("n-niI", g:current_modes) |
| 754 | |
| 755 | " R_CTRL-O |
| 756 | exe "normal R\<C-O>:call Save_mode()\<Cr>\<Esc>" |
| 757 | call assert_equal("n-niR", g:current_modes) |
| 758 | |
| 759 | " gR_CTRL-O |
| 760 | exe "normal gR\<C-O>:call Save_mode()\<Cr>\<Esc>" |
| 761 | call assert_equal("n-niV", g:current_modes) |
| 762 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 763 | " How to test operator-pending mode? |
| 764 | |
| 765 | call feedkeys("v", 'xt') |
| 766 | call assert_equal('v', mode()) |
| 767 | call assert_equal('v', mode(1)) |
| 768 | call feedkeys("\<Esc>V", 'xt') |
| 769 | call assert_equal('V', mode()) |
| 770 | call assert_equal('V', mode(1)) |
| 771 | call feedkeys("\<Esc>\<C-V>", 'xt') |
| 772 | call assert_equal("\<C-V>", mode()) |
| 773 | call assert_equal("\<C-V>", mode(1)) |
| 774 | call feedkeys("\<Esc>", 'xt') |
| 775 | |
| 776 | call feedkeys("gh", 'xt') |
| 777 | call assert_equal('s', mode()) |
| 778 | call assert_equal('s', mode(1)) |
| 779 | call feedkeys("\<Esc>gH", 'xt') |
| 780 | call assert_equal('S', mode()) |
| 781 | call assert_equal('S', mode(1)) |
| 782 | call feedkeys("\<Esc>g\<C-H>", 'xt') |
| 783 | call assert_equal("\<C-S>", mode()) |
| 784 | call assert_equal("\<C-S>", mode(1)) |
| 785 | call feedkeys("\<Esc>", 'xt') |
| 786 | |
| 787 | call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt') |
| 788 | call assert_equal('c-c', g:current_modes) |
| 789 | call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt') |
| 790 | call assert_equal('c-cv', g:current_modes) |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 791 | call feedkeys("Qcall Save_mode()\<CR>vi\<CR>", 'xt') |
| 792 | call assert_equal('c-ce', g:current_modes) |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 793 | " How to test Ex mode? |
| 794 | |
| 795 | bwipe! |
| 796 | iunmap <F2> |
Bram Moolenaar | ffea8c9 | 2017-03-13 20:37:15 +0100 | [diff] [blame] | 797 | set complete& |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 798 | endfunc |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 799 | |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 800 | " Test for append() |
Bram Moolenaar | d200702 | 2019-08-27 21:56:06 +0200 | [diff] [blame] | 801 | func Test_append() |
| 802 | enew! |
| 803 | split |
| 804 | call append(0, ["foo"]) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 805 | call append(1, []) |
| 806 | call append(1, test_null_list()) |
| 807 | call assert_equal(['foo', ''], getline(1, '$')) |
Bram Moolenaar | d200702 | 2019-08-27 21:56:06 +0200 | [diff] [blame] | 808 | split |
| 809 | only |
| 810 | undo |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 811 | undo |
Bram Moolenaar | 08f4157 | 2020-04-20 16:50:00 +0200 | [diff] [blame] | 812 | |
| 813 | " Using $ instead of '$' must give an error |
| 814 | call assert_fails("call append($, 'foobar')", 'E116:') |
Bram Moolenaar | d200702 | 2019-08-27 21:56:06 +0200 | [diff] [blame] | 815 | endfunc |
| 816 | |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 817 | " Test for setline() |
| 818 | func Test_setline() |
| 819 | new |
| 820 | call setline(0, ["foo"]) |
| 821 | call setline(0, []) |
| 822 | call setline(0, test_null_list()) |
| 823 | call setline(1, ["bar"]) |
| 824 | call setline(1, []) |
| 825 | call setline(1, test_null_list()) |
| 826 | call setline(2, []) |
| 827 | call setline(2, test_null_list()) |
| 828 | call setline(3, []) |
| 829 | call setline(3, test_null_list()) |
| 830 | call setline(2, ["baz"]) |
| 831 | call assert_equal(['bar', 'baz'], getline(1, '$')) |
| 832 | close! |
| 833 | endfunc |
| 834 | |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 835 | func Test_getbufvar() |
| 836 | let bnr = bufnr('%') |
| 837 | let b:var_num = '1234' |
| 838 | let def_num = '5678' |
| 839 | call assert_equal('1234', getbufvar(bnr, 'var_num')) |
| 840 | call assert_equal('1234', getbufvar(bnr, 'var_num', def_num)) |
| 841 | |
| 842 | let bd = getbufvar(bnr, '') |
| 843 | call assert_equal('1234', bd['var_num']) |
| 844 | call assert_true(exists("bd['changedtick']")) |
| 845 | call assert_equal(2, len(bd)) |
| 846 | |
| 847 | let bd2 = getbufvar(bnr, '', def_num) |
| 848 | call assert_equal(bd, bd2) |
| 849 | |
| 850 | unlet b:var_num |
| 851 | call assert_equal(def_num, getbufvar(bnr, 'var_num', def_num)) |
| 852 | call assert_equal('', getbufvar(bnr, 'var_num')) |
| 853 | |
| 854 | let bd = getbufvar(bnr, '') |
| 855 | call assert_equal(1, len(bd)) |
| 856 | let bd = getbufvar(bnr, '',def_num) |
| 857 | call assert_equal(1, len(bd)) |
| 858 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 859 | call assert_equal('', getbufvar(9999, '')) |
| 860 | call assert_equal(def_num, getbufvar(9999, '', def_num)) |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 861 | unlet def_num |
| 862 | |
Bram Moolenaar | 507647d | 2017-02-17 16:43:49 +0100 | [diff] [blame] | 863 | call assert_equal(0, getbufvar(bnr, '&autoindent')) |
| 864 | call assert_equal(0, getbufvar(bnr, '&autoindent', 1)) |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 865 | |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 866 | " Set and get a buffer-local variable |
| 867 | call setbufvar(bnr, 'bufvar_test', ['one', 'two']) |
| 868 | call assert_equal(['one', 'two'], getbufvar(bnr, 'bufvar_test')) |
| 869 | |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 870 | " Open new window with forced option values |
| 871 | set fileformats=unix,dos |
| 872 | new ++ff=dos ++bin ++enc=iso-8859-2 |
| 873 | call assert_equal('dos', getbufvar(bufnr('%'), '&fileformat')) |
| 874 | call assert_equal(1, getbufvar(bufnr('%'), '&bin')) |
| 875 | call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc')) |
| 876 | close |
| 877 | |
Bram Moolenaar | 5259275 | 2020-04-03 18:43:35 +0200 | [diff] [blame] | 878 | " Get the b: dict. |
| 879 | let b:testvar = 'one' |
| 880 | new |
| 881 | let b:testvar = 'two' |
| 882 | let thebuf = bufnr() |
| 883 | wincmd w |
| 884 | call assert_equal('two', getbufvar(thebuf, 'testvar')) |
| 885 | call assert_equal('two', getbufvar(thebuf, '').testvar) |
| 886 | bwipe! |
| 887 | |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 888 | set fileformats& |
| 889 | endfunc |
Bram Moolenaar | caf6434 | 2017-03-02 22:11:33 +0100 | [diff] [blame] | 890 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 891 | func Test_last_buffer_nr() |
| 892 | call assert_equal(bufnr('$'), last_buffer_nr()) |
| 893 | endfunc |
| 894 | |
| 895 | func Test_stridx() |
| 896 | call assert_equal(-1, stridx('', 'l')) |
| 897 | call assert_equal(0, stridx('', '')) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 898 | call assert_equal(0, 'hello'->stridx('')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 899 | call assert_equal(-1, stridx('hello', 'L')) |
| 900 | call assert_equal(2, stridx('hello', 'l', -1)) |
| 901 | call assert_equal(2, stridx('hello', 'l', 0)) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 902 | call assert_equal(2, 'hello'->stridx('l', 1)) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 903 | call assert_equal(3, stridx('hello', 'l', 3)) |
| 904 | call assert_equal(-1, stridx('hello', 'l', 4)) |
| 905 | call assert_equal(-1, stridx('hello', 'l', 10)) |
| 906 | call assert_equal(2, stridx('hello', 'll')) |
| 907 | call assert_equal(-1, stridx('hello', 'hello world')) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 908 | call assert_fails("let n=stridx('hello', [])", 'E730:') |
| 909 | call assert_fails("let n=stridx([], 'l')", 'E730:') |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 910 | endfunc |
| 911 | |
| 912 | func Test_strridx() |
| 913 | call assert_equal(-1, strridx('', 'l')) |
| 914 | call assert_equal(0, strridx('', '')) |
| 915 | call assert_equal(5, strridx('hello', '')) |
| 916 | call assert_equal(-1, strridx('hello', 'L')) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 917 | call assert_equal(3, 'hello'->strridx('l')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 918 | call assert_equal(3, strridx('hello', 'l', 10)) |
| 919 | call assert_equal(3, strridx('hello', 'l', 3)) |
| 920 | call assert_equal(2, strridx('hello', 'l', 2)) |
| 921 | call assert_equal(-1, strridx('hello', 'l', 1)) |
| 922 | call assert_equal(-1, strridx('hello', 'l', 0)) |
| 923 | call assert_equal(-1, strridx('hello', 'l', -1)) |
| 924 | call assert_equal(2, strridx('hello', 'll')) |
| 925 | call assert_equal(-1, strridx('hello', 'hello world')) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 926 | call assert_fails("let n=strridx('hello', [])", 'E730:') |
| 927 | call assert_fails("let n=strridx([], 'l')", 'E730:') |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 928 | endfunc |
| 929 | |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 930 | func Test_match_func() |
| 931 | call assert_equal(4, match('testing', 'ing')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 932 | call assert_equal(4, 'testing'->match('ing', 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 933 | call assert_equal(-1, match('testing', 'ing', 5)) |
| 934 | call assert_equal(-1, match('testing', 'ing', 8)) |
| 935 | call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing')) |
| 936 | call assert_equal(-1, match(['vim', 'testing', 'execute'], 'img')) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 937 | call assert_fails("let x=match('vim', [])", 'E730:') |
| 938 | call assert_equal(3, match(['a', 'b', 'c', 'a'], 'a', 1)) |
| 939 | call assert_equal(-1, match(['a', 'b', 'c', 'a'], 'a', 5)) |
| 940 | call assert_equal(4, match('testing', 'ing', -1)) |
| 941 | call assert_fails("let x=match('testing', 'ing', 0, [])", 'E745:') |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 942 | call assert_equal(-1, match(test_null_list(), 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 943 | endfunc |
| 944 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 945 | func Test_matchend() |
| 946 | call assert_equal(7, matchend('testing', 'ing')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 947 | call assert_equal(7, 'testing'->matchend('ing', 2)) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 948 | call assert_equal(-1, matchend('testing', 'ing', 5)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 949 | call assert_equal(-1, matchend('testing', 'ing', 8)) |
| 950 | call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing')) |
| 951 | call assert_equal(match(['vim', 'testing', 'execute'], 'img'), matchend(['vim', 'testing', 'execute'], 'img')) |
| 952 | endfunc |
| 953 | |
| 954 | func Test_matchlist() |
| 955 | call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 956 | call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], 'acd'->matchlist('\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 957 | call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4)) |
| 958 | endfunc |
| 959 | |
| 960 | func Test_matchstr() |
| 961 | call assert_equal('ing', matchstr('testing', 'ing')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 962 | call assert_equal('ing', 'testing'->matchstr('ing', 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 963 | call assert_equal('', matchstr('testing', 'ing', 5)) |
| 964 | call assert_equal('', matchstr('testing', 'ing', 8)) |
| 965 | call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing')) |
| 966 | call assert_equal('', matchstr(['vim', 'testing', 'execute'], 'img')) |
| 967 | endfunc |
| 968 | |
| 969 | func Test_matchstrpos() |
| 970 | call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 971 | call assert_equal(['ing', 4, 7], 'testing'->matchstrpos('ing', 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 972 | call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5)) |
| 973 | call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8)) |
| 974 | call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing')) |
| 975 | call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img')) |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 976 | call assert_equal(['', -1, -1], matchstrpos(test_null_list(), '\a')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 977 | endfunc |
| 978 | |
| 979 | func Test_nextnonblank_prevnonblank() |
| 980 | new |
| 981 | insert |
| 982 | This |
| 983 | |
| 984 | |
| 985 | is |
| 986 | |
| 987 | a |
| 988 | Test |
| 989 | . |
| 990 | call assert_equal(0, nextnonblank(-1)) |
| 991 | call assert_equal(0, nextnonblank(0)) |
| 992 | call assert_equal(1, nextnonblank(1)) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 993 | call assert_equal(4, 2->nextnonblank()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 994 | call assert_equal(4, nextnonblank(3)) |
| 995 | call assert_equal(4, nextnonblank(4)) |
| 996 | call assert_equal(6, nextnonblank(5)) |
| 997 | call assert_equal(6, nextnonblank(6)) |
| 998 | call assert_equal(7, nextnonblank(7)) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 999 | call assert_equal(0, 8->nextnonblank()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1000 | |
| 1001 | call assert_equal(0, prevnonblank(-1)) |
| 1002 | call assert_equal(0, prevnonblank(0)) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 1003 | call assert_equal(1, 1->prevnonblank()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1004 | call assert_equal(1, prevnonblank(2)) |
| 1005 | call assert_equal(1, prevnonblank(3)) |
| 1006 | call assert_equal(4, prevnonblank(4)) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 1007 | call assert_equal(4, 5->prevnonblank()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1008 | call assert_equal(6, prevnonblank(6)) |
| 1009 | call assert_equal(7, prevnonblank(7)) |
| 1010 | call assert_equal(0, prevnonblank(8)) |
| 1011 | bw! |
| 1012 | endfunc |
| 1013 | |
| 1014 | func Test_byte2line_line2byte() |
| 1015 | new |
Bram Moolenaar | c26f7c6 | 2018-08-20 22:53:04 +0200 | [diff] [blame] | 1016 | set endofline |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1017 | call setline(1, ['a', 'bc', 'd']) |
| 1018 | |
| 1019 | set fileformat=unix |
| 1020 | call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], |
| 1021 | \ map(range(-1, 8), 'byte2line(v:val)')) |
| 1022 | call assert_equal([-1, -1, 1, 3, 6, 8, -1], |
| 1023 | \ map(range(-1, 5), 'line2byte(v:val)')) |
| 1024 | |
| 1025 | set fileformat=mac |
| 1026 | call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 1027 | \ map(range(-1, 8), 'v:val->byte2line()')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1028 | call assert_equal([-1, -1, 1, 3, 6, 8, -1], |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 1029 | \ map(range(-1, 5), 'v:val->line2byte()')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1030 | |
| 1031 | set fileformat=dos |
| 1032 | call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1], |
| 1033 | \ map(range(-1, 11), 'byte2line(v:val)')) |
| 1034 | call assert_equal([-1, -1, 1, 4, 8, 11, -1], |
| 1035 | \ map(range(-1, 5), 'line2byte(v:val)')) |
| 1036 | |
Bram Moolenaar | c26f7c6 | 2018-08-20 22:53:04 +0200 | [diff] [blame] | 1037 | bw! |
| 1038 | set noendofline nofixendofline |
| 1039 | normal a- |
| 1040 | for ff in ["unix", "mac", "dos"] |
| 1041 | let &fileformat = ff |
| 1042 | call assert_equal(1, line2byte(1)) |
| 1043 | call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte). |
| 1044 | endfor |
| 1045 | |
| 1046 | set endofline& fixendofline& fileformat& |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1047 | bw! |
| 1048 | endfunc |
| 1049 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1050 | " Test for byteidx() and byteidxcomp() functions |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 1051 | func Test_byteidx() |
| 1052 | let a = '.é.' " one char of two bytes |
| 1053 | call assert_equal(0, byteidx(a, 0)) |
| 1054 | call assert_equal(0, byteidxcomp(a, 0)) |
| 1055 | call assert_equal(1, byteidx(a, 1)) |
| 1056 | call assert_equal(1, byteidxcomp(a, 1)) |
| 1057 | call assert_equal(3, byteidx(a, 2)) |
| 1058 | call assert_equal(3, byteidxcomp(a, 2)) |
| 1059 | call assert_equal(4, byteidx(a, 3)) |
| 1060 | call assert_equal(4, byteidxcomp(a, 3)) |
| 1061 | call assert_equal(-1, byteidx(a, 4)) |
| 1062 | call assert_equal(-1, byteidxcomp(a, 4)) |
| 1063 | |
| 1064 | let b = '.é.' " normal e with composing char |
| 1065 | call assert_equal(0, b->byteidx(0)) |
| 1066 | call assert_equal(1, b->byteidx(1)) |
| 1067 | call assert_equal(4, b->byteidx(2)) |
| 1068 | call assert_equal(5, b->byteidx(3)) |
| 1069 | call assert_equal(-1, b->byteidx(4)) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1070 | call assert_fails("call byteidx([], 0)", 'E730:') |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 1071 | |
| 1072 | call assert_equal(0, b->byteidxcomp(0)) |
| 1073 | call assert_equal(1, b->byteidxcomp(1)) |
| 1074 | call assert_equal(2, b->byteidxcomp(2)) |
| 1075 | call assert_equal(4, b->byteidxcomp(3)) |
| 1076 | call assert_equal(5, b->byteidxcomp(4)) |
| 1077 | call assert_equal(-1, b->byteidxcomp(5)) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1078 | call assert_fails("call byteidxcomp([], 0)", 'E730:') |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 1079 | endfunc |
| 1080 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1081 | func Test_count() |
| 1082 | let l = ['a', 'a', 'A', 'b'] |
| 1083 | call assert_equal(2, count(l, 'a')) |
| 1084 | call assert_equal(1, count(l, 'A')) |
| 1085 | call assert_equal(1, count(l, 'b')) |
| 1086 | call assert_equal(0, count(l, 'B')) |
| 1087 | |
| 1088 | call assert_equal(2, count(l, 'a', 0)) |
| 1089 | call assert_equal(1, count(l, 'A', 0)) |
| 1090 | call assert_equal(1, count(l, 'b', 0)) |
| 1091 | call assert_equal(0, count(l, 'B', 0)) |
| 1092 | |
| 1093 | call assert_equal(3, count(l, 'a', 1)) |
| 1094 | call assert_equal(3, count(l, 'A', 1)) |
| 1095 | call assert_equal(1, count(l, 'b', 1)) |
| 1096 | call assert_equal(1, count(l, 'B', 1)) |
| 1097 | call assert_equal(0, count(l, 'c', 1)) |
| 1098 | |
| 1099 | call assert_equal(1, count(l, 'a', 0, 1)) |
| 1100 | call assert_equal(2, count(l, 'a', 1, 1)) |
| 1101 | call assert_fails('call count(l, "a", 0, 10)', 'E684:') |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1102 | call assert_fails('call count(l, "a", [])', 'E745:') |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1103 | |
| 1104 | let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'} |
| 1105 | call assert_equal(2, count(d, 'a')) |
| 1106 | call assert_equal(1, count(d, 'A')) |
| 1107 | call assert_equal(1, count(d, 'b')) |
| 1108 | call assert_equal(0, count(d, 'B')) |
| 1109 | |
| 1110 | call assert_equal(2, count(d, 'a', 0)) |
| 1111 | call assert_equal(1, count(d, 'A', 0)) |
| 1112 | call assert_equal(1, count(d, 'b', 0)) |
| 1113 | call assert_equal(0, count(d, 'B', 0)) |
| 1114 | |
| 1115 | call assert_equal(3, count(d, 'a', 1)) |
| 1116 | call assert_equal(3, count(d, 'A', 1)) |
| 1117 | call assert_equal(1, count(d, 'b', 1)) |
| 1118 | call assert_equal(1, count(d, 'B', 1)) |
| 1119 | call assert_equal(0, count(d, 'c', 1)) |
| 1120 | |
| 1121 | call assert_fails('call count(d, "a", 0, 1)', 'E474:') |
Bram Moolenaar | 9966b21 | 2017-07-28 16:46:57 +0200 | [diff] [blame] | 1122 | |
| 1123 | call assert_equal(0, count("foo", "bar")) |
| 1124 | call assert_equal(1, count("foo", "oo")) |
| 1125 | call assert_equal(2, count("foo", "o")) |
| 1126 | call assert_equal(0, count("foo", "O")) |
| 1127 | call assert_equal(2, count("foo", "O", 1)) |
| 1128 | call assert_equal(2, count("fooooo", "oo")) |
Bram Moolenaar | 338e47f | 2017-12-19 11:55:26 +0100 | [diff] [blame] | 1129 | call assert_equal(0, count("foo", "")) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1130 | |
| 1131 | call assert_fails('call count(0, 0)', 'E712:') |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1132 | endfunc |
| 1133 | |
| 1134 | func Test_changenr() |
| 1135 | new Xchangenr |
| 1136 | call assert_equal(0, changenr()) |
| 1137 | norm ifoo |
| 1138 | call assert_equal(1, changenr()) |
| 1139 | set undolevels=10 |
| 1140 | norm Sbar |
| 1141 | call assert_equal(2, changenr()) |
| 1142 | undo |
| 1143 | call assert_equal(1, changenr()) |
| 1144 | redo |
| 1145 | call assert_equal(2, changenr()) |
| 1146 | bw! |
| 1147 | set undolevels& |
| 1148 | endfunc |
| 1149 | |
| 1150 | func Test_filewritable() |
| 1151 | new Xfilewritable |
| 1152 | write! |
| 1153 | call assert_equal(1, filewritable('Xfilewritable')) |
| 1154 | |
| 1155 | call assert_notequal(0, setfperm('Xfilewritable', 'r--r-----')) |
| 1156 | call assert_equal(0, filewritable('Xfilewritable')) |
| 1157 | |
| 1158 | call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----')) |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1159 | call assert_equal(1, 'Xfilewritable'->filewritable()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1160 | |
| 1161 | call assert_equal(0, filewritable('doesnotexist')) |
| 1162 | |
| 1163 | call delete('Xfilewritable') |
| 1164 | bw! |
| 1165 | endfunc |
| 1166 | |
Bram Moolenaar | 8295666 | 2018-10-06 15:18:45 +0200 | [diff] [blame] | 1167 | func Test_Executable() |
| 1168 | if has('win32') |
| 1169 | call assert_equal(1, executable('notepad')) |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1170 | call assert_equal(1, 'notepad.exe'->executable()) |
Bram Moolenaar | 8295666 | 2018-10-06 15:18:45 +0200 | [diff] [blame] | 1171 | call assert_equal(0, executable('notepad.exe.exe')) |
| 1172 | call assert_equal(0, executable('shell32.dll')) |
| 1173 | call assert_equal(0, executable('win.ini')) |
| 1174 | elseif has('unix') |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1175 | call assert_equal(1, 'cat'->executable()) |
Bram Moolenaar | a05a0d3 | 2018-10-07 18:43:05 +0200 | [diff] [blame] | 1176 | call assert_equal(0, executable('nodogshere')) |
Bram Moolenaar | d08b8c4 | 2019-07-24 14:59:45 +0200 | [diff] [blame] | 1177 | |
| 1178 | " get "cat" path and remove the leading / |
| 1179 | let catcmd = exepath('cat')[1:] |
| 1180 | new |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1181 | " check that the relative path works in / |
Bram Moolenaar | d08b8c4 | 2019-07-24 14:59:45 +0200 | [diff] [blame] | 1182 | lcd / |
| 1183 | call assert_equal(1, executable(catcmd)) |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1184 | call assert_equal('/' .. catcmd, catcmd->exepath()) |
Bram Moolenaar | d08b8c4 | 2019-07-24 14:59:45 +0200 | [diff] [blame] | 1185 | bwipe |
Bram Moolenaar | 8295666 | 2018-10-06 15:18:45 +0200 | [diff] [blame] | 1186 | endif |
| 1187 | endfunc |
| 1188 | |
Bram Moolenaar | 8662189 | 2019-03-30 21:51:28 +0100 | [diff] [blame] | 1189 | func Test_executable_longname() |
| 1190 | if !has('win32') |
| 1191 | return |
| 1192 | endif |
| 1193 | |
| 1194 | let fname = 'X' . repeat('あ', 200) . '.bat' |
| 1195 | call writefile([], fname) |
| 1196 | call assert_equal(1, executable(fname)) |
| 1197 | call delete(fname) |
| 1198 | endfunc |
| 1199 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1200 | func Test_hostname() |
| 1201 | let hostname_vim = hostname() |
| 1202 | if has('unix') |
| 1203 | let hostname_system = systemlist('uname -n')[0] |
| 1204 | call assert_equal(hostname_vim, hostname_system) |
| 1205 | endif |
| 1206 | endfunc |
| 1207 | |
| 1208 | func Test_getpid() |
| 1209 | " getpid() always returns the same value within a vim instance. |
| 1210 | call assert_equal(getpid(), getpid()) |
| 1211 | if has('unix') |
| 1212 | call assert_equal(systemlist('echo $PPID')[0], string(getpid())) |
| 1213 | endif |
| 1214 | endfunc |
| 1215 | |
| 1216 | func Test_hlexists() |
| 1217 | call assert_equal(0, hlexists('does_not_exist')) |
Bram Moolenaar | f9f24ce | 2019-08-31 21:17:39 +0200 | [diff] [blame] | 1218 | call assert_equal(0, 'Number'->hlexists()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1219 | call assert_equal(0, highlight_exists('does_not_exist')) |
| 1220 | call assert_equal(0, highlight_exists('Number')) |
| 1221 | syntax on |
| 1222 | call assert_equal(0, hlexists('does_not_exist')) |
| 1223 | call assert_equal(1, hlexists('Number')) |
| 1224 | call assert_equal(0, highlight_exists('does_not_exist')) |
| 1225 | call assert_equal(1, highlight_exists('Number')) |
| 1226 | syntax off |
| 1227 | endfunc |
| 1228 | |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 1229 | " Test for the col() function |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1230 | func Test_col() |
| 1231 | new |
| 1232 | call setline(1, 'abcdef') |
| 1233 | norm gg4|mx6|mY2| |
| 1234 | call assert_equal(2, col('.')) |
| 1235 | call assert_equal(7, col('$')) |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 1236 | call assert_equal(2, col('v')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1237 | call assert_equal(4, col("'x")) |
| 1238 | call assert_equal(6, col("'Y")) |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1239 | call assert_equal(2, [1, 2]->col()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1240 | call assert_equal(7, col([1, '$'])) |
| 1241 | |
| 1242 | call assert_equal(0, col('')) |
| 1243 | call assert_equal(0, col('x')) |
| 1244 | call assert_equal(0, col([2, '$'])) |
| 1245 | call assert_equal(0, col([1, 100])) |
| 1246 | call assert_equal(0, col([1])) |
Bram Moolenaar | 9d8d0b5 | 2020-04-24 22:47:31 +0200 | [diff] [blame] | 1247 | call assert_equal(0, col(test_null_list())) |
| 1248 | call assert_fails('let c = col({})', 'E731:') |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 1249 | |
| 1250 | " test for getting the visual start column |
| 1251 | func T() |
| 1252 | let g:Vcol = col('v') |
| 1253 | return '' |
| 1254 | endfunc |
| 1255 | let g:Vcol = 0 |
| 1256 | xmap <expr> <F2> T() |
| 1257 | exe "normal gg3|ve\<F2>" |
| 1258 | call assert_equal(3, g:Vcol) |
| 1259 | xunmap <F2> |
| 1260 | delfunc T |
| 1261 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1262 | " Test for the visual line start and end marks '< and '> |
| 1263 | call setline(1, ['one', 'one two', 'one two three']) |
| 1264 | "normal! ggVG |
| 1265 | call feedkeys("ggVG\<Esc>", 'xt') |
| 1266 | call assert_equal(1, col("'<")) |
| 1267 | call assert_equal(14, col("'>")) |
| 1268 | " Delete the last line of the visually selected region |
| 1269 | $d |
| 1270 | call assert_notequal(14, col("'>")) |
| 1271 | |
| 1272 | " Test with 'virtualedit' |
| 1273 | set virtualedit=all |
| 1274 | call cursor(1, 10) |
| 1275 | call assert_equal(4, col('.')) |
| 1276 | set virtualedit& |
| 1277 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1278 | bw! |
| 1279 | endfunc |
| 1280 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1281 | " Test for input() |
| 1282 | func Test_input_func() |
| 1283 | " Test for prompt with multiple lines |
| 1284 | redir => v |
| 1285 | call feedkeys(":let c = input(\"A\\nB\\nC\\n? \")\<CR>B\<CR>", 'xt') |
| 1286 | redir END |
| 1287 | call assert_equal("B", c) |
| 1288 | call assert_equal(['A', 'B', 'C'], split(v, "\n")) |
| 1289 | |
| 1290 | " Test for default value |
| 1291 | call feedkeys(":let c = input('color? ', 'red')\<CR>\<CR>", 'xt') |
| 1292 | call assert_equal('red', c) |
| 1293 | |
| 1294 | " Test for completion at the input prompt |
| 1295 | func! Tcomplete(arglead, cmdline, pos) |
| 1296 | return "item1\nitem2\nitem3" |
| 1297 | endfunc |
| 1298 | call feedkeys(":let c = input('Q? ', '' , 'custom,Tcomplete')\<CR>" |
| 1299 | \ .. "\<C-A>\<CR>", 'xt') |
| 1300 | delfunc Tcomplete |
| 1301 | call assert_equal('item1 item2 item3', c) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1302 | |
| 1303 | call assert_fails("call input('F:', '', 'invalid')", 'E180:') |
| 1304 | call assert_fails("call input('F:', '', [])", 'E730:') |
| 1305 | endfunc |
| 1306 | |
| 1307 | " Test for the inputdialog() function |
| 1308 | func Test_inputdialog() |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1309 | if has('gui_running') |
| 1310 | call assert_fails('let v=inputdialog([], "xx")', 'E730:') |
| 1311 | call assert_fails('let v=inputdialog("Q", [])', 'E730:') |
| 1312 | else |
| 1313 | call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<CR>", 'xt') |
| 1314 | call assert_equal('xx', v) |
| 1315 | call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<Esc>", 'xt') |
| 1316 | call assert_equal('yy', v) |
| 1317 | endif |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1318 | endfunc |
| 1319 | |
| 1320 | " Test for inputlist() |
Bram Moolenaar | 947b39e | 2018-07-22 19:36:37 +0200 | [diff] [blame] | 1321 | func Test_inputlist() |
| 1322 | call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx') |
| 1323 | call assert_equal(1, c) |
Bram Moolenaar | f9f24ce | 2019-08-31 21:17:39 +0200 | [diff] [blame] | 1324 | call feedkeys(":let c = ['Select color:', '1. red', '2. green', '3. blue']->inputlist()\<cr>2\<cr>", 'tx') |
Bram Moolenaar | 947b39e | 2018-07-22 19:36:37 +0200 | [diff] [blame] | 1325 | call assert_equal(2, c) |
| 1326 | call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx') |
| 1327 | call assert_equal(3, c) |
| 1328 | |
Bram Moolenaar | cde0ff3 | 2020-04-04 14:00:39 +0200 | [diff] [blame] | 1329 | " Use backspace to delete characters in the prompt |
| 1330 | call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<BS>3\<BS>2\<cr>", 'tx') |
| 1331 | call assert_equal(2, c) |
| 1332 | |
| 1333 | " Use mouse to make a selection |
| 1334 | call test_setmouse(&lines - 3, 2) |
| 1335 | call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<LeftMouse>", 'tx') |
| 1336 | call assert_equal(1, c) |
| 1337 | " Mouse click outside of the list |
| 1338 | call test_setmouse(&lines - 6, 2) |
| 1339 | call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<LeftMouse>", 'tx') |
| 1340 | call assert_equal(-2, c) |
| 1341 | |
Bram Moolenaar | 947b39e | 2018-07-22 19:36:37 +0200 | [diff] [blame] | 1342 | call assert_fails('call inputlist("")', 'E686:') |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 1343 | call assert_fails('call inputlist(test_null_list())', 'E686:') |
Bram Moolenaar | 947b39e | 2018-07-22 19:36:37 +0200 | [diff] [blame] | 1344 | endfunc |
| 1345 | |
Bram Moolenaar | caf6434 | 2017-03-02 22:11:33 +0100 | [diff] [blame] | 1346 | func Test_balloon_show() |
Bram Moolenaar | a0107bd | 2017-03-02 22:48:01 +0100 | [diff] [blame] | 1347 | if has('balloon_eval') |
| 1348 | " This won't do anything but must not crash either. |
| 1349 | call balloon_show('hi!') |
Bram Moolenaar | 7d8ea0b | 2020-01-27 23:01:30 +0100 | [diff] [blame] | 1350 | if !has('gui_running') |
| 1351 | call balloon_show(range(3)) |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1352 | call balloon_show([]) |
Bram Moolenaar | 7d8ea0b | 2020-01-27 23:01:30 +0100 | [diff] [blame] | 1353 | endif |
Bram Moolenaar | a0107bd | 2017-03-02 22:48:01 +0100 | [diff] [blame] | 1354 | endif |
Bram Moolenaar | caf6434 | 2017-03-02 22:11:33 +0100 | [diff] [blame] | 1355 | endfunc |
Bram Moolenaar | 2c90d51 | 2017-03-18 22:35:30 +0100 | [diff] [blame] | 1356 | |
| 1357 | func Test_setbufvar_options() |
| 1358 | " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the |
| 1359 | " window layout. |
| 1360 | call assert_equal(1, winnr('$')) |
| 1361 | split dummy_preview |
| 1362 | resize 2 |
| 1363 | set winfixheight winfixwidth |
| 1364 | let prev_id = win_getid() |
| 1365 | |
| 1366 | wincmd j |
| 1367 | let wh = winheight('.') |
| 1368 | let dummy_buf = bufnr('dummy_buf1', v:true) |
| 1369 | call setbufvar(dummy_buf, '&buftype', 'nofile') |
| 1370 | execute 'belowright vertical split #' . dummy_buf |
| 1371 | call assert_equal(wh, winheight('.')) |
| 1372 | let dum1_id = win_getid() |
| 1373 | |
| 1374 | wincmd h |
| 1375 | let wh = winheight('.') |
| 1376 | let dummy_buf = bufnr('dummy_buf2', v:true) |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1377 | eval 'nofile'->setbufvar(dummy_buf, '&buftype') |
Bram Moolenaar | 2c90d51 | 2017-03-18 22:35:30 +0100 | [diff] [blame] | 1378 | execute 'belowright vertical split #' . dummy_buf |
| 1379 | call assert_equal(wh, winheight('.')) |
| 1380 | |
| 1381 | bwipe! |
| 1382 | call win_gotoid(prev_id) |
| 1383 | bwipe! |
| 1384 | call win_gotoid(dum1_id) |
| 1385 | bwipe! |
| 1386 | endfunc |
Bram Moolenaar | d4863aa | 2017-04-07 19:50:12 +0200 | [diff] [blame] | 1387 | |
| 1388 | func Test_redo_in_nested_functions() |
| 1389 | nnoremap g. :set opfunc=Operator<CR>g@ |
| 1390 | function Operator( type, ... ) |
| 1391 | let @x = 'XXX' |
| 1392 | execute 'normal! g`[' . (a:type ==# 'line' ? 'V' : 'v') . 'g`]' . '"xp' |
| 1393 | endfunction |
| 1394 | |
| 1395 | function! Apply() |
| 1396 | 5,6normal! . |
| 1397 | endfunction |
| 1398 | |
| 1399 | new |
| 1400 | call setline(1, repeat(['some "quoted" text', 'more "quoted" text'], 3)) |
| 1401 | 1normal g.i" |
| 1402 | call assert_equal('some "XXX" text', getline(1)) |
| 1403 | 3,4normal . |
| 1404 | call assert_equal('some "XXX" text', getline(3)) |
| 1405 | call assert_equal('more "XXX" text', getline(4)) |
| 1406 | call Apply() |
| 1407 | call assert_equal('some "XXX" text', getline(5)) |
| 1408 | call assert_equal('more "XXX" text', getline(6)) |
| 1409 | bwipe! |
| 1410 | |
| 1411 | nunmap g. |
| 1412 | delfunc Operator |
| 1413 | delfunc Apply |
| 1414 | endfunc |
Bram Moolenaar | 2061552 | 2017-06-05 18:46:26 +0200 | [diff] [blame] | 1415 | |
| 1416 | func Test_shellescape() |
| 1417 | let save_shell = &shell |
| 1418 | set shell=bash |
| 1419 | call assert_equal("'text'", shellescape('text')) |
Bram Moolenaar | aad222c | 2019-09-06 22:46:09 +0200 | [diff] [blame] | 1420 | call assert_equal("'te\"xt'", 'te"xt'->shellescape()) |
Bram Moolenaar | 2061552 | 2017-06-05 18:46:26 +0200 | [diff] [blame] | 1421 | call assert_equal("'te'\\''xt'", shellescape("te'xt")) |
| 1422 | |
| 1423 | call assert_equal("'te%xt'", shellescape("te%xt")) |
| 1424 | call assert_equal("'te\\%xt'", shellescape("te%xt", 1)) |
| 1425 | call assert_equal("'te#xt'", shellescape("te#xt")) |
| 1426 | call assert_equal("'te\\#xt'", shellescape("te#xt", 1)) |
| 1427 | call assert_equal("'te!xt'", shellescape("te!xt")) |
| 1428 | call assert_equal("'te\\!xt'", shellescape("te!xt", 1)) |
| 1429 | |
| 1430 | call assert_equal("'te\nxt'", shellescape("te\nxt")) |
| 1431 | call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1)) |
| 1432 | set shell=tcsh |
| 1433 | call assert_equal("'te\\!xt'", shellescape("te!xt")) |
| 1434 | call assert_equal("'te\\\\!xt'", shellescape("te!xt", 1)) |
| 1435 | call assert_equal("'te\\\nxt'", shellescape("te\nxt")) |
| 1436 | call assert_equal("'te\\\\\nxt'", shellescape("te\nxt", 1)) |
| 1437 | |
| 1438 | let &shell = save_shell |
| 1439 | endfunc |
Bram Moolenaar | 295ac5a | 2018-03-22 23:04:02 +0100 | [diff] [blame] | 1440 | |
| 1441 | func Test_trim() |
| 1442 | call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B")) |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 1443 | call assert_equal("Testing", " \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B"->trim()) |
Bram Moolenaar | 295ac5a | 2018-03-22 23:04:02 +0100 | [diff] [blame] | 1444 | call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t")) |
| 1445 | call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww")) |
| 1446 | call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail")) |
| 1447 | call assert_equal("\tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", " ")) |
| 1448 | call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx")) |
| 1449 | call assert_equal("RESERVE", trim("你RESERVE好", "你好")) |
| 1450 | call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好")) |
| 1451 | call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", )) |
| 1452 | call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好")) |
| 1453 | call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes")) |
| 1454 | call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses")) |
| 1455 | call assert_equal("留下", trim("这些些不要这些留下这些", "这些不要")) |
| 1456 | call assert_equal("", trim("", "")) |
| 1457 | call assert_equal("a", trim("a", "")) |
| 1458 | call assert_equal("", trim("", "a")) |
| 1459 | |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 1460 | let chars = join(map(range(1, 0x20) + [0xa0], {n -> n->nr2char()}), '') |
Bram Moolenaar | 295ac5a | 2018-03-22 23:04:02 +0100 | [diff] [blame] | 1461 | call assert_equal("x", trim(chars . "x" . chars)) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1462 | |
| 1463 | call assert_fails('let c=trim([])', 'E730:') |
Bram Moolenaar | 295ac5a | 2018-03-22 23:04:02 +0100 | [diff] [blame] | 1464 | endfunc |
Bram Moolenaar | 0b6d911 | 2018-05-22 20:35:17 +0200 | [diff] [blame] | 1465 | |
| 1466 | " Test for reg_recording() and reg_executing() |
| 1467 | func Test_reg_executing_and_recording() |
| 1468 | let s:reg_stat = '' |
| 1469 | func s:save_reg_stat() |
| 1470 | let s:reg_stat = reg_recording() . ':' . reg_executing() |
| 1471 | return '' |
| 1472 | endfunc |
| 1473 | |
| 1474 | new |
| 1475 | call s:save_reg_stat() |
| 1476 | call assert_equal(':', s:reg_stat) |
| 1477 | call feedkeys("qa\"=s:save_reg_stat()\<CR>pq", 'xt') |
| 1478 | call assert_equal('a:', s:reg_stat) |
| 1479 | call feedkeys("@a", 'xt') |
| 1480 | call assert_equal(':a', s:reg_stat) |
| 1481 | call feedkeys("qb@aq", 'xt') |
| 1482 | call assert_equal('b:a', s:reg_stat) |
| 1483 | call feedkeys("q\"\"=s:save_reg_stat()\<CR>pq", 'xt') |
| 1484 | call assert_equal('":', s:reg_stat) |
| 1485 | |
Bram Moolenaar | cce713d | 2019-03-04 11:40:12 +0100 | [diff] [blame] | 1486 | " :normal command saves and restores reg_executing |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1487 | let s:reg_stat = '' |
Bram Moolenaar | cce713d | 2019-03-04 11:40:12 +0100 | [diff] [blame] | 1488 | let @q = ":call TestFunc()\<CR>:call s:save_reg_stat()\<CR>" |
| 1489 | func TestFunc() abort |
| 1490 | normal! ia |
| 1491 | endfunc |
| 1492 | call feedkeys("@q", 'xt') |
| 1493 | call assert_equal(':q', s:reg_stat) |
| 1494 | delfunc TestFunc |
| 1495 | |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1496 | " getchar() command saves and restores reg_executing |
| 1497 | map W :call TestFunc()<CR> |
| 1498 | let @q = "W" |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1499 | let g:typed = '' |
| 1500 | let g:regs = [] |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1501 | func TestFunc() abort |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1502 | let g:regs += [reg_executing()] |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1503 | let g:typed = getchar(0) |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1504 | let g:regs += [reg_executing()] |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1505 | endfunc |
| 1506 | call feedkeys("@qy", 'xt') |
| 1507 | call assert_equal(char2nr("y"), g:typed) |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1508 | call assert_equal(['q', 'q'], g:regs) |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1509 | delfunc TestFunc |
| 1510 | unmap W |
| 1511 | unlet g:typed |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1512 | unlet g:regs |
| 1513 | |
| 1514 | " input() command saves and restores reg_executing |
| 1515 | map W :call TestFunc()<CR> |
| 1516 | let @q = "W" |
| 1517 | let g:typed = '' |
| 1518 | let g:regs = [] |
| 1519 | func TestFunc() abort |
| 1520 | let g:regs += [reg_executing()] |
Bram Moolenaar | f9f24ce | 2019-08-31 21:17:39 +0200 | [diff] [blame] | 1521 | let g:typed = '?'->input() |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1522 | let g:regs += [reg_executing()] |
| 1523 | endfunc |
| 1524 | call feedkeys("@qy\<CR>", 'xt') |
| 1525 | call assert_equal("y", g:typed) |
| 1526 | call assert_equal(['q', 'q'], g:regs) |
| 1527 | delfunc TestFunc |
| 1528 | unmap W |
| 1529 | unlet g:typed |
| 1530 | unlet g:regs |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1531 | |
Bram Moolenaar | 0b6d911 | 2018-05-22 20:35:17 +0200 | [diff] [blame] | 1532 | bwipe! |
| 1533 | delfunc s:save_reg_stat |
| 1534 | unlet s:reg_stat |
| 1535 | endfunc |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1536 | |
Bram Moolenaar | f9f24ce | 2019-08-31 21:17:39 +0200 | [diff] [blame] | 1537 | func Test_inputsecret() |
| 1538 | map W :call TestFunc()<CR> |
| 1539 | let @q = "W" |
| 1540 | let g:typed1 = '' |
| 1541 | let g:typed2 = '' |
| 1542 | let g:regs = [] |
| 1543 | func TestFunc() abort |
| 1544 | let g:typed1 = '?'->inputsecret() |
| 1545 | let g:typed2 = inputsecret('password: ') |
| 1546 | endfunc |
| 1547 | call feedkeys("@qsomething\<CR>else\<CR>", 'xt') |
| 1548 | call assert_equal("something", g:typed1) |
| 1549 | call assert_equal("else", g:typed2) |
| 1550 | delfunc TestFunc |
| 1551 | unmap W |
| 1552 | unlet g:typed1 |
| 1553 | unlet g:typed2 |
| 1554 | endfunc |
| 1555 | |
Bram Moolenaar | 5d712e4 | 2019-09-03 23:37:01 +0200 | [diff] [blame] | 1556 | func Test_getchar() |
| 1557 | call feedkeys('a', '') |
| 1558 | call assert_equal(char2nr('a'), getchar()) |
| 1559 | |
Bram Moolenaar | db3a205 | 2019-11-16 18:22:41 +0100 | [diff] [blame] | 1560 | call setline(1, 'xxxx') |
Bram Moolenaar | 5d712e4 | 2019-09-03 23:37:01 +0200 | [diff] [blame] | 1561 | call test_setmouse(1, 3) |
| 1562 | let v:mouse_win = 9 |
| 1563 | let v:mouse_winid = 9 |
| 1564 | let v:mouse_lnum = 9 |
| 1565 | let v:mouse_col = 9 |
| 1566 | call feedkeys("\<S-LeftMouse>", '') |
| 1567 | call assert_equal("\<S-LeftMouse>", getchar()) |
| 1568 | call assert_equal(1, v:mouse_win) |
| 1569 | call assert_equal(win_getid(1), v:mouse_winid) |
| 1570 | call assert_equal(1, v:mouse_lnum) |
| 1571 | call assert_equal(3, v:mouse_col) |
Bram Moolenaar | db3a205 | 2019-11-16 18:22:41 +0100 | [diff] [blame] | 1572 | enew! |
Bram Moolenaar | 5d712e4 | 2019-09-03 23:37:01 +0200 | [diff] [blame] | 1573 | endfunc |
| 1574 | |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1575 | func Test_libcall_libcallnr() |
| 1576 | if !has('libcall') |
| 1577 | return |
| 1578 | endif |
| 1579 | |
| 1580 | if has('win32') |
| 1581 | let libc = 'msvcrt.dll' |
| 1582 | elseif has('mac') |
| 1583 | let libc = 'libSystem.B.dylib' |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 1584 | elseif executable('ldd') |
| 1585 | let libc = matchstr(split(system('ldd ' . GetVimProg())), '/libc\.so\>') |
| 1586 | endif |
| 1587 | if get(l:, 'libc', '') ==# '' |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1588 | " On Unix, libc.so can be in various places. |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 1589 | if has('linux') |
| 1590 | " There is not documented but regarding the 1st argument of glibc's |
| 1591 | " dlopen an empty string and nullptr are equivalent, so using an empty |
| 1592 | " string for the 1st argument of libcall allows to call functions. |
| 1593 | let libc = '' |
| 1594 | elseif has('sun') |
| 1595 | " Set the path to libc.so according to the architecture. |
| 1596 | let test_bits = system('file ' . GetVimProg()) |
| 1597 | let test_arch = system('uname -p') |
| 1598 | if test_bits =~ '64-bit' && test_arch =~ 'sparc' |
| 1599 | let libc = '/usr/lib/sparcv9/libc.so' |
| 1600 | elseif test_bits =~ '64-bit' && test_arch =~ 'i386' |
| 1601 | let libc = '/usr/lib/amd64/libc.so' |
| 1602 | else |
| 1603 | let libc = '/usr/lib/libc.so' |
| 1604 | endif |
| 1605 | else |
| 1606 | " Unfortunately skip this test until a good way is found. |
| 1607 | return |
| 1608 | endif |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1609 | endif |
| 1610 | |
| 1611 | if has('win32') |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 1612 | call assert_equal($USERPROFILE, 'USERPROFILE'->libcall(libc, 'getenv')) |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1613 | else |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 1614 | call assert_equal($HOME, 'HOME'->libcall(libc, 'getenv')) |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1615 | endif |
| 1616 | |
| 1617 | " If function returns NULL, libcall() should return an empty string. |
| 1618 | call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT')) |
| 1619 | |
| 1620 | " Test libcallnr() with string and integer argument. |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 1621 | call assert_equal(4, 'abcd'->libcallnr(libc, 'strlen')) |
| 1622 | call assert_equal(char2nr('A'), char2nr('a')->libcallnr(libc, 'toupper')) |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1623 | |
| 1624 | call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:') |
| 1625 | call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:') |
| 1626 | |
| 1627 | call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:') |
| 1628 | call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:') |
| 1629 | endfunc |
Bram Moolenaar | d90a144 | 2018-07-15 20:24:31 +0200 | [diff] [blame] | 1630 | |
| 1631 | sandbox function Fsandbox() |
| 1632 | normal ix |
| 1633 | endfunc |
| 1634 | |
| 1635 | func Test_func_sandbox() |
| 1636 | sandbox let F = {-> 'hello'} |
| 1637 | call assert_equal('hello', F()) |
| 1638 | |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1639 | sandbox let F = {-> "normal ix\<Esc>"->execute()} |
Bram Moolenaar | d90a144 | 2018-07-15 20:24:31 +0200 | [diff] [blame] | 1640 | call assert_fails('call F()', 'E48:') |
| 1641 | unlet F |
| 1642 | |
| 1643 | call assert_fails('call Fsandbox()', 'E48:') |
| 1644 | delfunc Fsandbox |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1645 | |
| 1646 | " From a sandbox try to set a predefined variable (which cannot be modified |
| 1647 | " from a sandbox) |
| 1648 | call assert_fails('sandbox let v:lnum = 10', 'E794:') |
Bram Moolenaar | d90a144 | 2018-07-15 20:24:31 +0200 | [diff] [blame] | 1649 | endfunc |
Bram Moolenaar | 9e353b5 | 2018-11-04 23:39:38 +0100 | [diff] [blame] | 1650 | |
| 1651 | func EditAnotherFile() |
| 1652 | let word = expand('<cword>') |
| 1653 | edit Xfuncrange2 |
| 1654 | endfunc |
| 1655 | |
| 1656 | func Test_func_range_with_edit() |
| 1657 | " Define a function that edits another buffer, then call it with a range that |
| 1658 | " is invalid in that buffer. |
| 1659 | call writefile(['just one line'], 'Xfuncrange2') |
| 1660 | new |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1661 | eval 10->range()->setline(1) |
Bram Moolenaar | 9e353b5 | 2018-11-04 23:39:38 +0100 | [diff] [blame] | 1662 | write Xfuncrange1 |
| 1663 | call assert_fails('5,8call EditAnotherFile()', 'E16:') |
| 1664 | |
| 1665 | call delete('Xfuncrange1') |
| 1666 | call delete('Xfuncrange2') |
| 1667 | bwipe! |
| 1668 | endfunc |
Bram Moolenaar | ded5f1b | 2018-11-10 17:33:29 +0100 | [diff] [blame] | 1669 | |
| 1670 | func Test_func_exists_on_reload() |
| 1671 | call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists') |
| 1672 | call assert_equal(0, exists('*ExistingFunction')) |
| 1673 | source Xfuncexists |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1674 | call assert_equal(1, '*ExistingFunction'->exists()) |
Bram Moolenaar | ded5f1b | 2018-11-10 17:33:29 +0100 | [diff] [blame] | 1675 | " Redefining a function when reloading a script is OK. |
| 1676 | source Xfuncexists |
| 1677 | call assert_equal(1, exists('*ExistingFunction')) |
| 1678 | |
| 1679 | " But redefining in another script is not OK. |
| 1680 | call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2') |
| 1681 | call assert_fails('source Xfuncexists2', 'E122:') |
| 1682 | |
| 1683 | delfunc ExistingFunction |
| 1684 | call assert_equal(0, exists('*ExistingFunction')) |
| 1685 | call writefile([ |
| 1686 | \ 'func ExistingFunction()', 'echo "yes"', 'endfunc', |
| 1687 | \ 'func ExistingFunction()', 'echo "no"', 'endfunc', |
| 1688 | \ ], 'Xfuncexists') |
| 1689 | call assert_fails('source Xfuncexists', 'E122:') |
| 1690 | call assert_equal(1, exists('*ExistingFunction')) |
| 1691 | |
| 1692 | call delete('Xfuncexists2') |
| 1693 | call delete('Xfuncexists') |
| 1694 | delfunc ExistingFunction |
| 1695 | endfunc |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1696 | |
| 1697 | " Test confirm({msg} [, {choices} [, {default} [, {type}]]]) |
| 1698 | func Test_confirm() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1699 | CheckUnix |
| 1700 | CheckNotGui |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1701 | |
| 1702 | call feedkeys('o', 'L') |
| 1703 | let a = confirm('Press O to proceed') |
| 1704 | call assert_equal(1, a) |
| 1705 | |
| 1706 | call feedkeys('y', 'L') |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1707 | let a = 'Are you sure?'->confirm("&Yes\n&No") |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1708 | call assert_equal(1, a) |
| 1709 | |
| 1710 | call feedkeys('n', 'L') |
| 1711 | let a = confirm('Are you sure?', "&Yes\n&No") |
| 1712 | call assert_equal(2, a) |
| 1713 | |
| 1714 | " confirm() should return 0 when pressing CTRL-C. |
Bram Moolenaar | 7929651 | 2020-03-22 16:17:14 +0100 | [diff] [blame] | 1715 | call feedkeys("\<C-C>", 'L') |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1716 | let a = confirm('Are you sure?', "&Yes\n&No") |
| 1717 | call assert_equal(0, a) |
| 1718 | |
| 1719 | " <Esc> requires another character to avoid it being seen as the start of an |
| 1720 | " escape sequence. Zero should be harmless. |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1721 | eval "\<Esc>0"->feedkeys('L') |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1722 | let a = confirm('Are you sure?', "&Yes\n&No") |
| 1723 | call assert_equal(0, a) |
| 1724 | |
| 1725 | " Default choice is returned when pressing <CR>. |
| 1726 | call feedkeys("\<CR>", 'L') |
| 1727 | let a = confirm('Are you sure?', "&Yes\n&No") |
| 1728 | call assert_equal(1, a) |
| 1729 | |
| 1730 | call feedkeys("\<CR>", 'L') |
| 1731 | let a = confirm('Are you sure?', "&Yes\n&No", 2) |
| 1732 | call assert_equal(2, a) |
| 1733 | |
| 1734 | call feedkeys("\<CR>", 'L') |
| 1735 | let a = confirm('Are you sure?', "&Yes\n&No", 0) |
| 1736 | call assert_equal(0, a) |
| 1737 | |
| 1738 | " Test with the {type} 4th argument |
| 1739 | for type in ['Error', 'Question', 'Info', 'Warning', 'Generic'] |
| 1740 | call feedkeys('y', 'L') |
| 1741 | let a = confirm('Are you sure?', "&Yes\n&No\n", 1, type) |
| 1742 | call assert_equal(1, a) |
| 1743 | endfor |
| 1744 | |
| 1745 | call assert_fails('call confirm([])', 'E730:') |
| 1746 | call assert_fails('call confirm("Are you sure?", [])', 'E730:') |
| 1747 | call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", [])', 'E745:') |
| 1748 | call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", 0, [])', 'E730:') |
| 1749 | endfunc |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 1750 | |
| 1751 | func Test_platform_name() |
| 1752 | " The system matches at most only one name. |
| 1753 | let names = ['amiga', 'beos', 'bsd', 'hpux', 'linux', 'mac', 'qnx', 'sun', 'vms', 'win32', 'win32unix'] |
| 1754 | call assert_inrange(0, 1, len(filter(copy(names), 'has(v:val)'))) |
| 1755 | |
| 1756 | " Is Unix? |
| 1757 | call assert_equal(has('beos'), has('beos') && has('unix')) |
| 1758 | call assert_equal(has('bsd'), has('bsd') && has('unix')) |
| 1759 | call assert_equal(has('hpux'), has('hpux') && has('unix')) |
| 1760 | call assert_equal(has('linux'), has('linux') && has('unix')) |
| 1761 | call assert_equal(has('mac'), has('mac') && has('unix')) |
| 1762 | call assert_equal(has('qnx'), has('qnx') && has('unix')) |
| 1763 | call assert_equal(has('sun'), has('sun') && has('unix')) |
| 1764 | call assert_equal(has('win32'), has('win32') && !has('unix')) |
| 1765 | call assert_equal(has('win32unix'), has('win32unix') && has('unix')) |
| 1766 | |
| 1767 | if has('unix') && executable('uname') |
| 1768 | let uname = system('uname') |
| 1769 | call assert_equal(uname =~? 'BeOS', has('beos')) |
Bram Moolenaar | a02e3f6 | 2019-02-07 21:27:14 +0100 | [diff] [blame] | 1770 | " GNU userland on BSD kernels (e.g., GNU/kFreeBSD) don't have BSD defined |
| 1771 | call assert_equal(uname =~? '\%(GNU/k\w\+\)\@<!BSD\|DragonFly', has('bsd')) |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 1772 | call assert_equal(uname =~? 'HP-UX', has('hpux')) |
| 1773 | call assert_equal(uname =~? 'Linux', has('linux')) |
| 1774 | call assert_equal(uname =~? 'Darwin', has('mac')) |
| 1775 | call assert_equal(uname =~? 'QNX', has('qnx')) |
| 1776 | call assert_equal(uname =~? 'SunOS', has('sun')) |
| 1777 | call assert_equal(uname =~? 'CYGWIN\|MSYS', has('win32unix')) |
| 1778 | endif |
| 1779 | endfunc |
Bram Moolenaar | 543c9b1 | 2019-04-05 22:50:40 +0200 | [diff] [blame] | 1780 | |
| 1781 | func Test_readdir() |
| 1782 | call mkdir('Xdir') |
| 1783 | call writefile([], 'Xdir/foo.txt') |
| 1784 | call writefile([], 'Xdir/bar.txt') |
| 1785 | call mkdir('Xdir/dir') |
| 1786 | |
| 1787 | " All results |
| 1788 | let files = readdir('Xdir') |
| 1789 | call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files)) |
| 1790 | |
| 1791 | " Only results containing "f" |
Bram Moolenaar | a0d1fef | 2019-09-04 22:29:14 +0200 | [diff] [blame] | 1792 | let files = 'Xdir'->readdir({ x -> stridx(x, 'f') !=- 1 }) |
Bram Moolenaar | 543c9b1 | 2019-04-05 22:50:40 +0200 | [diff] [blame] | 1793 | call assert_equal(['foo.txt'], sort(files)) |
| 1794 | |
| 1795 | " Only .txt files |
| 1796 | let files = readdir('Xdir', { x -> x =~ '.txt$' }) |
| 1797 | call assert_equal(['bar.txt', 'foo.txt'], sort(files)) |
| 1798 | |
| 1799 | " Only .txt files with string |
| 1800 | let files = readdir('Xdir', 'v:val =~ ".txt$"') |
| 1801 | call assert_equal(['bar.txt', 'foo.txt'], sort(files)) |
| 1802 | |
| 1803 | " Limit to 1 result. |
| 1804 | let l = [] |
| 1805 | let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1}) |
| 1806 | call assert_equal(1, len(files)) |
| 1807 | |
Bram Moolenaar | 27da7de | 2019-09-03 17:13:37 +0200 | [diff] [blame] | 1808 | " Nested readdir() must not crash |
| 1809 | let files = readdir('Xdir', 'readdir("Xdir", "1") != []') |
| 1810 | call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt']) |
| 1811 | |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1812 | eval 'Xdir'->delete('rf') |
Bram Moolenaar | 543c9b1 | 2019-04-05 22:50:40 +0200 | [diff] [blame] | 1813 | endfunc |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1814 | |
Bram Moolenaar | 701ff0a | 2019-05-24 14:14:14 +0200 | [diff] [blame] | 1815 | func Test_delete_rf() |
| 1816 | call mkdir('Xdir') |
| 1817 | call writefile([], 'Xdir/foo.txt') |
| 1818 | call writefile([], 'Xdir/bar.txt') |
| 1819 | call mkdir('Xdir/[a-1]') " issue #696 |
| 1820 | call writefile([], 'Xdir/[a-1]/foo.txt') |
| 1821 | call writefile([], 'Xdir/[a-1]/bar.txt') |
| 1822 | call assert_true(filereadable('Xdir/foo.txt')) |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1823 | call assert_true('Xdir/[a-1]/foo.txt'->filereadable()) |
Bram Moolenaar | 701ff0a | 2019-05-24 14:14:14 +0200 | [diff] [blame] | 1824 | |
| 1825 | call assert_equal(0, delete('Xdir', 'rf')) |
| 1826 | call assert_false(filereadable('Xdir/foo.txt')) |
| 1827 | call assert_false(filereadable('Xdir/[a-1]/foo.txt')) |
| 1828 | endfunc |
| 1829 | |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1830 | func Test_call() |
| 1831 | call assert_equal(3, call('len', [123])) |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 1832 | call assert_equal(3, 'len'->call([123])) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1833 | call assert_fails("call call('len', 123)", 'E714:') |
| 1834 | call assert_equal(0, call('', [])) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 1835 | call assert_equal(0, call('len', test_null_list())) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1836 | |
| 1837 | function Mylen() dict |
| 1838 | return len(self.data) |
| 1839 | endfunction |
| 1840 | let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 1841 | eval mydict.len->call([], mydict)->assert_equal(4) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1842 | call assert_fails("call call('Mylen', [], 0)", 'E715:') |
| 1843 | endfunc |
| 1844 | |
| 1845 | func Test_char2nr() |
| 1846 | call assert_equal(12354, char2nr('あ', 1)) |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1847 | call assert_equal(120, 'x'->char2nr()) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 1848 | set encoding=latin1 |
| 1849 | call assert_equal(120, 'x'->char2nr()) |
| 1850 | set encoding=utf-8 |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1851 | endfunc |
| 1852 | |
| 1853 | func Test_eventhandler() |
| 1854 | call assert_equal(0, eventhandler()) |
| 1855 | endfunc |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1856 | |
| 1857 | func Test_bufadd_bufload() |
| 1858 | call assert_equal(0, bufexists('someName')) |
| 1859 | let buf = bufadd('someName') |
| 1860 | call assert_notequal(0, buf) |
| 1861 | call assert_equal(1, bufexists('someName')) |
| 1862 | call assert_equal(0, getbufvar(buf, '&buflisted')) |
| 1863 | call assert_equal(0, bufloaded(buf)) |
| 1864 | call bufload(buf) |
| 1865 | call assert_equal(1, bufloaded(buf)) |
| 1866 | call assert_equal([''], getbufline(buf, 1, '$')) |
| 1867 | |
| 1868 | let curbuf = bufnr('') |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 1869 | eval ['some', 'text']->writefile('XotherName') |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 1870 | let buf = 'XotherName'->bufadd() |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1871 | call assert_notequal(0, buf) |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 1872 | eval 'XotherName'->bufexists()->assert_equal(1) |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1873 | call assert_equal(0, getbufvar(buf, '&buflisted')) |
| 1874 | call assert_equal(0, bufloaded(buf)) |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 1875 | eval buf->bufload() |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1876 | call assert_equal(1, bufloaded(buf)) |
| 1877 | call assert_equal(['some', 'text'], getbufline(buf, 1, '$')) |
| 1878 | call assert_equal(curbuf, bufnr('')) |
| 1879 | |
Bram Moolenaar | 892ae72 | 2019-06-30 20:33:01 +0200 | [diff] [blame] | 1880 | let buf1 = bufadd('') |
| 1881 | let buf2 = bufadd('') |
| 1882 | call assert_notequal(0, buf1) |
| 1883 | call assert_notequal(0, buf2) |
| 1884 | call assert_notequal(buf1, buf2) |
| 1885 | call assert_equal(1, bufexists(buf1)) |
| 1886 | call assert_equal(1, bufexists(buf2)) |
| 1887 | call assert_equal(0, bufloaded(buf1)) |
| 1888 | exe 'bwipe ' .. buf1 |
| 1889 | call assert_equal(0, bufexists(buf1)) |
| 1890 | call assert_equal(1, bufexists(buf2)) |
| 1891 | exe 'bwipe ' .. buf2 |
| 1892 | call assert_equal(0, bufexists(buf2)) |
| 1893 | |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1894 | bwipe someName |
Bram Moolenaar | 3940ec6 | 2019-07-05 21:53:24 +0200 | [diff] [blame] | 1895 | bwipe XotherName |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1896 | call assert_equal(0, bufexists('someName')) |
Bram Moolenaar | 3940ec6 | 2019-07-05 21:53:24 +0200 | [diff] [blame] | 1897 | call delete('XotherName') |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1898 | endfunc |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1899 | |
| 1900 | func Test_state() |
| 1901 | CheckRunVimInTerminal |
| 1902 | |
Bram Moolenaar | 3ed9efc | 2020-03-26 16:50:57 +0100 | [diff] [blame] | 1903 | let getstate = ":echo 'state: ' .. g:state .. '; mode: ' .. g:mode\<CR>" |
| 1904 | |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1905 | let lines =<< trim END |
| 1906 | call setline(1, ['one', 'two', 'three']) |
| 1907 | map ;; gg |
Bram Moolenaar | b7a97ef | 2019-09-28 22:11:56 +0200 | [diff] [blame] | 1908 | set complete=. |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1909 | func RunTimer() |
| 1910 | call timer_start(10, {id -> execute('let g:state = state()') .. execute('let g:mode = mode()')}) |
| 1911 | endfunc |
| 1912 | au Filetype foobar let g:state = state()|let g:mode = mode() |
| 1913 | END |
| 1914 | call writefile(lines, 'XState') |
| 1915 | let buf = RunVimInTerminal('-S XState', #{rows: 6}) |
| 1916 | |
| 1917 | " Using a ":" command Vim is busy, thus "S" is returned |
| 1918 | call term_sendkeys(buf, ":echo 'state: ' .. state() .. '; mode: ' .. mode()\<CR>") |
| 1919 | call WaitForAssert({-> assert_match('state: S; mode: n', term_getline(buf, 6))}, 1000) |
| 1920 | call term_sendkeys(buf, ":\<CR>") |
| 1921 | |
| 1922 | " Using a timer callback |
| 1923 | call term_sendkeys(buf, ":call RunTimer()\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1924 | call TermWait(buf, 25) |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1925 | call term_sendkeys(buf, getstate) |
| 1926 | call WaitForAssert({-> assert_match('state: c; mode: n', term_getline(buf, 6))}, 1000) |
| 1927 | |
| 1928 | " Halfway a mapping |
| 1929 | call term_sendkeys(buf, ":call RunTimer()\<CR>;") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1930 | call TermWait(buf, 25) |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1931 | call term_sendkeys(buf, ";") |
| 1932 | call term_sendkeys(buf, getstate) |
| 1933 | call WaitForAssert({-> assert_match('state: mSc; mode: n', term_getline(buf, 6))}, 1000) |
| 1934 | |
Bram Moolenaar | b7a97ef | 2019-09-28 22:11:56 +0200 | [diff] [blame] | 1935 | " Insert mode completion (bit slower on Mac) |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1936 | call term_sendkeys(buf, ":call RunTimer()\<CR>Got\<C-N>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1937 | call TermWait(buf, 25) |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1938 | call term_sendkeys(buf, "\<Esc>") |
| 1939 | call term_sendkeys(buf, getstate) |
| 1940 | call WaitForAssert({-> assert_match('state: aSc; mode: i', term_getline(buf, 6))}, 1000) |
| 1941 | |
| 1942 | " Autocommand executing |
| 1943 | call term_sendkeys(buf, ":set filetype=foobar\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1944 | call TermWait(buf, 25) |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1945 | call term_sendkeys(buf, getstate) |
| 1946 | call WaitForAssert({-> assert_match('state: xS; mode: n', term_getline(buf, 6))}, 1000) |
| 1947 | |
| 1948 | " Todo: "w" - waiting for ch_evalexpr() |
| 1949 | |
| 1950 | " messages scrolled |
| 1951 | call term_sendkeys(buf, ":call RunTimer()\<CR>:echo \"one\\ntwo\\nthree\"\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1952 | call TermWait(buf, 25) |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1953 | call term_sendkeys(buf, "\<CR>") |
| 1954 | call term_sendkeys(buf, getstate) |
| 1955 | call WaitForAssert({-> assert_match('state: Scs; mode: r', term_getline(buf, 6))}, 1000) |
| 1956 | |
| 1957 | call StopVimInTerminal(buf) |
| 1958 | call delete('XState') |
| 1959 | endfunc |
Bram Moolenaar | 50985eb | 2020-01-27 22:09:39 +0100 | [diff] [blame] | 1960 | |
| 1961 | func Test_range() |
| 1962 | " destructuring |
| 1963 | let [x, y] = range(2) |
| 1964 | call assert_equal([0, 1], [x, y]) |
| 1965 | |
| 1966 | " index |
| 1967 | call assert_equal(4, range(1, 10)[3]) |
| 1968 | |
| 1969 | " add() |
| 1970 | call assert_equal([0, 1, 2, 3], add(range(3), 3)) |
| 1971 | call assert_equal([0, 1, 2, [0, 1, 2]], add([0, 1, 2], range(3))) |
| 1972 | call assert_equal([0, 1, 2, [0, 1, 2]], add(range(3), range(3))) |
| 1973 | |
| 1974 | " append() |
| 1975 | new |
| 1976 | call append('.', range(5)) |
| 1977 | call assert_equal(['', '0', '1', '2', '3', '4'], getline(1, '$')) |
| 1978 | bwipe! |
| 1979 | |
| 1980 | " appendbufline() |
| 1981 | new |
| 1982 | call appendbufline(bufnr(''), '.', range(5)) |
| 1983 | call assert_equal(['0', '1', '2', '3', '4', ''], getline(1, '$')) |
| 1984 | bwipe! |
| 1985 | |
| 1986 | " call() |
| 1987 | func TwoArgs(a, b) |
| 1988 | return [a:a, a:b] |
| 1989 | endfunc |
| 1990 | call assert_equal([0, 1], call('TwoArgs', range(2))) |
| 1991 | |
| 1992 | " col() |
| 1993 | new |
| 1994 | call setline(1, ['foo', 'bar']) |
| 1995 | call assert_equal(2, col(range(1, 2))) |
| 1996 | bwipe! |
| 1997 | |
| 1998 | " complete() |
| 1999 | execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>" |
| 2000 | " complete_info() |
| 2001 | execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>\<C-r>=[complete_info(range(5)), ''][1]\<CR>" |
| 2002 | |
| 2003 | " copy() |
| 2004 | call assert_equal([1, 2, 3], copy(range(1, 3))) |
| 2005 | |
| 2006 | " count() |
| 2007 | call assert_equal(0, count(range(0), 3)) |
| 2008 | call assert_equal(0, count(range(2), 3)) |
| 2009 | call assert_equal(1, count(range(5), 3)) |
| 2010 | |
| 2011 | " cursor() |
| 2012 | new |
| 2013 | call setline(1, ['aaa', 'bbb', 'ccc']) |
| 2014 | call cursor(range(1, 2)) |
| 2015 | call assert_equal([2, 1], [col('.'), line('.')]) |
| 2016 | bwipe! |
| 2017 | |
| 2018 | " deepcopy() |
| 2019 | call assert_equal([1, 2, 3], deepcopy(range(1, 3))) |
| 2020 | |
| 2021 | " empty() |
| 2022 | call assert_true(empty(range(0))) |
| 2023 | call assert_false(empty(range(2))) |
| 2024 | |
| 2025 | " execute() |
| 2026 | new |
| 2027 | call setline(1, ['aaa', 'bbb', 'ccc']) |
| 2028 | call execute(range(3)) |
| 2029 | call assert_equal(2, line('.')) |
| 2030 | bwipe! |
| 2031 | |
| 2032 | " extend() |
| 2033 | call assert_equal([1, 2, 3, 4], extend([1], range(2, 4))) |
| 2034 | call assert_equal([1, 2, 3, 4], extend(range(1, 1), range(2, 4))) |
| 2035 | call assert_equal([1, 2, 3, 4], extend(range(1, 1), [2, 3, 4])) |
| 2036 | |
| 2037 | " filter() |
| 2038 | call assert_equal([1, 3], filter(range(5), 'v:val % 2')) |
| 2039 | |
| 2040 | " funcref() |
| 2041 | call assert_equal([0, 1], funcref('TwoArgs', range(2))()) |
| 2042 | |
| 2043 | " function() |
| 2044 | call assert_equal([0, 1], function('TwoArgs', range(2))()) |
| 2045 | |
| 2046 | " garbagecollect() |
| 2047 | let thelist = [1, range(2), 3] |
| 2048 | let otherlist = range(3) |
| 2049 | call test_garbagecollect_now() |
| 2050 | |
| 2051 | " get() |
| 2052 | call assert_equal(4, get(range(1, 10), 3)) |
| 2053 | call assert_equal(-1, get(range(1, 10), 42, -1)) |
| 2054 | |
| 2055 | " index() |
| 2056 | call assert_equal(1, index(range(1, 5), 2)) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 2057 | call assert_fails("echo index([1, 2], 1, [])", 'E745:') |
Bram Moolenaar | 50985eb | 2020-01-27 22:09:39 +0100 | [diff] [blame] | 2058 | |
| 2059 | " inputlist() |
Bram Moolenaar | 272ca95 | 2020-01-28 20:49:11 +0100 | [diff] [blame] | 2060 | call feedkeys(":let result = inputlist(range(10))\<CR>1\<CR>", 'x') |
| 2061 | call assert_equal(1, result) |
| 2062 | call feedkeys(":let result = inputlist(range(3, 10))\<CR>1\<CR>", 'x') |
| 2063 | call assert_equal(1, result) |
Bram Moolenaar | 50985eb | 2020-01-27 22:09:39 +0100 | [diff] [blame] | 2064 | |
| 2065 | " insert() |
| 2066 | call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42)) |
| 2067 | call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42, 0)) |
| 2068 | call assert_equal([1, 42, 2, 3, 4, 5], insert(range(1, 5), 42, 1)) |
| 2069 | call assert_equal([1, 2, 3, 4, 42, 5], insert(range(1, 5), 42, 4)) |
| 2070 | call assert_equal([1, 2, 3, 4, 42, 5], insert(range(1, 5), 42, -1)) |
| 2071 | call assert_equal([1, 2, 3, 4, 5, 42], insert(range(1, 5), 42, 5)) |
| 2072 | |
| 2073 | " join() |
| 2074 | call assert_equal('0 1 2 3 4', join(range(5))) |
| 2075 | |
Bram Moolenaar | 272ca95 | 2020-01-28 20:49:11 +0100 | [diff] [blame] | 2076 | " json_encode() |
| 2077 | call assert_equal('[0,1,2,3]', json_encode(range(4))) |
| 2078 | |
Bram Moolenaar | 50985eb | 2020-01-27 22:09:39 +0100 | [diff] [blame] | 2079 | " len() |
| 2080 | call assert_equal(0, len(range(0))) |
| 2081 | call assert_equal(2, len(range(2))) |
| 2082 | call assert_equal(5, len(range(0, 12, 3))) |
| 2083 | call assert_equal(4, len(range(3, 0, -1))) |
| 2084 | |
| 2085 | " list2str() |
| 2086 | call assert_equal('ABC', list2str(range(65, 67))) |
Bram Moolenaar | 08f4157 | 2020-04-20 16:50:00 +0200 | [diff] [blame] | 2087 | call assert_fails('let s = list2str(5)', 'E474:') |
Bram Moolenaar | 50985eb | 2020-01-27 22:09:39 +0100 | [diff] [blame] | 2088 | |
| 2089 | " lock() |
| 2090 | let thelist = range(5) |
| 2091 | lockvar thelist |
| 2092 | |
| 2093 | " map() |
| 2094 | call assert_equal([0, 2, 4, 6, 8], map(range(5), 'v:val * 2')) |
| 2095 | |
| 2096 | " match() |
| 2097 | call assert_equal(3, match(range(5), 3)) |
| 2098 | |
| 2099 | " matchaddpos() |
| 2100 | highlight MyGreenGroup ctermbg=green guibg=green |
| 2101 | call matchaddpos('MyGreenGroup', range(line('.'), line('.'))) |
| 2102 | |
| 2103 | " matchend() |
| 2104 | call assert_equal(4, matchend(range(5), '4')) |
| 2105 | call assert_equal(3, matchend(range(1, 5), '4')) |
| 2106 | call assert_equal(-1, matchend(range(1, 5), '42')) |
| 2107 | |
| 2108 | " matchstrpos() |
| 2109 | call assert_equal(['4', 4, 0, 1], matchstrpos(range(5), '4')) |
| 2110 | call assert_equal(['4', 3, 0, 1], matchstrpos(range(1, 5), '4')) |
| 2111 | call assert_equal(['', -1, -1, -1], matchstrpos(range(1, 5), '42')) |
| 2112 | |
| 2113 | " max() reverse() |
| 2114 | call assert_equal(0, max(range(0))) |
| 2115 | call assert_equal(0, max(range(10, 9))) |
| 2116 | call assert_equal(9, max(range(10))) |
| 2117 | call assert_equal(18, max(range(0, 20, 3))) |
| 2118 | call assert_equal(20, max(range(20, 0, -3))) |
| 2119 | call assert_equal(99999, max(range(100000))) |
| 2120 | call assert_equal(99999, max(range(99999, 0, -1))) |
| 2121 | call assert_equal(99999, max(reverse(range(100000)))) |
| 2122 | call assert_equal(99999, max(reverse(range(99999, 0, -1)))) |
| 2123 | |
| 2124 | " min() reverse() |
| 2125 | call assert_equal(0, min(range(0))) |
| 2126 | call assert_equal(0, min(range(10, 9))) |
| 2127 | call assert_equal(5, min(range(5, 10))) |
| 2128 | call assert_equal(5, min(range(5, 10, 3))) |
| 2129 | call assert_equal(2, min(range(20, 0, -3))) |
| 2130 | call assert_equal(0, min(range(100000))) |
| 2131 | call assert_equal(0, min(range(99999, 0, -1))) |
| 2132 | call assert_equal(0, min(reverse(range(100000)))) |
| 2133 | call assert_equal(0, min(reverse(range(99999, 0, -1)))) |
| 2134 | |
| 2135 | " remove() |
| 2136 | call assert_equal(1, remove(range(1, 10), 0)) |
| 2137 | call assert_equal(2, remove(range(1, 10), 1)) |
| 2138 | call assert_equal(9, remove(range(1, 10), 8)) |
| 2139 | call assert_equal(10, remove(range(1, 10), 9)) |
| 2140 | call assert_equal(10, remove(range(1, 10), -1)) |
| 2141 | call assert_equal([3, 4, 5], remove(range(1, 10), 2, 4)) |
| 2142 | |
| 2143 | " repeat() |
| 2144 | call assert_equal([0, 1, 2, 0, 1, 2], repeat(range(3), 2)) |
| 2145 | call assert_equal([0, 1, 2], repeat(range(3), 1)) |
| 2146 | call assert_equal([], repeat(range(3), 0)) |
| 2147 | call assert_equal([], repeat(range(5, 4), 2)) |
| 2148 | call assert_equal([], repeat(range(5, 4), 0)) |
| 2149 | |
| 2150 | " reverse() |
| 2151 | call assert_equal([2, 1, 0], reverse(range(3))) |
| 2152 | call assert_equal([0, 1, 2, 3], reverse(range(3, 0, -1))) |
| 2153 | call assert_equal([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], reverse(range(10))) |
| 2154 | call assert_equal([20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10], reverse(range(10, 20))) |
| 2155 | call assert_equal([16, 13, 10], reverse(range(10, 18, 3))) |
| 2156 | call assert_equal([19, 16, 13, 10], reverse(range(10, 19, 3))) |
| 2157 | call assert_equal([19, 16, 13, 10], reverse(range(10, 20, 3))) |
| 2158 | call assert_equal([11, 14, 17, 20], reverse(range(20, 10, -3))) |
| 2159 | call assert_equal([], reverse(range(0))) |
| 2160 | |
| 2161 | " TODO: setpos() |
| 2162 | " new |
| 2163 | " call setline(1, repeat([''], bufnr(''))) |
| 2164 | " call setline(bufnr('') + 1, repeat('x', bufnr('') * 2 + 6)) |
| 2165 | " call setpos('x', range(bufnr(''), bufnr('') + 3)) |
| 2166 | " bwipe! |
| 2167 | |
| 2168 | " setreg() |
| 2169 | call setreg('a', range(3)) |
| 2170 | call assert_equal("0\n1\n2\n", getreg('a')) |
| 2171 | |
Bram Moolenaar | b099202 | 2020-01-30 14:55:42 +0100 | [diff] [blame] | 2172 | " settagstack() |
| 2173 | call settagstack(1, #{items : range(4)}) |
Bram Moolenaar | 94255df | 2020-02-05 20:10:33 +0100 | [diff] [blame] | 2174 | |
Bram Moolenaar | b099202 | 2020-01-30 14:55:42 +0100 | [diff] [blame] | 2175 | " sign_define() |
| 2176 | call assert_fails("call sign_define(range(5))", "E715:") |
| 2177 | call assert_fails("call sign_placelist(range(5))", "E715:") |
| 2178 | |
| 2179 | " sign_undefine() |
| 2180 | call assert_fails("call sign_undefine(range(5))", "E908:") |
| 2181 | |
| 2182 | " sign_unplacelist() |
| 2183 | call assert_fails("call sign_unplacelist(range(5))", "E715:") |
| 2184 | |
Bram Moolenaar | 50985eb | 2020-01-27 22:09:39 +0100 | [diff] [blame] | 2185 | " sort() |
| 2186 | call assert_equal([0, 1, 2, 3, 4, 5], sort(range(5, 0, -1))) |
| 2187 | |
| 2188 | " string() |
| 2189 | call assert_equal('[0, 1, 2, 3, 4]', string(range(5))) |
| 2190 | |
Bram Moolenaar | b099202 | 2020-01-30 14:55:42 +0100 | [diff] [blame] | 2191 | " taglist() with 'tagfunc' |
| 2192 | func TagFunc(pattern, flags, info) |
| 2193 | return range(10) |
| 2194 | endfunc |
| 2195 | set tagfunc=TagFunc |
| 2196 | call assert_fails("call taglist('asdf')", 'E987:') |
| 2197 | set tagfunc= |
Bram Moolenaar | 94255df | 2020-02-05 20:10:33 +0100 | [diff] [blame] | 2198 | |
Bram Moolenaar | b099202 | 2020-01-30 14:55:42 +0100 | [diff] [blame] | 2199 | " term_start() |
Bram Moolenaar | 705724e | 2020-01-31 21:13:42 +0100 | [diff] [blame] | 2200 | if has('terminal') && has('termguicolors') |
Bram Moolenaar | b099202 | 2020-01-30 14:55:42 +0100 | [diff] [blame] | 2201 | call assert_fails('call term_start(range(3, 4))', 'E474:') |
| 2202 | let g:terminal_ansi_colors = range(16) |
Bram Moolenaar | 94255df | 2020-02-05 20:10:33 +0100 | [diff] [blame] | 2203 | if has('win32') |
| 2204 | let cmd = "cmd /c dir" |
| 2205 | else |
| 2206 | let cmd = "ls" |
| 2207 | endif |
| 2208 | call assert_fails('call term_start("' .. cmd .. '", #{term_finish: "close"})', 'E475:') |
Bram Moolenaar | b099202 | 2020-01-30 14:55:42 +0100 | [diff] [blame] | 2209 | unlet g:terminal_ansi_colors |
| 2210 | endif |
| 2211 | |
Bram Moolenaar | 50985eb | 2020-01-27 22:09:39 +0100 | [diff] [blame] | 2212 | " type() |
| 2213 | call assert_equal(v:t_list, type(range(5))) |
| 2214 | |
| 2215 | " uniq() |
| 2216 | call assert_equal([0, 1, 2, 3, 4], uniq(range(5))) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 2217 | |
| 2218 | " errors |
| 2219 | call assert_fails('let x=range(2, 8, 0)', 'E726:') |
| 2220 | call assert_fails('let x=range(3, 1)', 'E727:') |
| 2221 | call assert_fails('let x=range(1, 3, -2)', 'E727:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 2222 | call assert_fails('let x=range([])', 'E745:') |
| 2223 | call assert_fails('let x=range(1, [])', 'E745:') |
| 2224 | call assert_fails('let x=range(1, 4, [])', 'E745:') |
Bram Moolenaar | 50985eb | 2020-01-27 22:09:39 +0100 | [diff] [blame] | 2225 | endfunc |
Bram Moolenaar | 4132eb5 | 2020-02-14 16:53:00 +0100 | [diff] [blame] | 2226 | |
| 2227 | func Test_echoraw() |
| 2228 | CheckScreendump |
| 2229 | |
| 2230 | " Normally used for escape codes, but let's test with a CR. |
| 2231 | let lines =<< trim END |
| 2232 | call echoraw("hello\<CR>x") |
| 2233 | END |
| 2234 | call writefile(lines, 'XTest_echoraw') |
| 2235 | let buf = RunVimInTerminal('-S XTest_echoraw', {'rows': 5, 'cols': 40}) |
| 2236 | call VerifyScreenDump(buf, 'Test_functions_echoraw', {}) |
| 2237 | |
| 2238 | " clean up |
| 2239 | call StopVimInTerminal(buf) |
| 2240 | call delete('XTest_echoraw') |
| 2241 | endfunc |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 2242 | |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 2243 | " Test for echo highlighting |
| 2244 | func Test_echohl() |
| 2245 | echohl Search |
| 2246 | echo 'Vim' |
| 2247 | call assert_equal('Vim', Screenline(&lines)) |
| 2248 | " TODO: How to check the highlight group used by echohl? |
| 2249 | " ScreenAttrs() returns all zeros. |
| 2250 | echohl None |
| 2251 | endfunc |
| 2252 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 2253 | " Test for the eval() function |
| 2254 | func Test_eval() |
| 2255 | call assert_fails("call eval('5 a')", 'E488:') |
| 2256 | endfunc |
| 2257 | |
| 2258 | " Test for the nr2char() function |
| 2259 | func Test_nr2char() |
| 2260 | set encoding=latin1 |
| 2261 | call assert_equal('@', nr2char(64)) |
| 2262 | set encoding=utf8 |
| 2263 | call assert_equal('a', nr2char(97, 1)) |
| 2264 | call assert_equal('a', nr2char(97, 0)) |
| 2265 | endfunc |
| 2266 | |
| 2267 | " Test for screenattr(), screenchar() and screenchars() functions |
| 2268 | func Test_screen_functions() |
| 2269 | call assert_equal(-1, screenattr(-1, -1)) |
| 2270 | call assert_equal(-1, screenchar(-1, -1)) |
| 2271 | call assert_equal([], screenchars(-1, -1)) |
| 2272 | endfunc |
| 2273 | |
Bram Moolenaar | 08f4157 | 2020-04-20 16:50:00 +0200 | [diff] [blame] | 2274 | " Test for getcurpos() and setpos() |
| 2275 | func Test_getcurpos_setpos() |
| 2276 | new |
| 2277 | call setline(1, ['012345678', '012345678']) |
| 2278 | normal gg6l |
| 2279 | let sp = getcurpos() |
| 2280 | normal 0 |
| 2281 | call setpos('.', sp) |
| 2282 | normal jyl |
| 2283 | call assert_equal('6', @") |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 2284 | call assert_equal(-1, setpos('.', test_null_list())) |
| 2285 | call assert_equal(-1, setpos('.', {})) |
Bram Moolenaar | 08f4157 | 2020-04-20 16:50:00 +0200 | [diff] [blame] | 2286 | close! |
| 2287 | endfunc |
| 2288 | |
Bram Moolenaar | 92b83cc | 2020-04-25 15:24:44 +0200 | [diff] [blame] | 2289 | " Test for glob() |
| 2290 | func Test_glob() |
| 2291 | call assert_equal('', glob(test_null_string())) |
| 2292 | call assert_equal('', globpath(test_null_string(), test_null_string())) |
| 2293 | endfunc |
| 2294 | |
| 2295 | " Test for browse() |
| 2296 | func Test_browse() |
| 2297 | CheckFeature browse |
| 2298 | call assert_fails('call browse([], "open", "x", "a.c")', 'E745:') |
| 2299 | endfunc |
| 2300 | |
| 2301 | " Test for browsedir() |
| 2302 | func Test_browsedir() |
| 2303 | CheckFeature browse |
| 2304 | call assert_fails('call browsedir("open", [])', 'E730:') |
| 2305 | endfunc |
| 2306 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 2307 | " vim: shiftwidth=2 sts=2 expandtab |