nim-json-serialization/tests/utils.nim

15 lines
355 B
Nim
Raw Normal View History

2018-12-17 23:01:06 +00:00
import
strutils
2021-12-15 09:34:49 +00:00
# `dedent` exists in newer nim version
# and doesn't behave the same
proc test_dedent*(s: string): string =
2018-12-17 23:01:06 +00:00
var s = s.strip(leading = false)
2019-08-14 11:34:59 +00:00
var minIndent = high(int)
2018-12-17 23:01:06 +00:00
for l in s.splitLines:
let indent = count(l, ' ')
if indent == 0: continue
if indent < minIndent: minIndent = indent
result = s.unindent(minIndent)