Fixed output for writeText(s,float) and added unit test
This commit is contained in:
parent
2c32157fd3
commit
5e17ffae3a
2 changed files with 16 additions and 6 deletions
|
|
@ -99,15 +99,13 @@ when defined(c):
|
||||||
## than `$` because it is directly written to the stream without
|
## than `$` because it is directly written to the stream without
|
||||||
## allocating a standard Nim 'string'.
|
## allocating a standard Nim 'string'.
|
||||||
##
|
##
|
||||||
## Because this procedure uses stdlib, it is only active when nim compiles
|
## Because this procedure uses stdlib, it is only active when Nim compiles
|
||||||
## with the 'c' flag. Otherwise, float types fall back to the generic writeText
|
## with the 'c' flag. Otherwise, float types are passed to the generic writeText
|
||||||
## procedure.
|
## procedure.
|
||||||
var buffer: array[65, char]
|
var buffer: array[65, char]
|
||||||
discard writeFloatToBuffer(buffer, x)
|
discard writeFloatToBuffer(buffer, x)
|
||||||
for index in 0 ..< 65:
|
let bs: cstring = addr buffer
|
||||||
if buffer[index] == '\0':
|
write s, bs.toOpenArray(0, bs.len - 1)
|
||||||
break
|
|
||||||
write s, buffer[index]
|
|
||||||
|
|
||||||
template writeText*(s: OutputStream, str: string) =
|
template writeText*(s: OutputStream, str: string) =
|
||||||
write s, str
|
write s, str
|
||||||
|
|
|
||||||
|
|
@ -236,3 +236,15 @@ suite "output stream":
|
||||||
let resultsAreEqual = nimSeq == memStream.getOutput
|
let resultsAreEqual = nimSeq == memStream.getOutput
|
||||||
check resultsAreEqual
|
check resultsAreEqual
|
||||||
|
|
||||||
|
test "float output":
|
||||||
|
let basic: float64 = 12345.125
|
||||||
|
let small: float32 = 12345.125
|
||||||
|
let large: float64 = 9.99e+20
|
||||||
|
let tiny: float64 = -2.25e-35
|
||||||
|
|
||||||
|
outputText basic
|
||||||
|
outputText small
|
||||||
|
outputText large
|
||||||
|
outputText tiny
|
||||||
|
|
||||||
|
checkOutputsMatch()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue