mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 03:32:32 +00:00
* fixes #14054 * make tests green again * more tests are green * maybe now
This commit is contained in:
@@ -31,7 +31,11 @@
|
||||
- The file descriptors created for internal bookkeeping by `ioselector_kqueue`
|
||||
and `ioselector_epoll` will no longer be leaked to child processes.
|
||||
|
||||
- `strutils.formatFloat` with `precision = 0` has been restored to the version
|
||||
1 behaviour that produces a trailing dot, e.g. `formatFloat(3.14159, precision = 0)`
|
||||
is now `3.`, not `3`.
|
||||
- `critbits` adds `commonPrefixLen`.
|
||||
|
||||
- `relativePath(rel, abs)` and `relativePath(abs, rel)` used to silently give wrong results
|
||||
(see #13222); instead they now use `getCurrentDir` to resolve those cases,
|
||||
and this can now throw in edge cases where `getCurrentDir` throws.
|
||||
|
||||
@@ -692,11 +692,11 @@ when isMainModule:
|
||||
check &"{-123.456:.3f}", "-123.456"
|
||||
check &"{123.456:1g}", "123.456"
|
||||
check &"{123.456:.1f}", "123.5"
|
||||
check &"{123.456:.0f}", "123"
|
||||
check &"{123.456:.0f}", "123."
|
||||
check &"{123.456:>9.3f}", " 123.456"
|
||||
check &"{123.456:9.3f}", " 123.456"
|
||||
check &"{123.456:>9.4f}", " 123.4560"
|
||||
check &"{123.456:>9.0f}", " 123"
|
||||
check &"{123.456:>9.0f}", " 123."
|
||||
check &"{123.456:<9.4f}", "123.4560 "
|
||||
|
||||
# Float (scientific) tests
|
||||
|
||||
@@ -2430,10 +2430,6 @@ proc formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault,
|
||||
# but nothing else is possible:
|
||||
if buf[i] in {'.', ','}: result[i] = decimalSep
|
||||
else: result[i] = buf[i]
|
||||
since (1, 1):
|
||||
# remove trailing dot, compatible with Python's formatter and JS backend
|
||||
if result[^1] == decimalSep:
|
||||
result.setLen(len(result)-1)
|
||||
when defined(windows):
|
||||
# VS pre 2015 violates the C standard: "The exponent always contains at
|
||||
# least two digits, and only as many more digits as necessary to
|
||||
@@ -2936,7 +2932,8 @@ proc isNilOrWhitespace*(s: string): bool {.noSideEffect, procvar, rtl,
|
||||
when isMainModule:
|
||||
proc nonStaticTests =
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, -1) == "1234.567000"
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, 0) == "1235" # bugs 8242, 12586
|
||||
when not defined(js):
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, 0) == "1235." # bugs 8242, 12586
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, 1) == "1234.6"
|
||||
doAssert formatBiggestFloat(0.00000000001, ffDecimal, 11) == "0.00000000001"
|
||||
doAssert formatBiggestFloat(0.00000000001, ffScientific, 1, ',') in
|
||||
|
||||
@@ -37,7 +37,7 @@ bug12899()
|
||||
|
||||
proc nonStaticTests =
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, -1) == "1234.567000"
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, 0) == "1235" # bugs 8242, 12586
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, 0) == "1235." # bugs 8242, 12586
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, 1) == "1234.6"
|
||||
doAssert formatBiggestFloat(0.00000000001, ffDecimal, 11) == "0.00000000001"
|
||||
doAssert formatBiggestFloat(0.00000000001, ffScientific, 1, ',') in
|
||||
|
||||
@@ -173,3 +173,34 @@ block:
|
||||
y = 234
|
||||
z = true
|
||||
"""
|
||||
|
||||
|
||||
# tests from the very own strformat documentation!
|
||||
|
||||
let msg = "hello"
|
||||
doAssert fmt"{msg}\n" == "hello\\n"
|
||||
|
||||
doAssert &"{msg}\n" == "hello\n"
|
||||
|
||||
doAssert fmt"{msg}{'\n'}" == "hello\n"
|
||||
doAssert fmt("{msg}\n") == "hello\n"
|
||||
doAssert "{msg}\n".fmt == "hello\n"
|
||||
|
||||
doAssert &"""{"abc":>4}""" == " abc"
|
||||
doAssert &"""{"abc":<4}""" == "abc "
|
||||
|
||||
doAssert fmt"{-12345:08}" == "-0012345"
|
||||
doAssert fmt"{-1:3}" == " -1"
|
||||
doAssert fmt"{-1:03}" == "-01"
|
||||
doAssert fmt"{16:#X}" == "0x10"
|
||||
|
||||
doAssert fmt"{123.456}" == "123.456"
|
||||
doAssert fmt"{123.456:>9.3f}" == " 123.456"
|
||||
doAssert fmt"{123.456:9.3f}" == " 123.456"
|
||||
doAssert fmt"{123.456:9.4f}" == " 123.4560"
|
||||
doAssert fmt"{123.456:>9.0f}" == " 123."
|
||||
doAssert fmt"{123.456:<9.4f}" == "123.4560 "
|
||||
|
||||
doAssert fmt"{123.456:e}" == "1.234560e+02"
|
||||
doAssert fmt"{123.456:>13e}" == " 1.234560e+02"
|
||||
doAssert fmt"{123.456:13e}" == " 1.234560e+02"
|
||||
|
||||
Reference in New Issue
Block a user