]> code.delx.au - gnu-emacs-elpa/blob - tests/navigation.el
Add a jump to definition command bound to M-.
[gnu-emacs-elpa] / tests / navigation.el
1 ;;; tests/navigation.el --- Some tests for js2-mode.
2
3 ;; Copyright (C) 2009, 2011-2013 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Code:
21
22 (require 'ert)
23 (require 'js2-mode)
24
25 (cl-defun js2-navigation-helper (buffer-content expected-point &optional (point-offset 1))
26 (with-temp-buffer
27 (insert buffer-content)
28 (js2-mode)
29 (goto-char (or (- (point) point-offset)))
30 (js2-jump-to-definition)
31 (should (= (point) expected-point))))
32
33 (ert-deftest js2-jump-to-var ()
34 (js2-navigation-helper "var soup = 2; soup" 5))
35
36 (ert-deftest js2-jump-to-function ()
37 (js2-navigation-helper "function aFunction() {}; aFunction" 1))
38
39 (ert-deftest js2-jump-to-function-parameters ()
40 (js2-navigation-helper "var p1 = 4; function aFunction(p1, p2) {p1};" 32 4))
41
42 (ert-deftest js2-jump-to-object-property ()
43 (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"}; aObject.prop1" 16))