diff options
author | skilchen <skilchen@users.noreply.github.com> | 2018-06-05 00:26:16 +0200 |
---|---|---|
committer | Varriount <Varriount@users.noreply.github.com> | 2018-06-04 18:26:16 -0400 |
commit | fd102f39bb8c969d33015654422ff4541f211b51 (patch) | |
tree | d9993c8e87e943e50193d07f1340eb239249f4c0 /tests/stdlib/tstrformat.nim | |
parent | a3e5242d31fa2ac86072534a7528468c7a6f257d (diff) | |
download | Nim-fd102f39bb8c969d33015654422ff4541f211b51.tar.gz |
Fix strformat precision handling for strings (#7941)
* fix strformat precision handling for strings * add some limited unicode awareness to the precision handling for strings * improvement suggested by Varriount: use setLen and runeOffset instead of runeSubstr
Diffstat (limited to 'tests/stdlib/tstrformat.nim')
-rw-r--r-- | tests/stdlib/tstrformat.nim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/stdlib/tstrformat.nim b/tests/stdlib/tstrformat.nim index b4cbd41e0..919158ac4 100644 --- a/tests/stdlib/tstrformat.nim +++ b/tests/stdlib/tstrformat.nim @@ -12,6 +12,32 @@ var o: Obj doAssert fmt"{o}" == "foobar" doAssert fmt"{o:10}" == "foobar " +# see issue #7933 +var str = "abc" +doAssert fmt">7.1 :: {str:>7.1}" == ">7.1 :: a" +doAssert fmt">7.2 :: {str:>7.2}" == ">7.2 :: ab" +doAssert fmt">7.3 :: {str:>7.3}" == ">7.3 :: abc" +doAssert fmt">7.9 :: {str:>7.9}" == ">7.9 :: abc" +doAssert fmt">7.0 :: {str:>7.0}" == ">7.0 :: " +doAssert fmt" 7.1 :: {str:7.1}" == " 7.1 :: a " +doAssert fmt" 7.2 :: {str:7.2}" == " 7.2 :: ab " +doAssert fmt" 7.3 :: {str:7.3}" == " 7.3 :: abc " +doAssert fmt" 7.9 :: {str:7.9}" == " 7.9 :: abc " +doAssert fmt" 7.0 :: {str:7.0}" == " 7.0 :: " +doAssert fmt"^7.1 :: {str:^7.1}" == "^7.1 :: a " +doAssert fmt"^7.2 :: {str:^7.2}" == "^7.2 :: ab " +doAssert fmt"^7.3 :: {str:^7.3}" == "^7.3 :: abc " +doAssert fmt"^7.9 :: {str:^7.9}" == "^7.9 :: abc " +doAssert fmt"^7.0 :: {str:^7.0}" == "^7.0 :: " +str = "äöüe\u0309\u0319o\u0307\u0359" +doAssert fmt"^7.1 :: {str:^7.1}" == "^7.1 :: ä " +doAssert fmt"^7.2 :: {str:^7.2}" == "^7.2 :: äö " +doAssert fmt"^7.3 :: {str:^7.3}" == "^7.3 :: äöü " +doAssert fmt"^7.0 :: {str:^7.0}" == "^7.0 :: " +# this is actually wrong, but the unicode module has no support for graphemes +doAssert fmt"^7.4 :: {str:^7.4}" == "^7.4 :: äöüe " +doAssert fmt"^7.9 :: {str:^7.9}" == "^7.9 :: äöüe\u0309\u0319o\u0307\u0359" + # see issue #7932 doAssert fmt"{15:08}" == "00000015" # int, works doAssert fmt"{1.5:08}" == "000001.5" # float, works |