comparison src/testdir/test_textprop.vim @ 26242:685206b54ecf v8.2.3652

patch 8.2.3652: can only get text properties one line at a time Commit: https://github.com/vim/vim/commit/e021662f39b38ef7cf27e13850d0ce6890e48376 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Nov 23 11:46:32 2021 +0000 patch 8.2.3652: can only get text properties one line at a time Problem: Can only get text properties one line at a time. Solution: Add options to prop_list() to use a range of lines and filter by types. (Yegappan Lakshmanan, closes #9138)
author Bram Moolenaar <Bram@vim.org>
date Tue, 23 Nov 2021 13:00:05 +0100
parents 1d14b5d3de17
children 4cf208415483
comparison
equal deleted inserted replaced
26241:ae5abfa1efc8 26242:685206b54ecf
3 3
4 source check.vim 4 source check.vim
5 CheckFeature textprop 5 CheckFeature textprop
6 6
7 source screendump.vim 7 source screendump.vim
8 source vim9.vim
8 9
9 func Test_proptype_global() 10 func Test_proptype_global()
10 call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) 11 call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1})
11 let proptypes = prop_type_list() 12 let proptypes = prop_type_list()
12 call assert_equal(1, len(proptypes)) 13 call assert_equal(1, len(proptypes))
1643 bwipe! 1644 bwipe!
1644 prop_type_delete('bufnr-global') 1645 prop_type_delete('bufnr-global')
1645 endtry 1646 endtry
1646 enddef 1647 enddef
1647 1648
1648 1649 " Tests for the prop_list() function
1650 func Test_prop_list()
1651 let lines =<< trim END
1652 new
1653 call AddPropTypes()
1654 call setline(1, repeat([repeat('a', 60)], 10))
1655 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
1656 call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7})
1657 call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14})
1658 call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15})
1659 call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22})
1660 call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23})
1661 call assert_equal([
1662 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1663 \ 'type': 'one', 'length': 2, 'start': 1},
1664 \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
1665 \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1))
1666 #" text properties between a few lines
1667 call assert_equal([
1668 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
1669 \ 'type': 'one', 'length': 2, 'start': 1},
1670 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
1671 \ 'type': 'two', 'length': 2, 'start': 1},
1672 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
1673 \ 'type': 'one', 'length': 2, 'start': 1},
1674 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
1675 \ 'type': 'two', 'length': 2, 'start': 1}],
1676 \ prop_list(2, {'end_lnum': 5}))
1677 #" text properties across all the lines
1678 call assert_equal([
1679 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1680 \ 'type': 'one', 'length': 2, 'start': 1},
1681 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
1682 \ 'type': 'one', 'length': 2, 'start': 1},
1683 \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1,
1684 \ 'type': 'one', 'length': 2, 'start': 1}],
1685 \ prop_list(1, {'types': ['one'], 'end_lnum': -1}))
1686 #" text properties with the specified identifier
1687 call assert_equal([
1688 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
1689 \ 'type': 'one', 'length': 2, 'start': 1},
1690 \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1,
1691 \ 'type': 'two', 'length': 2, 'start': 1}],
1692 \ prop_list(1, {'ids': [20], 'end_lnum': 10}))
1693 #" text properties of the specified type and id
1694 call assert_equal([
1695 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
1696 \ 'type': 'two', 'length': 2, 'start': 1},
1697 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
1698 \ 'type': 'two', 'length': 2, 'start': 1}],
1699 \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20}))
1700 call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10}))
1701 call assert_equal([], prop_list(6, {'end_lnum': 10}))
1702 call assert_equal([], prop_list(2, {'end_lnum': 2}))
1703 #" error cases
1704 call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:')
1705 call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:')
1706 call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:')
1707 call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})",
1708 \ 'E971:')
1709 call assert_fails("echo prop_list(1, {'types': ['one', 'blue'],
1710 \ 'end_lnum': 10})", 'E971:')
1711 call assert_fails("echo prop_list(1, {'types': ['one', 10],
1712 \ 'end_lnum': 10})", 'E928:')
1713 call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:')
1714 call assert_equal([], prop_list(2, {'types': []}))
1715 call assert_equal([], prop_list(2, {'types': test_null_list()}))
1716 call assert_fails("call prop_list(1, {'types': {}})", 'E714:')
1717 call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:')
1718 call assert_equal([], prop_list(2, {'types': ['one'],
1719 \ 'ids': test_null_list()}))
1720 call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []}))
1721 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})",
1722 \ 'E714:')
1723 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})",
1724 \ 'E714:')
1725 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})",
1726 \ 'E745:')
1727 call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})",
1728 \ 'E745:')
1729
1730 #" get text properties from a non-current buffer
1731 wincmd w
1732 call assert_equal([
1733 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1734 \ 'type': 'one', 'length': 2, 'start': 1},
1735 \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1,
1736 \ 'type': 'two', 'length': 2, 'start': 1},
1737 \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1,
1738 \ 'type': 'one', 'length': 2, 'start': 1},
1739 \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1,
1740 \ 'type': 'two', 'length': 2, 'start': 1}],
1741 \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4}))
1742 wincmd w
1743
1744 #" get text properties after clearing all the properties
1745 call prop_clear(1, line('$'))
1746 call assert_equal([], prop_list(1, {'end_lnum': 10}))
1747
1748 call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6})
1749 call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6})
1750 call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6})
1751 #" get text properties with a list of types
1752 call assert_equal([
1753 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
1754 \ 'type': 'two', 'length': 2, 'start': 1},
1755 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1756 \ 'type': 'one', 'length': 2, 'start': 1}],
1757 \ prop_list(2, {'types': ['one', 'two']}))
1758 call assert_equal([
1759 \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1,
1760 \ 'type': 'three', 'length': 2, 'start': 1},
1761 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1762 \ 'type': 'one', 'length': 2, 'start': 1}],
1763 \ prop_list(2, {'types': ['one', 'three']}))
1764 #" get text properties with a list of identifiers
1765 call assert_equal([
1766 \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1,
1767 \ 'type': 'two', 'length': 2, 'start': 1},
1768 \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1769 \ 'type': 'one', 'length': 2, 'start': 1}],
1770 \ prop_list(2, {'ids': [5, 10, 20]}))
1771 call prop_clear(1, line('$'))
1772 call assert_equal([], prop_list(2, {'types': ['one', 'two']}))
1773 call assert_equal([], prop_list(2, {'ids': [5, 10, 20]}))
1774
1775 #" get text properties from a hidden buffer
1776 edit! Xaaa
1777 call setline(1, repeat([repeat('b', 60)], 10))
1778 call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
1779 call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10})
1780 VAR bnr = bufnr()
1781 hide edit Xbbb
1782 call assert_equal([
1783 \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1,
1784 \ 'type': 'one', 'length': 2, 'start': 1},
1785 \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1,
1786 \ 'type': 'two', 'length': 2, 'start': 1}],
1787 \ prop_list(1, {'bufnr': bnr,
1788 \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1}))
1789 #" get text properties from an unloaded buffer
1790 bunload! Xaaa
1791 call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1}))
1792
1793 call DeletePropTypes()
1794 :%bw!
1795 END
1796 call CheckLegacyAndVim9Success(lines)
1797 endfunc
1649 1798
1650 " vim: shiftwidth=2 sts=2 expandtab 1799 " vim: shiftwidth=2 sts=2 expandtab