emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/swift-mode d27b851 181/496: Add indentation rules for tern


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode d27b851 181/496: Add indentation rules for ternary operator
Date: Sun, 29 Aug 2021 11:33:32 -0400 (EDT)

branch: elpa/swift-mode
commit d27b85193906e9f76f43eb71fe02651014814c60
Author: ap4y <lod@pisem.net>
Commit: ap4y <lod@pisem.net>

    Add indentation rules for ternary operator
---
 swift-mode.el             |  10 ++++
 test/indentation-tests.el | 113 ++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 119 insertions(+), 4 deletions(-)

diff --git a/swift-mode.el b/swift-mode.el
index a8dca0b..405f868 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -272,6 +272,16 @@
   (pcase (cons kind token)
     (`(:elem . basic) swift-indent-offset)
 
+    (`(:after . ":") 0)
+    (`(:before . ":")
+     (cond
+      ;; Rule for ternary operator in
+      ;; assignment expression.
+      ;; Static indentation relatively to =
+      ((smie-rule-parent-p "=") 2)
+      ;; Rule for the case statement.
+      ((smie-rule-parent-p "case") swift-indent-offset)))
+
     (`(:after . "{")
      (if (smie-rule-parent-p "switch")
          (smie-rule-parent swift-indent-switch-case-offset)))
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index cb810b1..837108f 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -391,12 +391,12 @@ case y:
 (check-indentation indents-case-statements-with-destucturing/1
   "
 switch true {
-case let(x, y):
+case let(x, y) where x < y:
 |foo
 }
 " "
 switch true {
-case let(x, y):
+case let(x, y) where x < y:
     |foo
 }
 ")
@@ -404,12 +404,12 @@ case let(x, y):
 (check-indentation indents-case-statements-with-destucturing/2
   "
 switch true {
-case let .Foo(x):
+case let .Foo(x) where x > 0:
 |foo
 }
 " "
 switch true {
-case let .Foo(x):
+case let .Foo(x) where x > 0:
     |foo
 }
 ")
@@ -931,6 +931,111 @@ let foo = bar >
 "
 )
 
+(check-indentation conditional-operator/1
+                   "
+let a = a
+        |? a +
+          1
+        : a +
+          1
+" "
+let a = a
+        |? a +
+          1
+        : a +
+          1
+")
+
+(check-indentation conditional-operator/2
+                   "
+let a = a
+        ? a +
+          |1
+        : a +
+          1
+" "
+let a = a
+        ? a +
+          |1
+        : a +
+          1
+")
+
+(check-indentation conditional-operator/3
+                   "
+let a = a
+        ? a +
+          1
+        |: a +
+          1
+" "
+let a = a
+        ? a +
+          1
+        |: a +
+          1
+")
+
+(check-indentation conditional-operator/4
+                   "
+let a = a
+        ? a +
+          1
+        : a +
+          |1
+" "
+let a = a
+        ? a +
+          1
+        : a +
+          |1
+")
+
+(check-indentation conditional-operator/5
+                   "
+let a = a ?
+|a : a
+" "
+let a = a ?
+        |a : a
+")
+
+(check-indentation conditional-operator/6
+                   "
+let a = a ?
+      |b :
+        c
+" "
+let a = a ?
+        |b :
+        c
+")
+
+(check-indentation conditional-operator/7
+                   "
+let a = a ?
+        b :
+      |c
+" "
+let a = a ?
+        b :
+        |c
+")
+
+(check-indentation blank-line/1
+                   "
+func foo() {
+    let a = 1
+
+|let b = 1
+}
+" "
+func foo() {
+    let a = 1
+
+    |let b = 1
+}
+")
 
 (provide 'indentation-tests)
 



reply via email to

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