1" Test glob2regpat()
2
3source vim9.vim
4
5func Test_glob2regpat_invalid()
6  if has('float')
7    call assert_equal('^1\.33$', glob2regpat(1.33))
8    call CheckDefAndScriptFailure2(['echo glob2regpat(1.2)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1')
9  endif
10  call assert_fails('call glob2regpat("}")', 'E219:')
11  call assert_fails('call glob2regpat("{")', 'E220:')
12endfunc
13
14func Test_glob2regpat_valid()
15  call assert_equal('^foo\.', glob2regpat('foo.*'))
16  call assert_equal('^foo.$', 'foo?'->glob2regpat())
17  call assert_equal('\.vim$', glob2regpat('*.vim'))
18  call assert_equal('^[abc]$', glob2regpat('[abc]'))
19  call assert_equal('^foo bar$', glob2regpat('foo\ bar'))
20  call assert_equal('^foo,bar$', glob2regpat('foo,bar'))
21  call assert_equal('^\(foo\|bar\)$', glob2regpat('{foo,bar}'))
22  call assert_equal('.*', glob2regpat('**'))
23
24  if exists('+shellslash')
25    call assert_equal('^foo[\/].$', glob2regpat('foo\?'))
26    call assert_equal('^\(foo[\/]\|bar\|foobar\)$', glob2regpat('{foo\,bar,foobar}'))
27    call assert_equal('^[\/]\(foo\|bar[\/]\)$', glob2regpat('\{foo,bar\}'))
28    call assert_equal('^[\/][\/]\(foo\|bar[\/][\/]\)$', glob2regpat('\\{foo,bar\\}'))
29  else
30    call assert_equal('^foo?$', glob2regpat('foo\?'))
31    call assert_equal('^\(foo,bar\|foobar\)$', glob2regpat('{foo\,bar,foobar}'))
32    call assert_equal('^{foo,bar}$', glob2regpat('\{foo,bar\}'))
33    call assert_equal('^\\\(foo\|bar\\\)$', glob2regpat('\\{foo,bar\\}'))
34  endif
35endfunc
36
37" vim: shiftwidth=2 sts=2 expandtab
38