[feature]strformat: add 2 'fmt' macros that use specified characters instead of '{}' (#11748)
* [feature]strformat: add 2 'fmt' macros that use specified chars instead of '{}'
* strformat: revert documentation comments of `&` and 'fmt'
* strformat: removed single open/close char variant of fmt
This commit is contained in:
parent
5ed99f8d3f
commit
a9d7796e1c
2 changed files with 57 additions and 14 deletions
|
|
@ -133,3 +133,35 @@ doAssert fmt"{nat:3d}" == " 64"
|
|||
doAssert fmt"{nat:3o}" == "100"
|
||||
doAssert fmt"{nat:3x}" == " 40"
|
||||
doAssert fmt"{nat:3X}" == " 40"
|
||||
|
||||
block:
|
||||
template fmt(pattern: string; openCloseChar: char): untyped =
|
||||
fmt(pattern, openCloseChar, openCloseChar)
|
||||
|
||||
let
|
||||
testInt = 123
|
||||
testStr = "foobar"
|
||||
testFlt = 3.141592
|
||||
doAssert ">><<".fmt('<', '>') == "><"
|
||||
doAssert " >> << ".fmt('<', '>') == " > < "
|
||||
doAssert "<<>>".fmt('<', '>') == "<>"
|
||||
doAssert " << >> ".fmt('<', '>') == " < > "
|
||||
doAssert "''".fmt('\'') == "'"
|
||||
doAssert "''''".fmt('\'') == "''"
|
||||
doAssert "'' ''".fmt('\'') == "' '"
|
||||
doAssert "<testInt>".fmt('<', '>') == "123"
|
||||
doAssert "<testInt>".fmt('<', '>') == "123"
|
||||
doAssert "'testFlt:1.2f'".fmt('\'') == "3.14"
|
||||
doAssert "<testInt><testStr>".fmt('<', '>') == "123foobar"
|
||||
doAssert """ ""{"123+123"}"" """.fmt('"') == " \"{246}\" "
|
||||
doAssert "(((testFlt:1.2f)))((111))".fmt('(', ')') == "(3.14)(111)"
|
||||
doAssert """(()"foo" & "bar"())""".fmt(')', '(') == "(foobar)"
|
||||
doAssert "{}abc`testStr' `testFlt:1.2f' `1+1' ``".fmt('`', '\'') == "{}abcfoobar 3.14 2 `"
|
||||
doAssert """x = '"foo" & "bar"'
|
||||
y = '123 + 111'
|
||||
z = '3 in {2..7}'
|
||||
""".fmt('\'') ==
|
||||
"""x = foobar
|
||||
y = 234
|
||||
z = true
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue