diff options
author | Tomohiro <gpuppur@gmail.com> | 2019-10-28 20:33:44 +0900 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-10-28 12:33:44 +0100 |
commit | a9d7796e1c5719132461b1e2918ada085ed4242f (patch) | |
tree | f7571fd473318f6bcea49223b9d848f1e65bbfd6 /tests | |
parent | 5ed99f8d3fc67d6f02172ab9cbcc67c17eeee5c9 (diff) | |
download | Nim-a9d7796e1c5719132461b1e2918ada085ed4242f.tar.gz |
[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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdlib/tstrformat.nim | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/stdlib/tstrformat.nim b/tests/stdlib/tstrformat.nim index 732283674..a8dad6084 100644 --- a/tests/stdlib/tstrformat.nim +++ b/tests/stdlib/tstrformat.nim @@ -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 + """ |