add overload add(a: var string, b: openArray[char]) (#15951)

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
Timothee Cour
2021-03-01 07:51:12 -08:00
committed by GitHub
parent dd6b0f81ef
commit 0cb02fbbee
5 changed files with 152 additions and 122 deletions

View File

@@ -12,16 +12,16 @@ proc set_all[T](s: var openArray[T]; val: T) =
for i in 0..<s.len:
s[i] = val
proc test() =
var a0 = "hello_world"
var a1 = [1,2,3,4,5,6,7,8,9]
var a2 = @[1,2,3,4,5,6,7,8,9]
a0.set_all('i')
a1.set_all(4)
a2.set_all(4)
doAssert a0 == "iiiiiiiiiii"
doAssert a1 == [4,4,4,4,4,4,4,4,4]
doAssert a2 == @[4,4,4,4,4,4,4,4,4]
proc main() =
var a0 = "hello_world"
var a1 = [1,2,3,4,5,6,7,8,9]
var a2 = @[1,2,3,4,5,6,7,8,9]
a0.set_all('i')
a1.set_all(4)
a2.set_all(4)
doAssert a0 == "iiiiiiiiiii"
doAssert a1 == [4,4,4,4,4,4,4,4,4]
doAssert a2 == @[4,4,4,4,4,4,4,4,4]
const constval0 = "hello".map(proc(x: char): char = x)
const constval1 = [1,2,3,4].map(proc(x: int): int = x)
@@ -29,6 +29,5 @@ const constval1 = [1,2,3,4].map(proc(x: int): int = x)
doAssert("hello".map(proc(x: char): char = x) == constval0)
doAssert([1,2,3,4].map(proc(x: int): int = x) == constval1)
test()
static:
test()
static: main()
main()