diff options
| author | Theodor Thornhill | 2023-01-16 14:33:27 +0100 |
|---|---|---|
| committer | Theodor Thornhill | 2023-01-16 14:33:27 +0100 |
| commit | c8dd37b16c574beda900d4ee48ac7b4ab4a2ee56 (patch) | |
| tree | bfdf78d1353b15e22bc6cd106ce18a89eb069dd6 /test | |
| parent | e84111a0017b953be363210a68ac0c05f3f864bb (diff) | |
| download | emacs-c8dd37b16c574beda900d4ee48ac7b4ab4a2ee56.tar.gz emacs-c8dd37b16c574beda900d4ee48ac7b4ab4a2ee56.zip | |
Add some basic tests for java-ts-mode and typescript-ts-mode
* test/lisp/progmodes/java-ts-mode-resources/indent.erts: New file
with tests for indentation.
* test/lisp/progmodes/java-ts-mode-resources/movement.erts: New file
with tests for movement.
* test/lisp/progmodes/java-ts-mode-tests.el: New tests.
* test/lisp/progmodes/typescript-ts-mode-resources/indent.erts: New
file with tests for indentation.
* test/lisp/progmodes/typescript-ts-mode-tests.el: New tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/progmodes/java-ts-mode-resources/indent.erts | 44 | ||||
| -rw-r--r-- | test/lisp/progmodes/java-ts-mode-resources/movement.erts | 154 | ||||
| -rw-r--r-- | test/lisp/progmodes/java-ts-mode-tests.el | 35 | ||||
| -rw-r--r-- | test/lisp/progmodes/typescript-ts-mode-resources/indent.erts | 73 | ||||
| -rw-r--r-- | test/lisp/progmodes/typescript-ts-mode-tests.el | 31 |
5 files changed, 337 insertions, 0 deletions
diff --git a/test/lisp/progmodes/java-ts-mode-resources/indent.erts b/test/lisp/progmodes/java-ts-mode-resources/indent.erts new file mode 100644 index 00000000000..e59d5fed8e8 --- /dev/null +++ b/test/lisp/progmodes/java-ts-mode-resources/indent.erts | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | Code: | ||
| 2 | (lambda () | ||
| 3 | (setq indent-tabs-mode nil) | ||
| 4 | (setq java-ts-mode-indent-offset 2) | ||
| 5 | (java-ts-mode) | ||
| 6 | (indent-region (point-min) (point-max))) | ||
| 7 | |||
| 8 | Point-Char: | | ||
| 9 | |||
| 10 | Name: Basic | ||
| 11 | |||
| 12 | =-= | ||
| 13 | public class Basic { | ||
| 14 | public void basic() { | ||
| 15 | return; | ||
| 16 | } | ||
| 17 | } | ||
| 18 | =-=-= | ||
| 19 | |||
| 20 | Name: Empty Line | ||
| 21 | |||
| 22 | =-= | ||
| 23 | public class EmptyLine { | ||
| 24 | public void emptyLine() { | ||
| 25 | | | ||
| 26 | } | ||
| 27 | } | ||
| 28 | =-=-= | ||
| 29 | |||
| 30 | Name: Statements | ||
| 31 | |||
| 32 | =-= | ||
| 33 | if (x) { | ||
| 34 | for (var foo : foos) { | ||
| 35 | | | ||
| 36 | } | ||
| 37 | } else if (y) { | ||
| 38 | for (int i = 0; x < foos.size(); i++) { | ||
| 39 | return; | ||
| 40 | } | ||
| 41 | } else { | ||
| 42 | return; | ||
| 43 | } | ||
| 44 | =-=-= | ||
diff --git a/test/lisp/progmodes/java-ts-mode-resources/movement.erts b/test/lisp/progmodes/java-ts-mode-resources/movement.erts new file mode 100644 index 00000000000..23639b1f5ff --- /dev/null +++ b/test/lisp/progmodes/java-ts-mode-resources/movement.erts | |||
| @@ -0,0 +1,154 @@ | |||
| 1 | Code: | ||
| 2 | (lambda () | ||
| 3 | (java-ts-mode) | ||
| 4 | (forward-sentence 1)) | ||
| 5 | |||
| 6 | Point-Char: | | ||
| 7 | |||
| 8 | Name: forward-sentence moves over if | ||
| 9 | |||
| 10 | =-= | ||
| 11 | public class Basic { | ||
| 12 | public void basic() { | ||
| 13 | |if (x) { | ||
| 14 | |||
| 15 | } | ||
| 16 | log.info("some text: {}", text); | ||
| 17 | return; | ||
| 18 | } | ||
| 19 | } | ||
| 20 | =-= | ||
| 21 | public class Basic { | ||
| 22 | public void basic() { | ||
| 23 | if (x) { | ||
| 24 | |||
| 25 | }| | ||
| 26 | log.info("some text: {}", text); | ||
| 27 | return; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | =-=-= | ||
| 31 | |||
| 32 | Name: forward-sentence moves over method invocation | ||
| 33 | |||
| 34 | =-= | ||
| 35 | public class Basic { | ||
| 36 | public void basic() { | ||
| 37 | |log.info("some text: {}", text); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | =-= | ||
| 41 | public class Basic { | ||
| 42 | public void basic() { | ||
| 43 | log.info("some text: {}", text);| | ||
| 44 | } | ||
| 45 | } | ||
| 46 | =-=-= | ||
| 47 | |||
| 48 | Code: | ||
| 49 | (lambda () | ||
| 50 | (java-ts-mode) | ||
| 51 | (forward-sentence 2)) | ||
| 52 | |||
| 53 | Name: forward-sentence moves over multiple statements | ||
| 54 | |||
| 55 | =-= | ||
| 56 | public class Basic { | ||
| 57 | public void basic() { | ||
| 58 | |return; | ||
| 59 | return; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | =-= | ||
| 63 | public class Basic { | ||
| 64 | public void basic() { | ||
| 65 | return; | ||
| 66 | return;| | ||
| 67 | } | ||
| 68 | } | ||
| 69 | =-=-= | ||
| 70 | |||
| 71 | Code: | ||
| 72 | (lambda () | ||
| 73 | (java-ts-mode) | ||
| 74 | (backward-sentence 1)) | ||
| 75 | |||
| 76 | Name: backward-sentence moves over one statement | ||
| 77 | |||
| 78 | =-= | ||
| 79 | public class Basic { | ||
| 80 | public void basic() { | ||
| 81 | return;| | ||
| 82 | } | ||
| 83 | } | ||
| 84 | =-= | ||
| 85 | public class Basic { | ||
| 86 | public void basic() { | ||
| 87 | |return; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | =-=-= | ||
| 91 | |||
| 92 | Code: | ||
| 93 | (lambda () | ||
| 94 | (java-ts-mode) | ||
| 95 | (beginning-of-defun)) | ||
| 96 | |||
| 97 | Name: beginning-of-defun moves to defun start | ||
| 98 | |||
| 99 | =-= | ||
| 100 | public class Basic { | ||
| 101 | public void basic() { | ||
| 102 | return;| | ||
| 103 | } | ||
| 104 | } | ||
| 105 | =-= | ||
| 106 | public class Basic { | ||
| 107 | | public void basic() { | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | =-=-= | ||
| 112 | |||
| 113 | Code: | ||
| 114 | (lambda () | ||
| 115 | (java-ts-mode) | ||
| 116 | (beginning-of-defun) | ||
| 117 | (beginning-of-defun)) | ||
| 118 | |||
| 119 | Name: beginning-of-defun moves to class | ||
| 120 | |||
| 121 | =-= | ||
| 122 | public class Basic { | ||
| 123 | public void basic() { | ||
| 124 | return;| | ||
| 125 | } | ||
| 126 | } | ||
| 127 | =-= | ||
| 128 | |public class Basic { | ||
| 129 | public void basic() { | ||
| 130 | return; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | =-=-= | ||
| 134 | |||
| 135 | Code: | ||
| 136 | (lambda () | ||
| 137 | (java-ts-mode) | ||
| 138 | (end-of-defun)) | ||
| 139 | |||
| 140 | Name: end-of-defun moves to defun end | ||
| 141 | |||
| 142 | =-= | ||
| 143 | public class Basic { | ||
| 144 | public void basic() { | ||
| 145 | return;| | ||
| 146 | } | ||
| 147 | } | ||
| 148 | =-= | ||
| 149 | public class Basic { | ||
| 150 | public void basic() { | ||
| 151 | return; | ||
| 152 | } | ||
| 153 | |} | ||
| 154 | =-=-= | ||
diff --git a/test/lisp/progmodes/java-ts-mode-tests.el b/test/lisp/progmodes/java-ts-mode-tests.el new file mode 100644 index 00000000000..4fd8fc3019f --- /dev/null +++ b/test/lisp/progmodes/java-ts-mode-tests.el | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | ;;; java-ts-mode-tests.el --- Tests for Tree-sitter-based Java mode -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2023 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 <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Code: | ||
| 21 | |||
| 22 | (require 'ert) | ||
| 23 | (require 'ert-x) | ||
| 24 | (require 'treesit) | ||
| 25 | |||
| 26 | (ert-deftest java-ts-mode-test-indentation () | ||
| 27 | (skip-unless (treesit-ready-p 'java)) | ||
| 28 | (ert-test-erts-file (ert-resource-file "indent.erts"))) | ||
| 29 | |||
| 30 | (ert-deftest java-ts-mode-test-movement () | ||
| 31 | (skip-unless (treesit-ready-p 'java)) | ||
| 32 | (ert-test-erts-file (ert-resource-file "movement.erts"))) | ||
| 33 | |||
| 34 | (provide 'java-ts-mode-tests) | ||
| 35 | ;;; java-ts-mode-tests.el ends here | ||
diff --git a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts new file mode 100644 index 00000000000..146ee76574e --- /dev/null +++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | Code: | ||
| 2 | (lambda () | ||
| 3 | (setq indent-tabs-mode nil) | ||
| 4 | (setq typescript-ts-mode-indent-offset 2) | ||
| 5 | (typescript-ts-mode) | ||
| 6 | (indent-region (point-min) (point-max))) | ||
| 7 | |||
| 8 | Point-Char: | | ||
| 9 | |||
| 10 | Name: Basic indentation | ||
| 11 | |||
| 12 | =-= | ||
| 13 | const foo = () => { | ||
| 14 | console.log("bar"); | ||
| 15 | if (x) { | ||
| 16 | return y; | ||
| 17 | } else if (y) { | ||
| 18 | return u; | ||
| 19 | } | ||
| 20 | return baz.x() | ||
| 21 | ? true | ||
| 22 | : false; | ||
| 23 | } | ||
| 24 | =-=-= | ||
| 25 | |||
| 26 | Code: | ||
| 27 | (lambda () | ||
| 28 | (setq indent-tabs-mode nil) | ||
| 29 | (setq tsx-ts-mode-indent-offset 2) | ||
| 30 | (tsx-ts-mode) | ||
| 31 | (indent-region (point-min) (point-max))) | ||
| 32 | |||
| 33 | Name: JSX indentation | ||
| 34 | |||
| 35 | =-= | ||
| 36 | const foo = (props) => { | ||
| 37 | return ( | ||
| 38 | <div> | ||
| 39 | <div> | ||
| 40 | <div> | ||
| 41 | <div> | ||
| 42 | { | ||
| 43 | props.foo | ||
| 44 | ? Hello, foo! | ||
| 45 | : Hello, World!; | ||
| 46 | } | ||
| 47 | </div> | ||
| 48 | </div> | ||
| 49 | </div> | ||
| 50 | </div> | ||
| 51 | ); | ||
| 52 | } | ||
| 53 | =-=-= | ||
| 54 | |||
| 55 | Name: JSX indentation with attributes | ||
| 56 | |||
| 57 | =-= | ||
| 58 | const foo = (props) => { | ||
| 59 | return ( | ||
| 60 | <div | ||
| 61 | className={foo} | ||
| 62 | onClick={() => { | ||
| 63 | alert('???'); | ||
| 64 | return () => { | ||
| 65 | return 5+5; | ||
| 66 | }; | ||
| 67 | }} | ||
| 68 | > | ||
| 69 | <p>Some text</p> | ||
| 70 | </div> | ||
| 71 | ); | ||
| 72 | } | ||
| 73 | =-=-= | ||
diff --git a/test/lisp/progmodes/typescript-ts-mode-tests.el b/test/lisp/progmodes/typescript-ts-mode-tests.el new file mode 100644 index 00000000000..126f5e3298f --- /dev/null +++ b/test/lisp/progmodes/typescript-ts-mode-tests.el | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | ;;; typescript-ts-mode-tests.el --- Tests for Tree-sitter-based TypeScript mode -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2023 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 <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Code: | ||
| 21 | |||
| 22 | (require 'ert) | ||
| 23 | (require 'ert-x) | ||
| 24 | (require 'treesit) | ||
| 25 | |||
| 26 | (ert-deftest typescript-ts-mode-test-indentation () | ||
| 27 | (skip-unless (treesit-ready-p 'typescript)) | ||
| 28 | (ert-test-erts-file (ert-resource-file "indent.erts"))) | ||
| 29 | |||
| 30 | (provide 'typescript-ts-mode-tests) | ||
| 31 | ;;; typescript-ts-mode-tests.el ends here | ||