mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
nimpretty: fixes #9506
This commit is contained in:
@@ -111,15 +111,16 @@ proc softLinebreak(em: var Emitter, lit: string) =
|
||||
for i in 1..em.indentLevel+moreIndent(em): wr(" ")
|
||||
else:
|
||||
# search backwards for a good split position:
|
||||
for a in em.altSplitPos:
|
||||
for a in mitems(em.altSplitPos):
|
||||
if a > em.fixedUntil:
|
||||
var spaces = 0
|
||||
while a+spaces < em.content.len and em.content[a+spaces] == ' ':
|
||||
inc spaces
|
||||
if spaces > 0: delete(em.content, a, a+spaces-1)
|
||||
let ws = "\L" & repeat(' ',em.indentLevel+moreIndent(em))
|
||||
em.col = em.content.len - a
|
||||
let ws = "\L" & repeat(' ', em.indentLevel+moreIndent(em))
|
||||
em.content.insert(ws, a)
|
||||
a = -1
|
||||
break
|
||||
|
||||
proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||
@@ -256,8 +257,8 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||
tok.strongSpaceB == 0 and tok.strongSpaceA > 0
|
||||
|
||||
if not isUnary(tok):
|
||||
wr(" ")
|
||||
rememberSplit(splitBinary)
|
||||
wr(" ")
|
||||
of tkAccent:
|
||||
if not em.inquote and endsInAlpha(em): wr(" ")
|
||||
wr(TokTypeToStr[tok.tokType])
|
||||
|
||||
@@ -17,7 +17,9 @@ else:
|
||||
|
||||
proc test(infile, ext: string) =
|
||||
if execShellCmd("$# -o:$# --backup:off $#" % [nimp, infile.changeFileExt(ext), infile]) != 0:
|
||||
quit("FAILURE")
|
||||
echo "FAILURE: nimpretty cannot prettify ", infile
|
||||
failures += 1
|
||||
return
|
||||
let nimFile = splitFile(infile).name
|
||||
let expected = dir / "expected" / nimFile & ".nim"
|
||||
let produced = dir / nimFile.changeFileExt(ext)
|
||||
|
||||
@@ -7,3 +7,10 @@ foo bar
|
||||
|
||||
proc fun() =
|
||||
echo "ok1"
|
||||
|
||||
proc fun2(a = "fooo" & "bar" & "bar" & "bar" & "bar" & (
|
||||
"bar" & "bar" & "bar") & "bar" & "bar" & "bar" & "bar" & "bar" & "bar" &
|
||||
"bar" & "bar" & "bar"): auto =
|
||||
discard
|
||||
|
||||
fun2()
|
||||
|
||||
@@ -7,3 +7,8 @@ foo bar
|
||||
|
||||
proc fun() =
|
||||
echo "ok1"
|
||||
|
||||
proc fun2(a = "fooo" & "bar" & "bar" & "bar" & "bar" & ("bar" & "bar" & "bar") & "bar" & "bar" & "bar" & "bar" & "bar" & "bar" & "bar" & "bar" & "bar"): auto =
|
||||
discard
|
||||
|
||||
fun2()
|
||||
|
||||
Reference in New Issue
Block a user