test_glob2regpat.vim 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. " Test glob2regpat()
  2. source vim9.vim
  3. func Test_glob2regpat_invalid()
  4. if has('float')
  5. call assert_equal('^1\.33$', glob2regpat(1.33))
  6. call CheckDefExecAndScriptFailure(['echo glob2regpat(1.33)'], 'E806:')
  7. endif
  8. call assert_fails('call glob2regpat("}")', 'E219:')
  9. call assert_fails('call glob2regpat("{")', 'E220:')
  10. endfunc
  11. func Test_glob2regpat_valid()
  12. call assert_equal('^foo\.', glob2regpat('foo.*'))
  13. call assert_equal('^foo.$', 'foo?'->glob2regpat())
  14. call assert_equal('\.vim$', glob2regpat('*.vim'))
  15. call assert_equal('^[abc]$', glob2regpat('[abc]'))
  16. call assert_equal('^foo bar$', glob2regpat('foo\ bar'))
  17. call assert_equal('^foo,bar$', glob2regpat('foo,bar'))
  18. call assert_equal('^\(foo\|bar\)$', glob2regpat('{foo,bar}'))
  19. call assert_equal('.*', glob2regpat('**'))
  20. if exists('+shellslash')
  21. call assert_equal('^foo[\/].$', glob2regpat('foo\?'))
  22. call assert_equal('^\(foo[\/]\|bar\|foobar\)$', glob2regpat('{foo\,bar,foobar}'))
  23. call assert_equal('^[\/]\(foo\|bar[\/]\)$', glob2regpat('\{foo,bar\}'))
  24. call assert_equal('^[\/][\/]\(foo\|bar[\/][\/]\)$', glob2regpat('\\{foo,bar\\}'))
  25. else
  26. call assert_equal('^foo?$', glob2regpat('foo\?'))
  27. call assert_equal('^\(foo,bar\|foobar\)$', glob2regpat('{foo\,bar,foobar}'))
  28. call assert_equal('^{foo,bar}$', glob2regpat('\{foo,bar\}'))
  29. call assert_equal('^\\\(foo\|bar\\\)$', glob2regpat('\\{foo,bar\\}'))
  30. endif
  31. endfunc