blob: 0c41692a06ebdb0ec7dc96ee6e10bc93bba65e10 [file] [log] [blame]
Bram Moolenaarcada7892018-01-31 19:30:24 +01001" Test for shortpathname ':8' extension.
2" Only for use on Win32 systems!
3
Bram Moolenaar3f396972019-10-30 04:10:06 +01004set encoding=utf-8
5scriptencoding utf-8
6
Bram Moolenaar39de6412019-08-08 21:52:39 +02007source check.vim
8CheckMSWindows
Bram Moolenaarcada7892018-01-31 19:30:24 +01009
10func TestIt(file, bits, expected)
11 let res = fnamemodify(a:file, a:bits)
12 if a:expected != ''
13 call assert_equal(substitute(a:expected, '/', '\\', 'g'),
14 \ substitute(res, '/', '\\', 'g'),
15 \ "'" . a:file . "'->(" . a:bits . ")->'" . res . "'")
16 endif
17endfunc
18
Christian Brabandtd03882b2024-06-10 21:06:55 +020019func s:SetupDir(dir)
Bram Moolenaar0f823c32022-07-30 15:35:12 +010020 let trycount = 5
21 while 1
Christian Brabandtd03882b2024-06-10 21:06:55 +020022 if !filereadable(a:dir) && !isdirectory(a:dir)
Bram Moolenaar0f823c32022-07-30 15:35:12 +010023 break
24 endif
25 if trycount == 1
Christian Brabandtd03882b2024-06-10 21:06:55 +020026 call assert_report("Fatal: '" . a:dir . "' exists, cannot run this test")
Bram Moolenaar0f823c32022-07-30 15:35:12 +010027 return
28 endif
29 " When tests run in parallel the directory may exist, wait a bit until it
30 " is gone.
31 sleep 5
32 let trycount -= 1
33 endwhile
Christian Brabandtd03882b2024-06-10 21:06:55 +020034endfunc
35
36
37func Test_ColonEight()
38 let save_dir = getcwd()
39
40 " This could change for CygWin to //cygdrive/c .
41 let dir1 = 'c:/x.x.y'
42 call s:SetupDir(dir1)
Bram Moolenaarcada7892018-01-31 19:30:24 +010043
44 let file1 = dir1 . '/zz.y.txt'
45 let nofile1 = dir1 . '/z.y.txt'
46 let dir2 = dir1 . '/VimIsTheGreatestSinceSlicedBread'
47 let file2 = dir2 . '/z.txt'
48 let nofile2 = dir2 . '/zz.txt'
49
Bram Moolenaar56564962022-10-10 22:39:42 +010050 call mkdir(dir1, 'D')
Bram Moolenaarcada7892018-01-31 19:30:24 +010051 let resdir1 = substitute(fnamemodify(dir1, ':p:8'), '/$', '', '')
52 call assert_match('\V\^c:/XX\x\x\x\x~1.Y\$', resdir1)
53
54 let resfile1 = resdir1 . '/ZZY~1.TXT'
55 let resnofile1 = resdir1 . '/z.y.txt'
56 let resdir2 = resdir1 . '/VIMIST~1'
57 let resfile2 = resdir2 . '/z.txt'
58 let resnofile2 = resdir2 . '/zz.txt'
59
Bram Moolenaar56564962022-10-10 22:39:42 +010060 call mkdir(dir2, 'D')
61 call writefile([], file1, 'D')
62 call writefile([], file2, 'D')
Bram Moolenaarcada7892018-01-31 19:30:24 +010063
64 call TestIt(file1, ':p:8', resfile1)
65 call TestIt(nofile1, ':p:8', resnofile1)
66 call TestIt(file2, ':p:8', resfile2)
67 call TestIt(nofile2, ':p:8', resnofile2)
68 call TestIt(nofile2, ':p:8:h', fnamemodify(resnofile2, ':h'))
Bram Moolenaar3503d7c2019-11-09 20:10:17 +010069 call chdir(dir1)
Bram Moolenaarcada7892018-01-31 19:30:24 +010070 call TestIt(file1, ':.:8', strpart(resfile1, strlen(resdir1)+1))
71 call TestIt(nofile1, ':.:8', strpart(resnofile1, strlen(resdir1)+1))
72 call TestIt(file2, ':.:8', strpart(resfile2, strlen(resdir1)+1))
73 call TestIt(nofile2, ':.:8', strpart(resnofile2, strlen(resdir1)+1))
74 let $HOME=dir1
75 call TestIt(file1, ':~:8', '~' . strpart(resfile1, strlen(resdir1)))
76 call TestIt(nofile1, ':~:8', '~' . strpart(resnofile1, strlen(resdir1)))
77 call TestIt(file2, ':~:8', '~' . strpart(resfile2, strlen(resdir1)))
78 call TestIt(nofile2, ':~:8', '~' . strpart(resnofile2, strlen(resdir1)))
79
80 cd c:/
Bram Moolenaarcada7892018-01-31 19:30:24 +010081
Bram Moolenaar3503d7c2019-11-09 20:10:17 +010082 call chdir(save_dir)
Bram Moolenaarcada7892018-01-31 19:30:24 +010083endfunc
Bram Moolenaar3f396972019-10-30 04:10:06 +010084
85func Test_ColonEight_MultiByte()
Christian Brabandtd03882b2024-06-10 21:06:55 +020086 let dir = 'c:/Xtest_C8MB'
87 call s:SetupDir(dir)
Bram Moolenaar3f396972019-10-30 04:10:06 +010088
89 let file = dir . '/日本語のファイル.txt'
90
Bram Moolenaar56564962022-10-10 22:39:42 +010091 call mkdir(dir, 'D')
92 call writefile([], file, 'D')
Bram Moolenaar3f396972019-10-30 04:10:06 +010093
94 let sfile = fnamemodify(file, ':8')
95
96 call assert_notequal(file, sfile)
97 call assert_match('\~', sfile)
Bram Moolenaar3f396972019-10-30 04:10:06 +010098endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020099
Christian Brabandt81da16b2022-03-10 12:24:02 +0000100func Test_ColonEight_notexists()
101 let non_exists='C:\windows\newfile.txt'
102 call assert_equal(non_exists, fnamemodify(non_exists, ':p:8'))
103endfunc
104
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200105" vim: shiftwidth=2 sts=2 expandtab