diff options
| author | Dmitry Gutov | 2022-12-30 23:58:26 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2022-12-31 00:00:21 +0200 |
| commit | 8675f4136c7da7356e5578cf1eabda2f37a597e5 (patch) | |
| tree | f37bbb61f80912e30f2428c20b16c30c8e7ab2bc /test | |
| parent | 4922de626f05f0c26bc732b082c30c5c18a88416 (diff) | |
| download | emacs-8675f4136c7da7356e5578cf1eabda2f37a597e5.tar.gz emacs-8675f4136c7da7356e5578cf1eabda2f37a597e5.zip | |
Add new options for Ruby code indentation
* lisp/progmodes/ruby-mode.el (ruby-block-indent)
(ruby-after-operator-indent, ruby-method-call-indent)
(ruby-parenless-call-arguments-indent): New options (bug#60186).
(ruby-smie-grammar): Specify associativity for "?".
(ruby-smie--indent-to-stmt): Add optional argument.
* test/lisp/progmodes/ruby-mode-resources/ruby.rb: New cases.
* test/lisp/progmodes/ruby-mode-resources/ruby-method-call-indent.rb:
* test/lisp/progmodes/ruby-mode-resources/ruby-block-indent.rb:
* test/lisp/progmodes/ruby-mode-resources/ruby-after-operator-indent.rb:
* test/lisp/progmodes/ruby-mode-resources/
ruby-parenless-call-arguments-indent.rb: New files.
* test/lisp/progmodes/ruby-mode-tests.el: Add indentation tests for new files.
Diffstat (limited to 'test')
6 files changed, 127 insertions, 0 deletions
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby-after-operator-indent.rb b/test/lisp/progmodes/ruby-mode-resources/ruby-after-operator-indent.rb new file mode 100644 index 00000000000..25cd8736f97 --- /dev/null +++ b/test/lisp/progmodes/ruby-mode-resources/ruby-after-operator-indent.rb | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | 4 + | ||
| 2 | 5 + | ||
| 3 | 6 + | ||
| 4 | 7 | ||
| 5 | |||
| 6 | qux = 4 + 5 * | ||
| 7 | 6 + | ||
| 8 | 7 | ||
| 9 | |||
| 10 | foo = obj.bar { |m| tee(m) } + | ||
| 11 | obj.qux { |m| hum(m) } | ||
| 12 | |||
| 13 | foo. | ||
| 14 | bar | ||
| 15 | .baz | ||
| 16 | |||
| 17 | qux = foo.fee ? | ||
| 18 | bar : | ||
| 19 | tee | ||
| 20 | |||
| 21 | # Endless methods. | ||
| 22 | class Bar | ||
| 23 | def foo(abc) = bar + | ||
| 24 | baz | ||
| 25 | end | ||
| 26 | |||
| 27 | # Local Variables: | ||
| 28 | # ruby-after-operator-indent: nil | ||
| 29 | # End: | ||
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby-block-indent.rb b/test/lisp/progmodes/ruby-mode-resources/ruby-block-indent.rb new file mode 100644 index 00000000000..32882814b7e --- /dev/null +++ b/test/lisp/progmodes/ruby-mode-resources/ruby-block-indent.rb | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | foo | ||
| 2 | .asdasd | ||
| 3 | .proc do |**args| | ||
| 4 | p(**args) | ||
| 5 | end | ||
| 6 | |||
| 7 | foo | ||
| 8 | .asdasd | ||
| 9 | .proc { |**args| | ||
| 10 | p(**args) | ||
| 11 | } | ||
| 12 | |||
| 13 | bar.foo do | ||
| 14 | bar | ||
| 15 | end | ||
| 16 | |||
| 17 | bar.foo(tee) do | ||
| 18 | bar | ||
| 19 | end | ||
| 20 | |||
| 21 | bar.foo(tee) { | ||
| 22 | bar | ||
| 23 | } | ||
| 24 | |||
| 25 | x.foo do | ||
| 26 | foo | ||
| 27 | end.bar do | ||
| 28 | bar | ||
| 29 | end | ||
| 30 | |||
| 31 | # Local Variables: | ||
| 32 | # ruby-block-indent: nil | ||
| 33 | # End: | ||
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby-method-call-indent.rb b/test/lisp/progmodes/ruby-mode-resources/ruby-method-call-indent.rb new file mode 100644 index 00000000000..1a8285ee919 --- /dev/null +++ b/test/lisp/progmodes/ruby-mode-resources/ruby-method-call-indent.rb | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | foo2 = | ||
| 2 | subject. | ||
| 3 | update( | ||
| 4 | 2 | ||
| 5 | ) | ||
| 6 | |||
| 7 | foo3 = | ||
| 8 | subject | ||
| 9 | .update( | ||
| 10 | 2 | ||
| 11 | ) | ||
| 12 | |||
| 13 | # Local Variables: | ||
| 14 | # ruby-method-call-indent: nil | ||
| 15 | # End: | ||
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby-parenless-call-arguments-indent.rb b/test/lisp/progmodes/ruby-mode-resources/ruby-parenless-call-arguments-indent.rb new file mode 100644 index 00000000000..58e08810c4c --- /dev/null +++ b/test/lisp/progmodes/ruby-mode-resources/ruby-parenless-call-arguments-indent.rb | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | method arg1, | ||
| 2 | method2 arg2, | ||
| 3 | arg3, [ | ||
| 4 | arg4, | ||
| 5 | arg5 | ||
| 6 | ] | ||
| 7 | |||
| 8 | zzz = method (a + b), | ||
| 9 | c, :d => :e, | ||
| 10 | f: g | ||
| 11 | |||
| 12 | return render json: { | ||
| 13 | errors: { base: [message] }, | ||
| 14 | copying: copying | ||
| 15 | }, | ||
| 16 | status: 400 | ||
| 17 | |||
| 18 | foo(a, | ||
| 19 | b) | ||
| 20 | |||
| 21 | # Local Variables: | ||
| 22 | # ruby-parenless-call-arguments-indent: nil | ||
| 23 | # End: | ||
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby.rb b/test/lisp/progmodes/ruby-mode-resources/ruby.rb index 6a69d9db78a..bfae948b259 100644 --- a/test/lisp/progmodes/ruby-mode-resources/ruby.rb +++ b/test/lisp/progmodes/ruby-mode-resources/ruby.rb | |||
| @@ -226,6 +226,7 @@ desc "foo foo" \ | |||
| 226 | 226 | ||
| 227 | foo. | 227 | foo. |
| 228 | bar | 228 | bar |
| 229 | .baz | ||
| 229 | 230 | ||
| 230 | # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206 | 231 | # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206 |
| 231 | foo # comment intended to confuse the tokenizer | 232 | foo # comment intended to confuse the tokenizer |
| @@ -380,6 +381,18 @@ foo = [1, 2, 3].map do |i| | |||
| 380 | i + 1 | 381 | i + 1 |
| 381 | end | 382 | end |
| 382 | 383 | ||
| 384 | m1 = foo | ||
| 385 | .asdasd | ||
| 386 | .proc do |**args| | ||
| 387 | p(**args) | ||
| 388 | end | ||
| 389 | |||
| 390 | m2 = foo | ||
| 391 | .asdasd | ||
| 392 | .proc { |**args| | ||
| 393 | p(**args) | ||
| 394 | } | ||
| 395 | |||
| 383 | bar.foo do | 396 | bar.foo do |
| 384 | bar | 397 | bar |
| 385 | end | 398 | end |
| @@ -398,6 +411,12 @@ bar 1 do | |||
| 398 | end | 411 | end |
| 399 | end | 412 | end |
| 400 | 413 | ||
| 414 | x.foo do | ||
| 415 | foo | ||
| 416 | end.bar do | ||
| 417 | bar | ||
| 418 | end | ||
| 419 | |||
| 401 | foo | | 420 | foo | |
| 402 | bar | 421 | bar |
| 403 | 422 | ||
| @@ -540,5 +559,9 @@ class Bar | |||
| 540 | end | 559 | end |
| 541 | 560 | ||
| 542 | # Local Variables: | 561 | # Local Variables: |
| 562 | # ruby-after-operator-indent: t | ||
| 563 | # ruby-block-indent: t | ||
| 564 | # ruby-method-call-indent: t | ||
| 543 | # ruby-method-params-indent: t | 565 | # ruby-method-params-indent: t |
| 566 | # ruby-parenless-call-arguments-indent: t | ||
| 544 | # End: | 567 | # End: |
diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el index 560f780285a..5c81cc31cc1 100644 --- a/test/lisp/progmodes/ruby-mode-tests.el +++ b/test/lisp/progmodes/ruby-mode-tests.el | |||
| @@ -956,7 +956,11 @@ VALUES-PLIST is a list with alternating index and value elements." | |||
| 956 | (kill-buffer buf))))) | 956 | (kill-buffer buf))))) |
| 957 | 957 | ||
| 958 | (ruby-deftest-indent "ruby.rb") | 958 | (ruby-deftest-indent "ruby.rb") |
| 959 | (ruby-deftest-indent "ruby-after-operator-indent.rb") | ||
| 960 | (ruby-deftest-indent "ruby-block-indent.rb") | ||
| 961 | (ruby-deftest-indent "ruby-method-call-indent.rb") | ||
| 959 | (ruby-deftest-indent "ruby-method-params-indent.rb") | 962 | (ruby-deftest-indent "ruby-method-params-indent.rb") |
| 963 | (ruby-deftest-indent "ruby-parenless-call-arguments-indent.rb") | ||
| 960 | 964 | ||
| 961 | (ert-deftest ruby--test-chained-indentation () | 965 | (ert-deftest ruby--test-chained-indentation () |
| 962 | (with-temp-buffer | 966 | (with-temp-buffer |