Fix string rendering
This commit is contained in:
parent
cf9e13dd02
commit
44adb7176d
1 changed files with 10 additions and 3 deletions
|
|
@ -34,9 +34,6 @@ proc `$`*[T](ar: openarray[T]): string =
|
||||||
|
|
||||||
proc `$`*[T](some:typedesc[T]): string = name(T)
|
proc `$`*[T](some:typedesc[T]): string = name(T)
|
||||||
|
|
||||||
proc `$`*(s: ref object): string =
|
|
||||||
result = ($type(s)).replace(":ObjectType", "") & $s[]
|
|
||||||
|
|
||||||
template tupleObjToStr(obj): string {.dirty.} =
|
template tupleObjToStr(obj): string {.dirty.} =
|
||||||
var res = $type(obj)
|
var res = $type(obj)
|
||||||
template helper(n) {.gensym.} =
|
template helper(n) {.gensym.} =
|
||||||
|
|
@ -53,6 +50,8 @@ template tupleObjToStr(obj): string {.dirty.} =
|
||||||
else:
|
else:
|
||||||
res.add($type(value))
|
res.add($type(value))
|
||||||
helper(value)
|
helper(value)
|
||||||
|
elif (value is string):
|
||||||
|
res.add("\"" & $value & "\"")
|
||||||
else:
|
else:
|
||||||
res.add($value)
|
res.add($value)
|
||||||
firstElement = false
|
firstElement = false
|
||||||
|
|
@ -60,6 +59,9 @@ template tupleObjToStr(obj): string {.dirty.} =
|
||||||
helper(obj)
|
helper(obj)
|
||||||
res
|
res
|
||||||
|
|
||||||
|
proc `$`*(s: ref object): string =
|
||||||
|
result = "ref " & tupleObjToStr(s[]).replace(":ObjectType", "")
|
||||||
|
|
||||||
proc objToStr*[T: object](obj: var T): string =
|
proc objToStr*[T: object](obj: var T): string =
|
||||||
tupleObjToStr(obj)
|
tupleObjToStr(obj)
|
||||||
|
|
||||||
|
|
@ -79,6 +81,10 @@ macro toString*(obj: typed): untyped =
|
||||||
template toStrAst(obj): string =
|
template toStrAst(obj): string =
|
||||||
einheit.objToStr(obj)
|
einheit.objToStr(obj)
|
||||||
result = getAst(toStrAst(obj))
|
result = getAst(toStrAst(obj))
|
||||||
|
of ntyString:
|
||||||
|
template toStrAst(obj): string =
|
||||||
|
"\"" & $(obj) & "\""
|
||||||
|
result = getAst(toStrAst(obj))
|
||||||
else:
|
else:
|
||||||
template toStrAst(obj): string =
|
template toStrAst(obj): string =
|
||||||
$(obj)
|
$(obj)
|
||||||
|
|
@ -594,6 +600,7 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
echo " Where:"
|
echo " Where:"
|
||||||
for k, v in vals.pairs:
|
for k, v in vals.pairs:
|
||||||
echo " ", k, " -> ", v
|
echo " ", k, " -> ", v
|
||||||
|
|
||||||
echo " Location: $1; line $2".format(filename, line)
|
echo " Location: $1; line $2".format(filename, line)
|
||||||
self.lastTestFailed = true
|
self.lastTestFailed = true
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue