* 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.
(cherry picked from commit
c8dd37b16c574beda900d4ee48ac7b4ab4a2ee56)
--- /dev/null
+Code:
+ (lambda ()
+ (setq indent-tabs-mode nil)
+ (setq java-ts-mode-indent-offset 2)
+ (java-ts-mode)
+ (indent-region (point-min) (point-max)))
+
+Point-Char: |
+
+Name: Basic
+
+=-=
+public class Basic {
+ public void basic() {
+ return;
+ }
+}
+=-=-=
+
+Name: Empty Line
+
+=-=
+public class EmptyLine {
+ public void emptyLine() {
+ |
+ }
+}
+=-=-=
+
+Name: Statements
+
+=-=
+if (x) {
+ for (var foo : foos) {
+ |
+ }
+} else if (y) {
+ for (int i = 0; x < foos.size(); i++) {
+ return;
+ }
+} else {
+ return;
+}
+=-=-=
--- /dev/null
+Code:
+ (lambda ()
+ (java-ts-mode)
+ (forward-sentence 1))
+
+Point-Char: |
+
+Name: forward-sentence moves over if
+
+=-=
+public class Basic {
+ public void basic() {
+ |if (x) {
+
+ }
+ log.info("some text: {}", text);
+ return;
+ }
+}
+=-=
+public class Basic {
+ public void basic() {
+ if (x) {
+
+ }|
+ log.info("some text: {}", text);
+ return;
+ }
+}
+=-=-=
+
+Name: forward-sentence moves over method invocation
+
+=-=
+public class Basic {
+ public void basic() {
+ |log.info("some text: {}", text);
+ }
+}
+=-=
+public class Basic {
+ public void basic() {
+ log.info("some text: {}", text);|
+ }
+}
+=-=-=
+
+Code:
+ (lambda ()
+ (java-ts-mode)
+ (forward-sentence 2))
+
+Name: forward-sentence moves over multiple statements
+
+=-=
+public class Basic {
+ public void basic() {
+ |return;
+ return;
+ }
+}
+=-=
+public class Basic {
+ public void basic() {
+ return;
+ return;|
+ }
+}
+=-=-=
+
+Code:
+ (lambda ()
+ (java-ts-mode)
+ (backward-sentence 1))
+
+Name: backward-sentence moves over one statement
+
+=-=
+public class Basic {
+ public void basic() {
+ return;|
+ }
+}
+=-=
+public class Basic {
+ public void basic() {
+ |return;
+ }
+}
+=-=-=
+
+Code:
+ (lambda ()
+ (java-ts-mode)
+ (beginning-of-defun))
+
+Name: beginning-of-defun moves to defun start
+
+=-=
+public class Basic {
+ public void basic() {
+ return;|
+ }
+}
+=-=
+public class Basic {
+| public void basic() {
+ return;
+ }
+}
+=-=-=
+
+Code:
+ (lambda ()
+ (java-ts-mode)
+ (beginning-of-defun)
+ (beginning-of-defun))
+
+Name: beginning-of-defun moves to class
+
+=-=
+public class Basic {
+ public void basic() {
+ return;|
+ }
+}
+=-=
+|public class Basic {
+ public void basic() {
+ return;
+ }
+}
+=-=-=
+
+Code:
+ (lambda ()
+ (java-ts-mode)
+ (end-of-defun))
+
+Name: end-of-defun moves to defun end
+
+=-=
+public class Basic {
+ public void basic() {
+ return;|
+ }
+}
+=-=
+public class Basic {
+ public void basic() {
+ return;
+ }
+|}
+=-=-=
--- /dev/null
+;;; java-ts-mode-tests.el --- Tests for Tree-sitter-based Java mode -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'ert-x)
+(require 'treesit)
+
+(ert-deftest java-ts-mode-test-indentation ()
+ (skip-unless (treesit-ready-p 'java))
+ (ert-test-erts-file (ert-resource-file "indent.erts")))
+
+(ert-deftest java-ts-mode-test-movement ()
+ (skip-unless (treesit-ready-p 'java))
+ (ert-test-erts-file (ert-resource-file "movement.erts")))
+
+(provide 'java-ts-mode-tests)
+;;; java-ts-mode-tests.el ends here
--- /dev/null
+Code:
+ (lambda ()
+ (setq indent-tabs-mode nil)
+ (setq typescript-ts-mode-indent-offset 2)
+ (typescript-ts-mode)
+ (indent-region (point-min) (point-max)))
+
+Point-Char: |
+
+Name: Basic indentation
+
+=-=
+const foo = () => {
+ console.log("bar");
+ if (x) {
+ return y;
+ } else if (y) {
+ return u;
+ }
+ return baz.x()
+ ? true
+ : false;
+}
+=-=-=
+
+Code:
+ (lambda ()
+ (setq indent-tabs-mode nil)
+ (setq tsx-ts-mode-indent-offset 2)
+ (tsx-ts-mode)
+ (indent-region (point-min) (point-max)))
+
+Name: JSX indentation
+
+=-=
+const foo = (props) => {
+ return (
+ <div>
+ <div>
+ <div>
+ <div>
+ {
+ props.foo
+ ? Hello, foo!
+ : Hello, World!;
+ }
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+=-=-=
+
+Name: JSX indentation with attributes
+
+=-=
+const foo = (props) => {
+ return (
+ <div
+ className={foo}
+ onClick={() => {
+ alert('???');
+ return () => {
+ return 5+5;
+ };
+ }}
+ >
+ <p>Some text</p>
+ </div>
+ );
+}
+=-=-=
--- /dev/null
+;;; typescript-ts-mode-tests.el --- Tests for Tree-sitter-based TypeScript mode -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'ert-x)
+(require 'treesit)
+
+(ert-deftest typescript-ts-mode-test-indentation ()
+ (skip-unless (treesit-ready-p 'typescript))
+ (ert-test-erts-file (ert-resource-file "indent.erts")))
+
+(provide 'typescript-ts-mode-tests)
+;;; typescript-ts-mode-tests.el ends here