]> code.delx.au - gnu-emacs-elpa/blob - packages/js2-mode/tests/navigation.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / js2-mode / tests / navigation.el
1 ;;; tests/navigation.el --- Some tests for js2-mode.
2
3 ;; Copyright (C) 2009, 2011-2015 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 &optional expected-point (point-offset 1))
26 (with-temp-buffer
27 (insert buffer-content)
28 (let ((start-point (or (- (point) point-offset))))
29 (js2-mode)
30 (goto-char start-point)
31 (ignore-errors (js2-jump-to-definition))
32 (print (format "%d %d" (point) start-point))
33 (should (= (point) (or expected-point start-point))))))
34
35 (ert-deftest js2-jump-to-var ()
36 (js2-navigation-helper "var soup = 2; soup" 5))
37
38 (ert-deftest js2-jump-to-function ()
39 (js2-navigation-helper "function aFunction() {}; aFunction" 1))
40
41 (ert-deftest js2-jump-to-function-parameters ()
42 (js2-navigation-helper "var p1 = 4; function aFunction(p1, p2) {p1};" 32 4))
43
44 (ert-deftest js2-jump-to-object-property ()
45 (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"}; aObject.prop1" 16))
46
47 (ert-deftest js2-no-jump-to-object-property ()
48 (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"}; anotherObject.prop1"))
49
50 (ert-deftest js2-jump-to-nested-property ()
51 (js2-navigation-helper "var aObject = {prop1: {prop2: { prop3: 4}}}; aObject.prop1.prop2.prop3" 33))
52
53 (ert-deftest js2-jump-to-object ()
54 (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"}; aObject.prop1" 5 13))
55
56 (ert-deftest js2-jump-to-property ()
57 (js2-navigation-helper "aObject.func = functon(){};aObject.func" 9))
58
59 (ert-deftest js2-jump-to-property-object-property ()
60 (js2-navigation-helper "aObject.value = {prop:1};aObject.value.prop" 18))