summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-06-20 11:35:36 +0200
committerAraq <rumpf_a@web.de>2018-06-20 11:35:36 +0200
commit1be82d96a682338ba53832bcc2772b7865b47b57 (patch)
tree97ed89236b163122ff85eaa601e00a30cda0674e
parent9adfaa7f0704b46f29f3b2f1cdf7d2e83f73ce07 (diff)
downloadNim-1be82d96a682338ba53832bcc2772b7865b47b57.tar.gz
nimpretty: bugfixes; refs #8078
-rw-r--r--compiler/layouter.nim11
-rw-r--r--nimpretty/tester.nim2
-rw-r--r--nimpretty/tests/exhaustive.nim16
-rw-r--r--nimpretty/tests/expected/exhaustive.nim18
4 files changed, 42 insertions, 5 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index 409b656c9..62844db4b 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -74,9 +74,10 @@ template wr(x) =
 template goodCol(col): bool = col in 40..MaxLineLen
 
 const
-  splitters = {tkComma, tkSemicolon, tkParLe, tkParDotLe,
-               tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
-               tkCurlyLe}
+  openPars = {tkParLe, tkParDotLe,
+              tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
+              tkCurlyLe}
+  splitters = openPars + {tkComma, tkSemicolon}
   oprSet = {tkOpr, tkDiv, tkMod, tkShl, tkShr, tkIn, tkNotin, tkIs,
             tkIsnot, tkNot, tkOf, tkAs, tkDotDot, tkAnd, tkOr, tkXor}
 
@@ -169,7 +170,9 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
   of tokKeywordLow..tokKeywordHigh:
     if endsInAlpha(em):
       wr(" ")
-    elif not em.inquote and not endsInWhite(em) and tok.tokType in oprSet:
+    elif not em.inquote and not endsInWhite(em) and
+        em.lastTok notin openPars:
+      #and tok.tokType in oprSet
       wr(" ")
 
     if not em.inquote:
diff --git a/nimpretty/tester.nim b/nimpretty/tester.nim
index 7db245b5f..8798ce06a 100644
--- a/nimpretty/tester.nim
+++ b/nimpretty/tester.nim
@@ -16,7 +16,7 @@ proc test(infile, outfile: string) =
   let produced = dir / nimFile & ".pretty"
   if strip(readFile(expected)) != strip(readFile(produced)):
     echo "FAILURE: files differ: ", nimFile
-    discard execShellCmd("diff -uNdr " & produced & " " & expected)
+    discard execShellCmd("diff -uNdr " & expected & " " & produced)
     failures += 1
   else:
     echo "SUCCESS: files identical: ", nimFile
diff --git a/nimpretty/tests/exhaustive.nim b/nimpretty/tests/exhaustive.nim
index 0ce3bde89..9f2141fbb 100644
--- a/nimpretty/tests/exhaustive.nim
+++ b/nimpretty/tests/exhaustive.nim
@@ -8,6 +8,22 @@ import verylongnamehere,verylongnamehere,verylongnamehereverylongnamehereverylon
 proc `[]=`() = discard "index setter"
 proc `putter=`() = discard cast[pointer](cast[int](buffer) + size)
 
+(not false)
+
+let expr = if true: "true" else: "false"
+
+var body = newNimNode(nnkIfExpr).add(
+  newNimNode(nnkElifBranch).add(
+    infix(newDotExpr(ident("a"), ident("kind")), "==", newDotExpr(ident("b"), ident("kind"))),
+    condition
+  ),
+  newNimNode(nnkElse).add(newStmtList(newNimNode(nnkReturnStmt).add(ident("false"))))
+)
+
+# comment
+
+var x = 1
+
 type
   GeneralTokenizer* = object of RootObj ## comment here
     kind*: TokenClass ## and here
diff --git a/nimpretty/tests/expected/exhaustive.nim b/nimpretty/tests/expected/exhaustive.nim
index dd3ff74e8..95071fce3 100644
--- a/nimpretty/tests/expected/exhaustive.nim
+++ b/nimpretty/tests/expected/exhaustive.nim
@@ -9,6 +9,24 @@ import verylongnamehere, verylongnamehere,
 proc `[]=`() = discard "index setter"
 proc `putter=`() = discard cast[pointer](cast[int](buffer) + size)
 
+(not false)
+
+let expr = if true: "true" else: "false"
+
+var body = newNimNode(nnkIfExpr).add(
+  newNimNode(nnkElifBranch).add(
+    infix(newDotExpr(ident("a"), ident("kind")), "==", newDotExpr(ident("b"),
+        ident("kind"))),
+    condition
+  ),
+  newNimNode(nnkElse).add(newStmtList(newNimNode(nnkReturnStmt).add(ident(
+      "false"))))
+)
+
+# comment
+
+var x = 1
+
 type
   GeneralTokenizer* = object of RootObj ## comment here
     kind*: TokenClass         ## and here