Bram Moolenaar | cada789 | 2018-01-31 19:30:24 +0100 | [diff] [blame] | 1 | " Test for shortpathname ':8' extension. |
| 2 | " Only for use on Win32 systems! |
| 3 | |
Bram Moolenaar | 3f39697 | 2019-10-30 04:10:06 +0100 | [diff] [blame] | 4 | set encoding=utf-8 |
| 5 | scriptencoding utf-8 |
| 6 | |
Bram Moolenaar | 39de641 | 2019-08-08 21:52:39 +0200 | [diff] [blame] | 7 | source check.vim |
| 8 | CheckMSWindows |
Bram Moolenaar | cada789 | 2018-01-31 19:30:24 +0100 | [diff] [blame] | 9 | |
| 10 | func 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 |
| 17 | endfunc |
| 18 | |
| 19 | func Test_ColonEight() |
| 20 | let save_dir = getcwd() |
| 21 | |
Bram Moolenaar | 0f823c3 | 2022-07-30 15:35:12 +0100 | [diff] [blame] | 22 | " This could change for CygWin to //cygdrive/c . |
Bram Moolenaar | cada789 | 2018-01-31 19:30:24 +0100 | [diff] [blame] | 23 | let dir1 = 'c:/x.x.y' |
Bram Moolenaar | 0f823c3 | 2022-07-30 15:35:12 +0100 | [diff] [blame] | 24 | let trycount = 5 |
| 25 | while 1 |
| 26 | if !filereadable(dir1) && !isdirectory(dir1) |
| 27 | break |
| 28 | endif |
| 29 | if trycount == 1 |
| 30 | call assert_report("Fatal: '" . dir1 . "' exists, cannot run this test") |
| 31 | return |
| 32 | endif |
| 33 | " When tests run in parallel the directory may exist, wait a bit until it |
| 34 | " is gone. |
| 35 | sleep 5 |
| 36 | let trycount -= 1 |
| 37 | endwhile |
Bram Moolenaar | cada789 | 2018-01-31 19:30:24 +0100 | [diff] [blame] | 38 | |
| 39 | let file1 = dir1 . '/zz.y.txt' |
| 40 | let nofile1 = dir1 . '/z.y.txt' |
| 41 | let dir2 = dir1 . '/VimIsTheGreatestSinceSlicedBread' |
| 42 | let file2 = dir2 . '/z.txt' |
| 43 | let nofile2 = dir2 . '/zz.txt' |
| 44 | |
| 45 | call mkdir(dir1) |
| 46 | let resdir1 = substitute(fnamemodify(dir1, ':p:8'), '/$', '', '') |
| 47 | call assert_match('\V\^c:/XX\x\x\x\x~1.Y\$', resdir1) |
| 48 | |
| 49 | let resfile1 = resdir1 . '/ZZY~1.TXT' |
| 50 | let resnofile1 = resdir1 . '/z.y.txt' |
| 51 | let resdir2 = resdir1 . '/VIMIST~1' |
| 52 | let resfile2 = resdir2 . '/z.txt' |
| 53 | let resnofile2 = resdir2 . '/zz.txt' |
| 54 | |
| 55 | call mkdir(dir2) |
| 56 | call writefile([], file1) |
| 57 | call writefile([], file2) |
| 58 | |
| 59 | call TestIt(file1, ':p:8', resfile1) |
| 60 | call TestIt(nofile1, ':p:8', resnofile1) |
| 61 | call TestIt(file2, ':p:8', resfile2) |
| 62 | call TestIt(nofile2, ':p:8', resnofile2) |
| 63 | call TestIt(nofile2, ':p:8:h', fnamemodify(resnofile2, ':h')) |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 64 | call chdir(dir1) |
Bram Moolenaar | cada789 | 2018-01-31 19:30:24 +0100 | [diff] [blame] | 65 | call TestIt(file1, ':.:8', strpart(resfile1, strlen(resdir1)+1)) |
| 66 | call TestIt(nofile1, ':.:8', strpart(resnofile1, strlen(resdir1)+1)) |
| 67 | call TestIt(file2, ':.:8', strpart(resfile2, strlen(resdir1)+1)) |
| 68 | call TestIt(nofile2, ':.:8', strpart(resnofile2, strlen(resdir1)+1)) |
| 69 | let $HOME=dir1 |
| 70 | call TestIt(file1, ':~:8', '~' . strpart(resfile1, strlen(resdir1))) |
| 71 | call TestIt(nofile1, ':~:8', '~' . strpart(resnofile1, strlen(resdir1))) |
| 72 | call TestIt(file2, ':~:8', '~' . strpart(resfile2, strlen(resdir1))) |
| 73 | call TestIt(nofile2, ':~:8', '~' . strpart(resnofile2, strlen(resdir1))) |
| 74 | |
| 75 | cd c:/ |
| 76 | call delete(file2) |
| 77 | call delete(file1) |
| 78 | call delete(dir2, 'd') |
| 79 | call delete(dir1, 'd') |
| 80 | |
Bram Moolenaar | 3503d7c | 2019-11-09 20:10:17 +0100 | [diff] [blame] | 81 | call chdir(save_dir) |
Bram Moolenaar | cada789 | 2018-01-31 19:30:24 +0100 | [diff] [blame] | 82 | endfunc |
Bram Moolenaar | 3f39697 | 2019-10-30 04:10:06 +0100 | [diff] [blame] | 83 | |
| 84 | func Test_ColonEight_MultiByte() |
| 85 | let dir = 'Xtest' |
| 86 | |
| 87 | let file = dir . '/日本語のファイル.txt' |
| 88 | |
| 89 | call mkdir(dir) |
| 90 | call writefile([], file) |
| 91 | |
| 92 | let sfile = fnamemodify(file, ':8') |
| 93 | |
| 94 | call assert_notequal(file, sfile) |
| 95 | call assert_match('\~', sfile) |
| 96 | |
| 97 | call delete(file) |
| 98 | call delete(dir, 'd') |
| 99 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 100 | |
Christian Brabandt | 81da16b | 2022-03-10 12:24:02 +0000 | [diff] [blame] | 101 | func Test_ColonEight_notexists() |
| 102 | let non_exists='C:\windows\newfile.txt' |
| 103 | call assert_equal(non_exists, fnamemodify(non_exists, ':p:8')) |
| 104 | endfunc |
| 105 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 106 | " vim: shiftwidth=2 sts=2 expandtab |