aboutsummaryrefslogtreecommitdiffstats
path: root/test/automated/python-tests.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2013-04-18 23:31:09 -0300
committerFabián Ezequiel Gallina2013-04-18 23:31:09 -0300
commitadc3121366c4cc6d90b0122036bdfb0eb6308e3f (patch)
tree502e58d0fa27c68dd1afa0f380b26c3f864dfb4c /test/automated/python-tests.el
parent7e00831f518cf4c9ca505ec3e8767bf0787766b4 (diff)
downloademacs-adc3121366c4cc6d90b0122036bdfb0eb6308e3f.tar.gz
emacs-adc3121366c4cc6d90b0122036bdfb0eb6308e3f.zip
New faster Imenu implementation.
* lisp/progmodes/python.el: (python-imenu-prev-index-position): (python-imenu-format-item-label-function) (python-imenu-format-parent-item-label-function) (python-imenu-format-parent-item-jump-label-function): New vars. (python-imenu-format-item-label) (python-imenu-format-parent-item-label) (python-imenu-format-parent-item-jump-label) (python-imenu--put-parent, python-imenu--build-tree) (python-imenu-create-index, python-imenu-create-flat-index) (python-util-popn): New functions. (python-mode): Set imenu-create-index-function to python-imenu-create-index. * test/automated/python-tests.el (python-imenu-prev-index-position-1): Removed test. (python-imenu-create-index-1, python-imenu-create-flat-index-1): New tests. Fixes: debbugs:14058
Diffstat (limited to 'test/automated/python-tests.el')
-rw-r--r--test/automated/python-tests.el143
1 files changed, 105 insertions, 38 deletions
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index 15089e6b393..8462a863b84 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -1673,66 +1673,133 @@ Using `python-shell-interpreter' and
1673 1673
1674 1674
1675;;; Imenu 1675;;; Imenu
1676(ert-deftest python-imenu-prev-index-position-1 () 1676
1677 (require 'imenu) 1677(ert-deftest python-imenu-create-index-1 ()
1678 (python-tests-with-temp-buffer 1678 (python-tests-with-temp-buffer
1679 " 1679 "
1680def decoratorFunctionWithArguments(arg1, arg2, arg3): 1680class Foo(models.Model):
1681 pass
1682
1683
1684class Bar(models.Model):
1685 pass
1686
1687
1688def decorator(arg1, arg2, arg3):
1681 '''print decorated function call data to stdout. 1689 '''print decorated function call data to stdout.
1682 1690
1683 Usage: 1691 Usage:
1684 1692
1685 @decoratorFunctionWithArguments('arg1', 'arg2') 1693 @decorator('arg1', 'arg2')
1686 def func(a, b, c=True): 1694 def func(a, b, c=True):
1687 pass 1695 pass
1688 ''' 1696 '''
1689 1697
1690 def wwrap(f): 1698 def wrap(f):
1691 print 'Inside wwrap()' 1699 print ('wrap')
1692 def wrapped_f(*args): 1700 def wrapped_f(*args):
1693 print 'Inside wrapped_f()' 1701 print ('wrapped_f')
1694 print 'Decorator arguments:', arg1, arg2, arg3 1702 print ('Decorator arguments:', arg1, arg2, arg3)
1695 f(*args) 1703 f(*args)
1696 print 'After f(*args)' 1704 print ('called f(*args)')
1697 return wrapped_f 1705 return wrapped_f
1698 return wwrap 1706 return wrap
1699 1707
1700def test(): # Some comment
1701 'This is a test function'
1702 print 'test'
1703 1708
1704class C(object): 1709class Baz(object):
1705 1710
1706 def m(self): 1711 def a(self):
1707 self.c() 1712 pass
1708 1713
1709 def b(): 1714 def b(self):
1710 pass 1715 pass
1711 1716
1712 def a(): 1717 class Frob(object):
1718
1719 def c(self):
1713 pass 1720 pass
1721"
1722 (goto-char (point-max))
1723 (should (equal
1724 (list
1725 (cons "Foo (class)" (copy-marker 2))
1726 (cons "Bar (class)" (copy-marker 38))
1727 (list
1728 "decorator (def)"
1729 (cons "*function definition*" (copy-marker 74))
1730 (list
1731 "wrap (def)"
1732 (cons "*function definition*" (copy-marker 254))
1733 (cons "wrapped_f (def)" (copy-marker 294))))
1734 (list
1735 "Baz (class)"
1736 (cons "*class definition*" (copy-marker 519))
1737 (cons "a (def)" (copy-marker 539))
1738 (cons "b (def)" (copy-marker 570))
1739 (list
1740 "Frob (class)"
1741 (cons "*class definition*" (copy-marker 601))
1742 (cons "c (def)" (copy-marker 626)))))
1743 (python-imenu-create-index)))))
1744
1745(ert-deftest python-imenu-create-flat-index-1 ()
1746 (python-tests-with-temp-buffer
1747 "
1748class Foo(models.Model):
1749 pass
1714 1750
1715 def c(self): 1751
1752class Bar(models.Model):
1753 pass
1754
1755
1756def decorator(arg1, arg2, arg3):
1757 '''print decorated function call data to stdout.
1758
1759 Usage:
1760
1761 @decorator('arg1', 'arg2')
1762 def func(a, b, c=True):
1763 pass
1764 '''
1765
1766 def wrap(f):
1767 print ('wrap')
1768 def wrapped_f(*args):
1769 print ('wrapped_f')
1770 print ('Decorator arguments:', arg1, arg2, arg3)
1771 f(*args)
1772 print ('called f(*args)')
1773 return wrapped_f
1774 return wrap
1775
1776
1777class Baz(object):
1778
1779 def a(self):
1780 pass
1781
1782 def b(self):
1716 pass 1783 pass
1784
1785 class Frob(object):
1786
1787 def c(self):
1788 pass
1717" 1789"
1718 (let ((expected 1790 (goto-char (point-max))
1719 '(("*Rescan*" . -99) 1791 (should (equal
1720 ("decoratorFunctionWithArguments" . 2) 1792 (list (cons "Foo" (copy-marker 2))
1721 ("decoratorFunctionWithArguments.wwrap" . 224) 1793 (cons "Bar" (copy-marker 38))
1722 ("decoratorFunctionWithArguments.wwrap.wrapped_f" . 273) 1794 (cons "decorator" (copy-marker 74))
1723 ("test" . 500) 1795 (cons "decorator.wrap" (copy-marker 254))
1724 ("C" . 575) 1796 (cons "decorator.wrap.wrapped_f" (copy-marker 294))
1725 ("C.m" . 593) 1797 (cons "Baz" (copy-marker 519))
1726 ("C.m.b" . 628) 1798 (cons "Baz.a" (copy-marker 539))
1727 ("C.m.a" . 663) 1799 (cons "Baz.b" (copy-marker 570))
1728 ("C.c" . 698)))) 1800 (cons "Baz.Frob" (copy-marker 601))
1729 (mapc 1801 (cons "Baz.Frob.c" (copy-marker 626)))
1730 (lambda (elt) 1802 (python-imenu-create-flat-index)))))
1731 (should (= (cdr (assoc-string (car elt) expected))
1732 (if (markerp (cdr elt))
1733 (marker-position (cdr elt))
1734 (cdr elt)))))
1735 (imenu--make-index-alist)))))
1736 1803
1737 1804
1738;;; Misc helpers 1805;;; Misc helpers