Skip to content

Commit 0ec87f8

Browse files
stevengjgiordano
authored andcommitted
test replace(io, ...) API
1 parent 1aff869 commit 0ec87f8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/strings/util.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,24 @@ end
333333
# Issue 36953
334334
@test replace("abc", "" => "_", count=1) == "_abc"
335335

336+
# tests for io::IO API (in addition to internals exercised above):
337+
let buf = IOBuffer()
338+
replace(buf, "aaa", 'a' => 'z', count=0)
339+
replace(buf, "aaa", 'a' => 'z', count=1)
340+
replace(buf, "bbb", 'a' => 'z')
341+
replace(buf, "aaa", 'a' => 'z')
342+
@test String(take!(buf)) == "aaazaabbbzzz"
343+
end
344+
let tempfile = tempname()
345+
open(tempfile, "w") do f
346+
replace(f, "aaa", 'a' => 'z', count=0)
347+
replace(f, "aaa", 'a' => 'z', count=1)
348+
replace(f, "bbb", 'a' => 'z')
349+
replace(f, "aaa", 'a' => 'z')
350+
print(f, "\n")
351+
end
352+
@test read(tempfile, String) == "aaazaabbbzzz\n"
353+
end
336354
end
337355

338356
@testset "replace many" begin

0 commit comments

Comments
 (0)