parent
ac0f5c83ca
commit
ce4383be3b
1 changed files with 5 additions and 3 deletions
|
|
@ -194,9 +194,11 @@ proc `$`*[T](self: Option[T]): string =
|
||||||
## If the option does not have a value, the result will be `None[T]` where `T` is the name of
|
## If the option does not have a value, the result will be `None[T]` where `T` is the name of
|
||||||
## the type contained in the option.
|
## the type contained in the option.
|
||||||
if self.isSome:
|
if self.isSome:
|
||||||
"Some(" & $self.val & ")"
|
result = "Some("
|
||||||
|
result.addQuoted self.val
|
||||||
|
result.add ")"
|
||||||
else:
|
else:
|
||||||
"None[" & name(T) & "]"
|
result = "None[" & name(T) & "]"
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import unittest, sequtils
|
import unittest, sequtils
|
||||||
|
|
@ -247,7 +249,7 @@ when isMainModule:
|
||||||
check(stringNone.get("Correct") == "Correct")
|
check(stringNone.get("Correct") == "Correct")
|
||||||
|
|
||||||
test "$":
|
test "$":
|
||||||
check($(some("Correct")) == "Some(Correct)")
|
check($(some("Correct")) == "Some(\"Correct\")")
|
||||||
check($(stringNone) == "None[string]")
|
check($(stringNone) == "None[string]")
|
||||||
|
|
||||||
test "map with a void result":
|
test "map with a void result":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue