Bram Moolenaar | 2b61852 | 2019-01-12 13:26:03 +0100 | [diff] [blame] | 1 | " Tests for the :source command. |
| 2 | |
| 3 | func Test_source_autocmd() |
| 4 | call writefile([ |
| 5 | \ 'let did_source = 1', |
| 6 | \ ], 'Xsourced') |
| 7 | au SourcePre *source* let did_source_pre = 1 |
| 8 | au SourcePost *source* let did_source_post = 1 |
| 9 | |
| 10 | source Xsourced |
| 11 | |
| 12 | call assert_equal(g:did_source, 1) |
| 13 | call assert_equal(g:did_source_pre, 1) |
| 14 | call assert_equal(g:did_source_post, 1) |
| 15 | |
| 16 | call delete('Xsourced') |
| 17 | au! SourcePre |
| 18 | au! SourcePost |
| 19 | unlet g:did_source |
| 20 | unlet g:did_source_pre |
| 21 | unlet g:did_source_post |
| 22 | endfunc |
| 23 | |
| 24 | func Test_source_cmd() |
| 25 | au SourceCmd *source* let did_source = expand('<afile>') |
| 26 | au SourcePre *source* let did_source_pre = 2 |
| 27 | au SourcePost *source* let did_source_post = 2 |
| 28 | |
| 29 | source Xsourced |
| 30 | |
| 31 | call assert_equal(g:did_source, 'Xsourced') |
| 32 | call assert_false(exists('g:did_source_pre')) |
| 33 | call assert_equal(g:did_source_post, 2) |
| 34 | |
| 35 | au! SourceCmd |
| 36 | au! SourcePre |
| 37 | au! SourcePost |
| 38 | endfunc |
Bram Moolenaar | 5357552 | 2019-05-22 22:38:25 +0200 | [diff] [blame] | 39 | |
| 40 | func Test_source_sandbox() |
| 41 | new |
| 42 | call writefile(["Ohello\<Esc>"], 'Xsourcehello') |
| 43 | source! Xsourcehello | echo |
| 44 | call assert_equal('hello', getline(1)) |
| 45 | call assert_fails('sandbox source! Xsourcehello', 'E48:') |
| 46 | bwipe! |
Bram Moolenaar | ddd3308 | 2019-06-03 23:07:25 +0200 | [diff] [blame] | 47 | call delete('Xsourcehello') |
Bram Moolenaar | 5357552 | 2019-05-22 22:38:25 +0200 | [diff] [blame] | 48 | endfunc |