view src/testdir/test_stat.vim @ 10730:44e9340dc604 v8.0.0255

patch 8.0.0255: setpos() does not use the buffer argument for all marks commit https://github.com/vim/vim/commit/f13e00b2cf381e13fd327b5387a5bd6f004ac2a3 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 28 18:23:54 2017 +0100 patch 8.0.0255: setpos() does not use the buffer argument for all marks Problem: When calling setpos() with a buffer argument it often is ignored. (Matthew Malcomson) Solution: Make the buffer argument work for all marks local to a buffer. (neovim #5713) Add more tests.
author Christian Brabandt <cb@256bit.org>
date Sat, 28 Jan 2017 18:30:04 +0100
parents f094d4085014
children 750779134e67
line wrap: on
line source

" Tests for stat functions and checktime

func Test_existent_file()
  let fname='Xtest.tmp'

  let ts=localtime()
  sleep 1
  let fl=['Hello World!']
  call writefile(fl, fname)
  let tf=getftime(fname)
  sleep 1
  let te=localtime()

  call assert_true(ts <= tf && tf <= te)
  call assert_equal(strlen(fl[0] . "\n"), getfsize(fname))
  call assert_equal('file', getftype(fname))
  call assert_equal('rw-', getfperm(fname)[0:2])
endfunc

func Test_existent_directory()
  let dname='.'

  call assert_equal(0, getfsize(dname))
  call assert_equal('dir', getftype(dname))
  call assert_equal('rwx', getfperm(dname)[0:2])
endfunc

func Test_checktime()
  let fname='Xtest.tmp'

  let fl=['Hello World!']
  call writefile(fl, fname)
  set autoread
  exec 'e' fname
  sleep 2
  let fl=readfile(fname)
  let fl[0] .= ' - checktime'
  call writefile(fl, fname)
  checktime
  call assert_equal(fl[0], getline(1))
endfunc

func Test_nonexistent_file()
  let fname='Xtest.tmp'

  call delete(fname)
  call assert_equal(-1, getftime(fname))
  call assert_equal(-1, getfsize(fname))
  call assert_equal('', getftype(fname))
  call assert_equal('', getfperm(fname))
endfunc

func Test_win32_symlink_dir()
  " On Windows, non-admin users cannot create symlinks.
  " So we use an existing symlink for this test.
  if has('win32')
    " Check if 'C:\Users\All Users' is a symlink to a directory.
    let res=system('dir C:\Users /a')
    if match(res, '\C<SYMLINKD> *All Users') >= 0
      " Get the filetype of the symlink.
      call assert_equal('dir', getftype('C:\Users\All Users'))
    endif
  endif
endfunc