diff options
| author | Wilhelm H Kirschbaum | 2023-03-12 17:10:43 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2023-03-12 17:41:44 +0200 |
| commit | d965d030879d9ca4ef5098cb4e2e7c56128b904b (patch) | |
| tree | 8ab985a3946eac5e52417f7bb32b012db3db0af5 /test | |
| parent | 802e64922bcee40c8362b9627aa33a0de0c068d7 (diff) | |
| download | emacs-d965d030879d9ca4ef5098cb4e2e7c56128b904b.tar.gz emacs-d965d030879d9ca4ef5098cb4e2e7c56128b904b.zip | |
Add elixir-ts-mode (Bug#61996)
* etc/NEWS: Mention the new mode.
* lisp/progmodes/elixir-ts-mode.el: New file.
* test/lisp/progmodes/elixir-ts-mode-tests.el: New file.
* test/lisp/progmodes/elixir-ts-mode-resources/indent.erts: New file.
* admin/notes/tree-sitter/build-module/batch.sh:
* admin/notes/tree-sitter/build-module/build.sh: Add Elixir support.
* lisp/progmodes/eglot.el (eglot-server-programs): Add elixir-ts-mode.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/progmodes/elixir-ts-mode-resources/indent.erts | 308 | ||||
| -rw-r--r-- | test/lisp/progmodes/elixir-ts-mode-tests.el | 31 |
2 files changed, 339 insertions, 0 deletions
diff --git a/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts b/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts new file mode 100644 index 00000000000..748455cc3f2 --- /dev/null +++ b/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts | |||
| @@ -0,0 +1,308 @@ | |||
| 1 | Code: | ||
| 2 | (lambda () | ||
| 3 | (setq indent-tabs-mode nil) | ||
| 4 | (elixir-ts-mode) | ||
| 5 | (indent-region (point-min) (point-max))) | ||
| 6 | |||
| 7 | Point-Char: $ | ||
| 8 | |||
| 9 | Name: Basic modules | ||
| 10 | |||
| 11 | =-= | ||
| 12 | defmodule Foobar do | ||
| 13 | def bar() do | ||
| 14 | "one" | ||
| 15 | end | ||
| 16 | end | ||
| 17 | =-= | ||
| 18 | defmodule Foobar do | ||
| 19 | def bar() do | ||
| 20 | "one" | ||
| 21 | end | ||
| 22 | end | ||
| 23 | =-=-= | ||
| 24 | |||
| 25 | Name: Map | ||
| 26 | |||
| 27 | =-= | ||
| 28 | map = %{ | ||
| 29 | "a" => 1, | ||
| 30 | "b" => 2 | ||
| 31 | } | ||
| 32 | =-=-= | ||
| 33 | |||
| 34 | Name: Map in function def | ||
| 35 | |||
| 36 | =-= | ||
| 37 | def foobar() do | ||
| 38 | %{ | ||
| 39 | one: "one", | ||
| 40 | two: "two", | ||
| 41 | three: "three", | ||
| 42 | four: "four" | ||
| 43 | } | ||
| 44 | end | ||
| 45 | =-=-= | ||
| 46 | |||
| 47 | Name: Map in tuple | ||
| 48 | |||
| 49 | =-= | ||
| 50 | def foo() do | ||
| 51 | {:ok, | ||
| 52 | %{ | ||
| 53 | state | ||
| 54 | | extra_arguments: extra_arguments, | ||
| 55 | max_children: max_children, | ||
| 56 | max_restarts: max_restarts, | ||
| 57 | max_seconds: max_seconds, | ||
| 58 | strategy: strategy | ||
| 59 | }} | ||
| 60 | end | ||
| 61 | =-=-= | ||
| 62 | |||
| 63 | Name: Nested maps | ||
| 64 | |||
| 65 | =-= | ||
| 66 | %{ | ||
| 67 | foo: "bar", | ||
| 68 | bar: %{ | ||
| 69 | foo: "bar" | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | def foo() do | ||
| 74 | %{ | ||
| 75 | foo: "bar", | ||
| 76 | bar: %{ | ||
| 77 | foo: "bar" | ||
| 78 | } | ||
| 79 | } | ||
| 80 | end | ||
| 81 | =-=-= | ||
| 82 | |||
| 83 | Name: Block assignments | ||
| 84 | |||
| 85 | =-= | ||
| 86 | foo = | ||
| 87 | if true do | ||
| 88 | "yes" | ||
| 89 | else | ||
| 90 | "no" | ||
| 91 | end | ||
| 92 | =-=-= | ||
| 93 | |||
| 94 | Name: Function rescue | ||
| 95 | |||
| 96 | =-= | ||
| 97 | def foo do | ||
| 98 | "bar" | ||
| 99 | rescue | ||
| 100 | e -> | ||
| 101 | "bar" | ||
| 102 | end | ||
| 103 | =-=-= | ||
| 104 | |||
| 105 | Name: With statement | ||
| 106 | =-= | ||
| 107 | with one <- one(), | ||
| 108 | two <- two(), | ||
| 109 | {:ok, value} <- get_value(one, two) do | ||
| 110 | {:ok, value} | ||
| 111 | else | ||
| 112 | {:error, %{"Message" => message}} -> | ||
| 113 | {:error, message} | ||
| 114 | end | ||
| 115 | =-=-= | ||
| 116 | |||
| 117 | Name: Pipe statements with fn | ||
| 118 | |||
| 119 | =-= | ||
| 120 | [1, 2] | ||
| 121 | |> Enum.map(fn num -> | ||
| 122 | num + 1 | ||
| 123 | end) | ||
| 124 | =-=-= | ||
| 125 | |||
| 126 | Name: Pipe statements stab clases | ||
| 127 | |||
| 128 | =-= | ||
| 129 | [1, 2] | ||
| 130 | |> Enum.map(fn | ||
| 131 | x when x < 10 -> x * 2 | ||
| 132 | x -> x * 3 | ||
| 133 | end) | ||
| 134 | =-=-= | ||
| 135 | |||
| 136 | Name: Pipe statements params | ||
| 137 | |||
| 138 | =-= | ||
| 139 | [1, 2] | ||
| 140 | |> foobar( | ||
| 141 | :one, | ||
| 142 | :two, | ||
| 143 | :three, | ||
| 144 | :four | ||
| 145 | ) | ||
| 146 | =-=-= | ||
| 147 | |||
| 148 | Name: Parameter maps | ||
| 149 | |||
| 150 | =-= | ||
| 151 | def something(%{ | ||
| 152 | one: :one, | ||
| 153 | two: :two | ||
| 154 | }) do | ||
| 155 | {:ok, "done"} | ||
| 156 | end | ||
| 157 | =-=-= | ||
| 158 | |||
| 159 | Name: Binary operator in else block | ||
| 160 | |||
| 161 | =-= | ||
| 162 | defp foobar() do | ||
| 163 | if false do | ||
| 164 | :foo | ||
| 165 | else | ||
| 166 | :bar |> foo | ||
| 167 | end | ||
| 168 | end | ||
| 169 | =-=-= | ||
| 170 | |||
| 171 | Name: Tuple indentation | ||
| 172 | |||
| 173 | =-= | ||
| 174 | tuple = { | ||
| 175 | :one, | ||
| 176 | :two | ||
| 177 | } | ||
| 178 | |||
| 179 | { | ||
| 180 | :one, | ||
| 181 | :two | ||
| 182 | } | ||
| 183 | =-=-= | ||
| 184 | |||
| 185 | Name: Spec and method | ||
| 186 | |||
| 187 | =-= | ||
| 188 | @spec foobar( | ||
| 189 | t, | ||
| 190 | acc, | ||
| 191 | (one, something -> :bar | far), | ||
| 192 | (two -> :bar | far) | ||
| 193 | ) :: any() | ||
| 194 | when chunk: any | ||
| 195 | def foobar(enumerable, acc, chunk_fun, after_fun) do | ||
| 196 | {_, {res, acc}} = | ||
| 197 | case after_fun.(acc) do | ||
| 198 | {:one, "one"} -> | ||
| 199 | "one" | ||
| 200 | |||
| 201 | {:two, "two"} -> | ||
| 202 | "two" | ||
| 203 | end | ||
| 204 | end | ||
| 205 | =-=-= | ||
| 206 | |||
| 207 | Name: Spec with multi-line result | ||
| 208 | |||
| 209 | =-= | ||
| 210 | @type result :: | ||
| 211 | {:done, term} | ||
| 212 | | {:two} | ||
| 213 | | {:one} | ||
| 214 | |||
| 215 | @type result :: | ||
| 216 | { | ||
| 217 | :done, | ||
| 218 | term | ||
| 219 | } | ||
| 220 | | {:two} | ||
| 221 | | {:one} | ||
| 222 | |||
| 223 | @type boo_bar :: | ||
| 224 | (foo :: pos_integer, bar :: pos_integer -> any()) | ||
| 225 | |||
| 226 | @spec foo_bar( | ||
| 227 | t, | ||
| 228 | (foo -> any), | ||
| 229 | (() -> any) | (foo, foo -> boolean) | module() | ||
| 230 | ) :: any | ||
| 231 | when foo: any | ||
| 232 | def foo(one, fun, other) | ||
| 233 | =-=-= | ||
| 234 | |||
| 235 | Name: String concatenation in call | ||
| 236 | |||
| 237 | =-= | ||
| 238 | IO.warn( | ||
| 239 | "one" <> | ||
| 240 | "two" <> | ||
| 241 | "bar" | ||
| 242 | ) | ||
| 243 | |||
| 244 | IO.warn( | ||
| 245 | "foo" <> | ||
| 246 | "bar" | ||
| 247 | ) | ||
| 248 | =-=-= | ||
| 249 | |||
| 250 | Name: Incomplete tuple | ||
| 251 | |||
| 252 | =-= | ||
| 253 | map = { | ||
| 254 | :foo | ||
| 255 | |||
| 256 | =-= | ||
| 257 | map = { | ||
| 258 | :foo | ||
| 259 | |||
| 260 | =-=-= | ||
| 261 | |||
| 262 | Name: Incomplete map | ||
| 263 | |||
| 264 | =-= | ||
| 265 | map = %{ | ||
| 266 | "a" => "a", | ||
| 267 | =-=-= | ||
| 268 | |||
| 269 | Name: Incomplete list | ||
| 270 | |||
| 271 | =-= | ||
| 272 | map = [ | ||
| 273 | :foo | ||
| 274 | |||
| 275 | =-= | ||
| 276 | map = [ | ||
| 277 | :foo | ||
| 278 | |||
| 279 | =-=-= | ||
| 280 | |||
| 281 | Name: String concatenation | ||
| 282 | |||
| 283 | =-= | ||
| 284 | "one" <> | ||
| 285 | "two" <> | ||
| 286 | "three" <> | ||
| 287 | "four" | ||
| 288 | =-=-= | ||
| 289 | |||
| 290 | Name: Tuple with same line first node | ||
| 291 | |||
| 292 | =-= | ||
| 293 | {:one, | ||
| 294 | :two} | ||
| 295 | |||
| 296 | {:ok, | ||
| 297 | fn one -> | ||
| 298 | one | ||
| 299 | |> String.upcase(one) | ||
| 300 | end} | ||
| 301 | =-=-= | ||
| 302 | |||
| 303 | Name: Long tuple | ||
| 304 | |||
| 305 | =-= | ||
| 306 | {"January", "February", "March", "April", "May", "June", "July", "August", "September", | ||
| 307 | "October", "November", "December"} | ||
| 308 | =-=-= | ||
diff --git a/test/lisp/progmodes/elixir-ts-mode-tests.el b/test/lisp/progmodes/elixir-ts-mode-tests.el new file mode 100644 index 00000000000..8e546ad5cc6 --- /dev/null +++ b/test/lisp/progmodes/elixir-ts-mode-tests.el | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | ;;; c-ts-mode-tests.el --- Tests for Tree-sitter-based C 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 elixir-ts-mode-test-indentation () | ||
| 27 | (skip-unless (and (treesit-ready-p 'elixir) (treesit-ready-p 'heex))) | ||
| 28 | (ert-test-erts-file (ert-resource-file "indent.erts"))) | ||
| 29 | |||
| 30 | (provide 'elixir-ts-mode-tests) | ||
| 31 | ;;; elixir-ts-mode-tests.el ends here | ||