1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
|
local uv = vim.uv
local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local cimport = helpers.cimport
local eq = helpers.eq
local neq = helpers.neq
local ffi = helpers.ffi
local cstr = helpers.cstr
local to_cstr = helpers.to_cstr
local NULL = helpers.NULL
local OK = helpers.OK
local FAIL = helpers.FAIL
local mkdir = helpers.mkdir
cimport('string.h')
local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h')
local options = cimport('./src/nvim/option_vars.h')
local length = 0
local buffer = nil
describe('path.c', function()
describe('path_full_dir_name', function()
setup(function()
mkdir('unit-test-directory')
end)
teardown(function()
uv.fs_rmdir('unit-test-directory')
end)
local function path_full_dir_name(directory, buf, len)
directory = to_cstr(directory)
return cimp.path_full_dir_name(directory, buf, len)
end
before_each(function()
-- Create empty string buffer which will contain the resulting path.
length = string.len(uv.cwd()) + 22
buffer = cstr(length, '')
end)
itp('returns the absolute directory name of a given relative one', function()
local result = path_full_dir_name('..', buffer, length)
eq(OK, result)
local old_dir = uv.cwd()
uv.chdir('..')
local expected = uv.cwd()
uv.chdir(old_dir)
eq(expected, (ffi.string(buffer)))
end)
itp('returns the current directory name if the given string is empty', function()
eq(OK, (path_full_dir_name('', buffer, length)))
eq(uv.cwd(), (ffi.string(buffer)))
end)
itp('works with a normal relative dir', function()
local result = path_full_dir_name('unit-test-directory', buffer, length)
eq(uv.cwd() .. '/unit-test-directory', (ffi.string(buffer)))
eq(OK, result)
end)
itp('works with a non-existing relative dir', function()
local result = path_full_dir_name('does-not-exist', buffer, length)
eq(uv.cwd() .. '/does-not-exist', (ffi.string(buffer)))
eq(OK, result)
end)
itp('fails with a non-existing absolute dir', function()
eq(FAIL, path_full_dir_name('/does_not_exist', buffer, length))
end)
end)
describe('path_full_compare', function()
local function path_full_compare(s1, s2, cn, ee)
s1 = to_cstr(s1)
s2 = to_cstr(s2)
return cimp.path_full_compare(s1, s2, cn or 0, ee or 1)
end
local f1 = 'f1.o'
local f2 = 'f2.o'
before_each(function()
-- create the three files that will be used in this spec
io.open(f1, 'w'):close()
io.open(f2, 'w'):close()
end)
after_each(function()
os.remove(f1)
os.remove(f2)
end)
itp('returns kEqualFiles when passed the same file', function()
eq(cimp.kEqualFiles, (path_full_compare(f1, f1)))
end)
itp('returns kEqualFileNames when files that dont exist and have same name', function()
eq(cimp.kEqualFileNames, (path_full_compare('null.txt', 'null.txt', true)))
end)
itp('returns kBothFilesMissing when files that dont exist', function()
eq(cimp.kBothFilesMissing, (path_full_compare('null.txt', 'null.txt')))
end)
itp('returns kDifferentFiles when passed different files', function()
eq(cimp.kDifferentFiles, (path_full_compare(f1, f2)))
eq(cimp.kDifferentFiles, (path_full_compare(f2, f1)))
end)
itp('returns kOneFileMissing if only one does not exist', function()
eq(cimp.kOneFileMissing, (path_full_compare(f1, 'null.txt')))
eq(cimp.kOneFileMissing, (path_full_compare('null.txt', f1)))
end)
end)
describe('path_tail', function()
local function path_tail(file)
local res = cimp.path_tail((to_cstr(file)))
neq(NULL, res)
return ffi.string(res)
end
itp('returns the tail of a given file path', function()
eq('file.txt', path_tail('directory/file.txt'))
end)
itp('returns an empty string if file ends in a slash', function()
eq('', path_tail('directory/'))
end)
end)
describe('path_tail_with_sep', function()
local function path_tail_with_sep(file)
local res = cimp.path_tail_with_sep((to_cstr(file)))
neq(NULL, res)
return ffi.string(res)
end
itp('returns the tail of a file together with its separator', function()
eq('///file.txt', path_tail_with_sep('directory///file.txt'))
end)
itp('returns an empty string when given an empty file name', function()
eq('', path_tail_with_sep(''))
end)
itp('returns only the separator if there is a trailing separator', function()
eq('/', path_tail_with_sep('some/directory/'))
end)
itp('cuts a leading separator', function()
eq('file.txt', path_tail_with_sep('/file.txt'))
eq('', path_tail_with_sep('/'))
end)
itp('returns the whole file name if there is no separator', function()
eq('file.txt', path_tail_with_sep('file.txt'))
end)
end)
describe('invocation_path_tail', function()
-- Returns the path tail and length (out param) of the tail.
-- Does not convert the tail from C-pointer to lua string for use with
-- strcmp.
local function invocation_path_tail(invk)
local plen = ffi.new('size_t[?]', 1)
local ptail = cimp.invocation_path_tail((to_cstr(invk)), plen)
neq(NULL, ptail)
-- it does not change the output if len==NULL
local tail2 = cimp.invocation_path_tail((to_cstr(invk)), NULL)
neq(NULL, tail2)
eq((ffi.string(ptail)), (ffi.string(tail2)))
return ptail, plen[0]
end
-- This test mimics the intended use in C.
local function compare(base, pinvk, len)
return eq(0, (ffi.C.strncmp((to_cstr(base)), pinvk, len)))
end
itp('returns the executable name of an invocation given a relative invocation', function()
local invk, len = invocation_path_tail('directory/exe a b c')
compare('exe a b c', invk, len)
eq(3, len)
end)
itp('returns the executable name of an invocation given an absolute invocation', function()
if ffi.os == 'Windows' then
local invk, len = invocation_path_tail('C:\\Users\\anyone\\Program Files\\z a b')
compare('z a b', invk, len)
eq(1, len)
else
local invk, len = invocation_path_tail('/usr/bin/z a b')
compare('z a b', invk, len)
eq(1, len)
end
end)
itp('does not count arguments to the executable as part of its path', function()
local invk, len = invocation_path_tail('exe a/b\\c')
compare('exe a/b\\c', invk, len)
eq(3, len)
end)
itp('only accepts whitespace as a terminator for the executable name', function()
local invk, _ = invocation_path_tail('exe-a+b_c[]()|#!@$%^&*')
eq('exe-a+b_c[]()|#!@$%^&*', (ffi.string(invk)))
end)
itp('is equivalent to path_tail when args do not contain a path separator', function()
local ptail = cimp.path_tail(to_cstr('a/b/c x y z'))
neq(NULL, ptail)
local tail = ffi.string(ptail)
local invk, _ = invocation_path_tail('a/b/c x y z')
eq(tail, ffi.string(invk))
end)
itp('is not equivalent to path_tail when args contain a path separator', function()
local ptail = cimp.path_tail(to_cstr('a/b/c x y/z'))
neq(NULL, ptail)
local invk, _ = invocation_path_tail('a/b/c x y/z')
neq((ffi.string(ptail)), (ffi.string(invk)))
end)
end)
describe('path_next_component', function()
local function path_next_component(file)
local res = cimp.path_next_component((to_cstr(file)))
neq(NULL, res)
return ffi.string(res)
end
itp('returns', function()
eq('directory/file.txt', path_next_component('some/directory/file.txt'))
end)
itp('returns empty string if given file contains no separator', function()
eq('', path_next_component('file.txt'))
end)
end)
describe('path_shorten_fname', function()
itp('returns NULL if `full_path` is NULL', function()
local dir = to_cstr('some/directory/file.txt')
eq(NULL, (cimp.path_shorten_fname(NULL, dir)))
end)
itp('returns NULL if the path and dir does not match', function()
local dir = to_cstr('not/the/same')
local full = to_cstr('as/this.txt')
eq(NULL, (cimp.path_shorten_fname(full, dir)))
end)
itp('returns NULL if the path is not separated properly', function()
local dir = to_cstr('some/very/long/')
local full = to_cstr('some/very/long/directory/file.txt')
eq(NULL, (cimp.path_shorten_fname(full, dir)))
end)
itp('shortens the filename if `dir_name` is the start of `full_path`', function()
local full = to_cstr('some/very/long/directory/file.txt')
local dir = to_cstr('some/very/long')
eq('directory/file.txt', (ffi.string(cimp.path_shorten_fname(full, dir))))
end)
end)
end)
describe('path_try_shorten_fname', function()
local cwd = uv.cwd()
before_each(function()
mkdir('ut_directory')
end)
after_each(function()
uv.chdir(cwd)
uv.fs_rmdir('ut_directory')
end)
describe('path_try_shorten_fname', function()
itp('returns shortened path if possible', function()
uv.chdir('ut_directory')
local full = to_cstr(uv.cwd() .. '/subdir/file.txt')
eq('subdir/file.txt', (ffi.string(cimp.path_try_shorten_fname(full))))
end)
itp('returns `full_path` if a shorter version is not possible', function()
local old = uv.cwd()
uv.chdir('ut_directory')
local full = old .. '/subdir/file.txt'
eq(full, (ffi.string(cimp.path_try_shorten_fname(to_cstr(full)))))
end)
itp('returns NULL if `full_path` is NULL', function()
eq(NULL, (cimp.path_try_shorten_fname(NULL)))
end)
end)
end)
describe('path.c path_guess_exepath', function()
local cwd = uv.cwd()
for _, name in ipairs({ './nvim', '.nvim', 'foo/nvim' }) do
itp('"' .. name .. '" returns name catenated with CWD', function()
local bufsize = 255
local buf = cstr(bufsize, '')
cimp.path_guess_exepath(name, buf, bufsize)
eq(cwd .. '/' .. name, ffi.string(buf))
end)
end
itp('absolute path returns the name unmodified', function()
local name = '/foo/bar/baz'
local bufsize = 255
local buf = cstr(bufsize, '')
cimp.path_guess_exepath(name, buf, bufsize)
eq(name, ffi.string(buf))
end)
itp('returns the name unmodified if not found in $PATH', function()
local name = '23u0293_not_in_path'
local bufsize = 255
local buf = cstr(bufsize, '')
cimp.path_guess_exepath(name, buf, bufsize)
eq(name, ffi.string(buf))
end)
itp('does not crash if $PATH item exceeds MAXPATHL', function()
local orig_path_env = os.getenv('PATH')
local name = 'cat' -- Some executable in $PATH.
local bufsize = 255
local buf = cstr(bufsize, '')
local insane_path = orig_path_env .. ':' .. (('x/'):rep(4097))
cimp.os_setenv('PATH', insane_path, true)
cimp.path_guess_exepath(name, buf, bufsize)
eq('bin/' .. name, ffi.string(buf):sub(-#('bin/' .. name), -1))
-- Restore $PATH.
cimp.os_setenv('PATH', orig_path_env, true)
end)
itp('returns full path found in $PATH', function()
local name = 'cat' -- Some executable in $PATH.
local bufsize = 255
local buf = cstr(bufsize, '')
cimp.path_guess_exepath(name, buf, bufsize)
-- Usually "/bin/cat" on unix, "/path/to/nvim/cat" on Windows.
eq('bin/' .. name, ffi.string(buf):sub(-#('bin/' .. name), -1))
end)
end)
describe('path.c', function()
setup(function()
mkdir('unit-test-directory')
io.open('unit-test-directory/test.file', 'w'):close()
-- Since the tests are executed, they are called by an executable. We use
-- that executable for several asserts.
local absolute_executable = arg[0]
-- Split absolute_executable into a directory and the actual file name for
-- later usage.
local directory, executable_name = string.match(absolute_executable, '^(.*)/(.*)$') -- luacheck: ignore
end)
teardown(function()
os.remove('unit-test-directory/test.file')
uv.fs_rmdir('unit-test-directory')
end)
describe('vim_FullName', function()
local function vim_FullName(filename, buflen, do_expand)
local buf = cstr(buflen, '')
local result = cimp.vim_FullName(to_cstr(filename), buf, buflen, do_expand)
return buf, result
end
local function get_buf_len(s, t)
return math.max(string.len(s), string.len(t)) + 1
end
itp('fails if given filename is NULL', function()
local do_expand = 1
local buflen = 10
local buf = cstr(buflen, '')
local result = cimp.vim_FullName(NULL, buf, buflen, do_expand)
eq(FAIL, result)
end)
itp('fails safely if given length is wrong #5737', function()
local filename = 'foo/bar/bazzzzzzz/buz/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/a'
local too_short_len = 8
local buf = cstr(too_short_len, '')
local do_expand = 1
local result = cimp.vim_FullName(filename, buf, too_short_len, do_expand)
local expected = string.sub(filename, 1, (too_short_len - 1))
eq(expected, ffi.string(buf))
eq(FAIL, result)
end)
itp('uses the filename if the filename is a URL', function()
local filename = 'http://www.neovim.org'
local buflen = string.len(filename) + 1
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(filename, ffi.string(buf))
eq(OK, result)
end)
itp('fails and uses filename if given filename contains non-existing directory', function()
local filename = 'non_existing_dir/test.file'
local buflen = string.len(filename) + 1
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(filename, ffi.string(buf))
eq(FAIL, result)
end)
itp('concatenates filename if it does not contain a slash', function()
local expected = uv.cwd() .. '/test.file'
local filename = 'test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(expected, ffi.string(buf))
eq(OK, result)
end)
itp('concatenates directory name if it does not contain a slash', function()
local expected = uv.cwd() .. '/..'
local filename = '..'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(expected, ffi.string(buf))
eq(OK, result)
end)
itp(
'enters given directory (instead of just concatenating the strings) if possible and if path contains a slash',
function()
local old_dir = uv.cwd()
uv.chdir('..')
local expected = uv.cwd() .. '/test.file'
uv.chdir(old_dir)
local filename = '../test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(expected, ffi.string(buf))
eq(OK, result)
end
)
itp('just copies the path if it is already absolute and force=0', function()
local absolute_path = '/absolute/path'
local buflen = string.len(absolute_path) + 1
local do_expand = 0
local buf, result = vim_FullName(absolute_path, buflen, do_expand)
eq(absolute_path, ffi.string(buf))
eq(OK, result)
end)
itp('fails and uses filename when the path is relative to HOME', function()
eq(false, cimp.os_isdir('~'), 'sanity check: no literal "~" directory')
local absolute_path = '~/home.file'
local buflen = string.len(absolute_path) + 1
local do_expand = 1
local buf, result = vim_FullName(absolute_path, buflen, do_expand)
eq(absolute_path, ffi.string(buf))
eq(FAIL, result)
end)
itp('works with some "normal" relative path with directories', function()
local expected = uv.cwd() .. '/unit-test-directory/test.file'
local filename = 'unit-test-directory/test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(expected, ffi.string(buf))
eq(OK, result)
end)
itp('does not modify the given filename', function()
local expected = uv.cwd() .. '/unit-test-directory/test.file'
local filename = to_cstr('unit-test-directory/test.file')
local buflen = string.len(expected) + 1
local buf = cstr(buflen, '')
local do_expand = 1
-- Don't use the wrapper but pass a cstring directly to the c function.
eq('unit-test-directory/test.file', ffi.string(filename))
local result = cimp.vim_FullName(filename, buf, buflen, do_expand)
eq(expected, ffi.string(buf))
eq(OK, result)
end)
itp('works with directories that have one path component', function()
local filename = '/tmp'
local expected = filename
local buflen = get_buf_len(expected, filename)
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq('/tmp', ffi.string(buf))
eq(OK, result)
end)
itp('does not remove trailing slash from non-existing relative directory #20847', function()
local expected = uv.cwd() .. '/non_existing_dir/'
local filename = 'non_existing_dir/'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(expected, ffi.string(buf))
eq(OK, result)
end)
itp('expands "./" to the current directory #7117', function()
local expected = uv.cwd() .. '/unit-test-directory/test.file'
local filename = './unit-test-directory/test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(OK, result)
eq(expected, ffi.string(buf))
end)
itp('collapses "foo/../foo" to "foo" #7117', function()
local expected = uv.cwd() .. '/unit-test-directory/test.file'
local filename = 'unit-test-directory/../unit-test-directory/test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
local buf, result = vim_FullName(filename, buflen, do_expand)
eq(OK, result)
eq(expected, ffi.string(buf))
end)
end)
describe('path_fix_case', function()
local function fix_case(file)
local c_file = to_cstr(file)
cimp.path_fix_case(c_file)
return ffi.string(c_file)
end
before_each(function()
mkdir('CamelCase')
end)
after_each(function()
uv.fs_rmdir('CamelCase')
end)
if ffi.os == 'Windows' or ffi.os == 'OSX' then
itp('Corrects the case of file names in Mac and Windows', function()
eq('CamelCase', fix_case('camelcase'))
eq('CamelCase', fix_case('cAMELcASE'))
end)
else
itp('does nothing on Linux', function()
eq('camelcase', fix_case('camelcase'))
eq('cAMELcASE', fix_case('cAMELcASE'))
end)
end
end)
describe('append_path', function()
itp('joins given paths with a slash', function()
local path1 = cstr(100, 'path1')
local to_append = to_cstr('path2')
eq(OK, (cimp.append_path(path1, to_append, 100)))
eq('path1/path2', (ffi.string(path1)))
end)
itp('joins given paths without adding an unnecessary slash', function()
local path1 = cstr(100, 'path1/')
local to_append = to_cstr('path2')
eq(OK, cimp.append_path(path1, to_append, 100))
eq('path1/path2', (ffi.string(path1)))
end)
itp('fails and uses filename if there is not enough space left for to_append', function()
local path1 = cstr(11, 'path1/')
local to_append = to_cstr('path2')
eq(FAIL, (cimp.append_path(path1, to_append, 11)))
end)
itp('does not append a slash if to_append is empty', function()
local path1 = cstr(6, 'path1')
local to_append = to_cstr('')
eq(OK, (cimp.append_path(path1, to_append, 6)))
eq('path1', (ffi.string(path1)))
end)
itp('does not append unnecessary dots', function()
local path1 = cstr(6, 'path1')
local to_append = to_cstr('.')
eq(OK, (cimp.append_path(path1, to_append, 6)))
eq('path1', (ffi.string(path1)))
end)
itp('copies to_append to path, if path is empty', function()
local path1 = cstr(7, '')
local to_append = to_cstr('/path2')
eq(OK, (cimp.append_path(path1, to_append, 7)))
eq('/path2', (ffi.string(path1)))
end)
end)
describe('path_is_absolute', function()
local function path_is_absolute(filename)
filename = to_cstr(filename)
return cimp.path_is_absolute(filename)
end
itp('returns true if filename starts with a slash', function()
eq(true, path_is_absolute('/some/directory/'))
end)
itp('returns true if filename starts with a tilde', function()
eq(true, path_is_absolute('~/in/my/home~/directory'))
end)
itp('returns false if filename starts not with slash nor tilde', function()
eq(false, path_is_absolute('not/in/my/home~/directory'))
end)
end)
describe('path_with_extension', function()
local function path_with_extension(filename, extension)
local c_filename = to_cstr(filename)
local c_extension = to_cstr(extension)
return cimp.path_with_extension(c_filename, c_extension)
end
itp('returns true if filename includes a provided extension', function()
eq(true, path_with_extension('/some/path/file.lua', 'lua'))
end)
itp('returns false if filename does not include a provided extension', function()
eq(false, path_with_extension('/some/path/file.vim', 'lua'))
eq(false, path_with_extension('/some/path/file', 'lua'))
end)
itp("respects 'fileignorecase' option", function()
options.p_fic = false
eq(false, path_with_extension('/some/path/file.VIM', 'vim'))
eq(false, path_with_extension('/some/path/file.LUA', 'lua'))
options.p_fic = true
eq(true, path_with_extension('/some/path/file.VIM', 'vim'))
eq(true, path_with_extension('/some/path/file.LUA', 'lua'))
end)
end)
describe('path_with_url', function()
itp('scheme is alpha and inner hyphen only', function()
local function path_with_url(fname)
return cimp.path_with_url(to_cstr(fname))
end
eq(1, path_with_url([[test://xyz/foo/b0]]))
eq(2, path_with_url([[test:\\xyz\foo\b0]]))
eq(0, path_with_url([[test+abc://xyz/foo/b1]]))
eq(0, path_with_url([[test_abc://xyz/foo/b2]]))
eq(1, path_with_url([[test-abc://xyz/foo/b3]]))
eq(2, path_with_url([[test-abc:\\xyz\foo\b3]]))
eq(0, path_with_url([[-test://xyz/foo/b4]]))
eq(0, path_with_url([[test-://xyz/foo/b5]]))
eq(1, path_with_url([[test-C:/xyz/foo/b5]]))
eq(1, path_with_url([[test-custom:/xyz/foo/b5]]))
eq(0, path_with_url([[c:/xyz/foo/b5]]))
eq(0, path_with_url([[C:/xyz/foo/b5]]))
end)
end)
end)
|