nim-json-serialization/tests/utils.nim

23 lines
679 B
Nim
Raw Normal View History

2023-12-13 09:07:57 +00:00
# json-serialization
# Copyright (c) 2019-2023 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
import
strutils
2018-12-17 23:01:06 +00:00
# `dedent` exists in newer Nim version and doesn't behave the same
func test_dedent*(s: string): string =
var
s = s.strip(leading = false)
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
s.unindent(minIndent)