emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c8dd37b16c 2/2: Add some basic tests for java-ts-mode and typescr


From: Theodor Thornhill
Subject: master c8dd37b16c 2/2: Add some basic tests for java-ts-mode and typescript-ts-mode
Date: Mon, 16 Jan 2023 08:38:36 -0500 (EST)

branch: master
commit c8dd37b16c574beda900d4ee48ac7b4ab4a2ee56
Author: Theodor Thornhill <theo@thornhill.no>
Commit: Theodor Thornhill <theo@thornhill.no>

    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.
---
 .../progmodes/java-ts-mode-resources/indent.erts   |  44 ++++++
 .../progmodes/java-ts-mode-resources/movement.erts | 154 +++++++++++++++++++++
 test/lisp/progmodes/java-ts-mode-tests.el          |  35 +++++
 .../typescript-ts-mode-resources/indent.erts       |  73 ++++++++++
 test/lisp/progmodes/typescript-ts-mode-tests.el    |  31 +++++
 5 files changed, 337 insertions(+)

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 0000000000..e59d5fed8e
--- /dev/null
+++ b/test/lisp/progmodes/java-ts-mode-resources/indent.erts
@@ -0,0 +1,44 @@
+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;
+}
+=-=-=
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 0000000000..23639b1f5f
--- /dev/null
+++ b/test/lisp/progmodes/java-ts-mode-resources/movement.erts
@@ -0,0 +1,154 @@
+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;
+  }
+|}
+=-=-=
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 0000000000..4fd8fc3019
--- /dev/null
+++ b/test/lisp/progmodes/java-ts-mode-tests.el
@@ -0,0 +1,35 @@
+;;; 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
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 0000000000..146ee76574
--- /dev/null
+++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
@@ -0,0 +1,73 @@
+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>
+  );
+}
+=-=-=
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 0000000000..126f5e3298
--- /dev/null
+++ b/test/lisp/progmodes/typescript-ts-mode-tests.el
@@ -0,0 +1,31 @@
+;;; 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]