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
|
||||
## allocating a standard Nim 'string'.
|
||||
##
|
||||
## 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
|
||||
## Because this procedure uses stdlib, it is only active when Nim compiles
|
||||
## with the 'c' flag. Otherwise, float types are passed to the generic writeText
|
||||
## procedure.
|
||||
var buffer: array[65, char]
|
||||
discard writeFloatToBuffer(buffer, x)
|
||||
for index in 0 ..< 65:
|
||||
if buffer[index] == '\0':
|
||||
break
|
||||
write s, buffer[index]
|
||||
let bs: cstring = addr buffer
|
||||
write s, bs.toOpenArray(0, bs.len - 1)
|
||||
|
||||
template writeText*(s: OutputStream, str: string) =
|
||||
write s, str
|
||||
|
|
|
|||
|
|
@ -236,3 +236,15 @@ suite "output stream":
|
|||
let resultsAreEqual = nimSeq == memStream.getOutput
|
||||
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