Mercurial > vim
comparison src/testdir/test_autocmd.vim @ 16397:7a942d92980d v8.1.1203
patch 8.1.1203: some autocmd tests are old style
commit https://github.com/vim/vim/commit/69ea587289b03e23a9fb96adffd6e8173cbc5896
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 25 20:29:00 2019 +0200
patch 8.1.1203: some autocmd tests are old style
Problem: Some autocmd tests are old style.
Solution: Turn the tests into new style. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4295)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 25 Apr 2019 20:30:05 +0200 |
parents | 81e6940504e8 |
children | 3b2db762a509 |
comparison
equal
deleted
inserted
replaced
16396:8f1c91d920f3 | 16397:7a942d92980d |
---|---|
1484 | 1484 |
1485 call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') | 1485 call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') |
1486 endfunc | 1486 endfunc |
1487 | 1487 |
1488 " FileChangedShell tested in test_filechanged.vim | 1488 " FileChangedShell tested in test_filechanged.vim |
1489 | |
1490 " Tests for the following autocommands: | |
1491 " - FileWritePre writing a compressed file | |
1492 " - FileReadPost reading a compressed file | |
1493 " - BufNewFile reading a file template | |
1494 " - BufReadPre decompressing the file to be read | |
1495 " - FilterReadPre substituting characters in the temp file | |
1496 " - FilterReadPost substituting characters after filtering | |
1497 " - FileReadPre set options for decompression | |
1498 " - FileReadPost decompress the file | |
1499 func Test_ReadWrite_Autocmds() | |
1500 " Run this test only on Unix-like systems and if gzip is available | |
1501 if !has('unix') || !executable("gzip") | |
1502 return | |
1503 endif | |
1504 | |
1505 " Make $GZIP empty, "-v" would cause trouble. | |
1506 let $GZIP = "" | |
1507 | |
1508 " Use a FileChangedShell autocommand to avoid a prompt for 'Xtestfile.gz' | |
1509 " being modified outside of Vim (noticed on Solaris). | |
1510 au FileChangedShell * echo 'caught FileChangedShell' | |
1511 | |
1512 " Test for the FileReadPost, FileWritePre and FileWritePost autocmds | |
1513 augroup Test1 | |
1514 au! | |
1515 au FileWritePre *.gz '[,']!gzip | |
1516 au FileWritePost *.gz undo | |
1517 au FileReadPost *.gz '[,']!gzip -d | |
1518 augroup END | |
1519 | |
1520 new | |
1521 set bin | |
1522 call append(0, [ | |
1523 \ 'line 2 Abcdefghijklmnopqrstuvwxyz', | |
1524 \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1525 \ 'line 4 Abcdefghijklmnopqrstuvwxyz', | |
1526 \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1527 \ 'line 6 Abcdefghijklmnopqrstuvwxyz', | |
1528 \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1529 \ 'line 8 Abcdefghijklmnopqrstuvwxyz', | |
1530 \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1531 \ 'line 10 Abcdefghijklmnopqrstuvwxyz' | |
1532 \ ]) | |
1533 1,9write! Xtestfile.gz | |
1534 enew! | close | |
1535 | |
1536 new | |
1537 " Read and decompress the testfile | |
1538 0read Xtestfile.gz | |
1539 call assert_equal([ | |
1540 \ 'line 2 Abcdefghijklmnopqrstuvwxyz', | |
1541 \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1542 \ 'line 4 Abcdefghijklmnopqrstuvwxyz', | |
1543 \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1544 \ 'line 6 Abcdefghijklmnopqrstuvwxyz', | |
1545 \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1546 \ 'line 8 Abcdefghijklmnopqrstuvwxyz', | |
1547 \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1548 \ 'line 10 Abcdefghijklmnopqrstuvwxyz' | |
1549 \ ], getline(1, 9)) | |
1550 enew! | close | |
1551 | |
1552 augroup Test1 | |
1553 au! | |
1554 augroup END | |
1555 | |
1556 " Test for the FileAppendPre and FileAppendPost autocmds | |
1557 augroup Test2 | |
1558 au! | |
1559 au BufNewFile *.c read Xtest.c | |
1560 au FileAppendPre *.out '[,']s/new/NEW/ | |
1561 au FileAppendPost *.out !cat Xtest.c >> test.out | |
1562 augroup END | |
1563 | |
1564 call writefile(['/*', ' * Here is a new .c file', ' */'], 'Xtest.c') | |
1565 new foo.c " should load Xtest.c | |
1566 call assert_equal(['/*', ' * Here is a new .c file', ' */'], getline(2, 4)) | |
1567 w! >> test.out " append it to the output file | |
1568 | |
1569 let contents = readfile('test.out') | |
1570 call assert_equal(' * Here is a NEW .c file', contents[2]) | |
1571 call assert_equal(' * Here is a new .c file', contents[5]) | |
1572 | |
1573 call delete('test.out') | |
1574 enew! | close | |
1575 augroup Test2 | |
1576 au! | |
1577 augroup END | |
1578 | |
1579 " Test for the BufReadPre and BufReadPost autocmds | |
1580 augroup Test3 | |
1581 au! | |
1582 " setup autocommands to decompress before reading and re-compress | |
1583 " afterwards | |
1584 au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand("<afile>")) | |
1585 au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) | |
1586 au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r")) | |
1587 au BufReadPost *.gz exe '!gzip ' . shellescape(expand("<afile>:r")) | |
1588 augroup END | |
1589 | |
1590 e! Xtestfile.gz " Edit compressed file | |
1591 call assert_equal([ | |
1592 \ 'line 2 Abcdefghijklmnopqrstuvwxyz', | |
1593 \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1594 \ 'line 4 Abcdefghijklmnopqrstuvwxyz', | |
1595 \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1596 \ 'line 6 Abcdefghijklmnopqrstuvwxyz', | |
1597 \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1598 \ 'line 8 Abcdefghijklmnopqrstuvwxyz', | |
1599 \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1600 \ 'line 10 Abcdefghijklmnopqrstuvwxyz' | |
1601 \ ], getline(1, 9)) | |
1602 | |
1603 w! >> test.out " Append it to the output file | |
1604 | |
1605 augroup Test3 | |
1606 au! | |
1607 augroup END | |
1608 | |
1609 " Test for the FilterReadPre and FilterReadPost autocmds. | |
1610 set shelltemp " need temp files here | |
1611 augroup Test4 | |
1612 au! | |
1613 au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t") | |
1614 au FilterReadPre *.out exe 'silent !sed s/e/E/ ' . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>")) | |
1615 au FilterReadPre *.out exe 'silent !rm ' . shellescape(expand("<afile>")) . '.t' | |
1616 au FilterReadPost *.out '[,']s/x/X/g | |
1617 augroup END | |
1618 | |
1619 e! test.out " Edit the output file | |
1620 1,$!cat | |
1621 call assert_equal([ | |
1622 \ 'linE 2 AbcdefghijklmnopqrstuvwXyz', | |
1623 \ 'linE 3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | |
1624 \ 'linE 4 AbcdefghijklmnopqrstuvwXyz', | |
1625 \ 'linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | |
1626 \ 'linE 6 AbcdefghijklmnopqrstuvwXyz', | |
1627 \ 'linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | |
1628 \ 'linE 8 AbcdefghijklmnopqrstuvwXyz', | |
1629 \ 'linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | |
1630 \ 'linE 10 AbcdefghijklmnopqrstuvwXyz' | |
1631 \ ], getline(1, 9)) | |
1632 call assert_equal([ | |
1633 \ 'line 2 Abcdefghijklmnopqrstuvwxyz', | |
1634 \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1635 \ 'line 4 Abcdefghijklmnopqrstuvwxyz', | |
1636 \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1637 \ 'line 6 Abcdefghijklmnopqrstuvwxyz', | |
1638 \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1639 \ 'line 8 Abcdefghijklmnopqrstuvwxyz', | |
1640 \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1641 \ 'line 10 Abcdefghijklmnopqrstuvwxyz' | |
1642 \ ], readfile('test.out')) | |
1643 | |
1644 augroup Test4 | |
1645 au! | |
1646 augroup END | |
1647 set shelltemp&vim | |
1648 | |
1649 " Test for the FileReadPre and FileReadPost autocmds. | |
1650 augroup Test5 | |
1651 au! | |
1652 au FileReadPre *.gz exe 'silent !gzip -d ' . shellescape(expand("<afile>")) | |
1653 au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) | |
1654 au FileReadPost *.gz '[,']s/l/L/ | |
1655 augroup END | |
1656 | |
1657 new | |
1658 0r Xtestfile.gz " Read compressed file | |
1659 call assert_equal([ | |
1660 \ 'Line 2 Abcdefghijklmnopqrstuvwxyz', | |
1661 \ 'Line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1662 \ 'Line 4 Abcdefghijklmnopqrstuvwxyz', | |
1663 \ 'Line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1664 \ 'Line 6 Abcdefghijklmnopqrstuvwxyz', | |
1665 \ 'Line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1666 \ 'Line 8 Abcdefghijklmnopqrstuvwxyz', | |
1667 \ 'Line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1668 \ 'Line 10 Abcdefghijklmnopqrstuvwxyz' | |
1669 \ ], getline(1, 9)) | |
1670 call assert_equal([ | |
1671 \ 'line 2 Abcdefghijklmnopqrstuvwxyz', | |
1672 \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1673 \ 'line 4 Abcdefghijklmnopqrstuvwxyz', | |
1674 \ 'line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1675 \ 'line 6 Abcdefghijklmnopqrstuvwxyz', | |
1676 \ 'line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1677 \ 'line 8 Abcdefghijklmnopqrstuvwxyz', | |
1678 \ 'line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | |
1679 \ 'line 10 Abcdefghijklmnopqrstuvwxyz' | |
1680 \ ], readfile('Xtestfile.gz')) | |
1681 | |
1682 augroup Test5 | |
1683 au! | |
1684 augroup END | |
1685 | |
1686 au! FileChangedShell | |
1687 call delete('Xtestfile.gz') | |
1688 call delete('Xtest.c') | |
1689 call delete('test.out') | |
1690 endfunc |