From 0ec87f8055e45bf3b8f68f613e9bae0f071490ef Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Fri, 10 Feb 2023 19:14:38 -0500 Subject: [PATCH] test replace(io, ...) API --- test/strings/util.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/strings/util.jl b/test/strings/util.jl index 5218310c5c1c7..fd237594f4ad5 100644 --- a/test/strings/util.jl +++ b/test/strings/util.jl @@ -333,6 +333,24 @@ end # Issue 36953 @test replace("abc", "" => "_", count=1) == "_abc" + # tests for io::IO API (in addition to internals exercised above): + let buf = IOBuffer() + replace(buf, "aaa", 'a' => 'z', count=0) + replace(buf, "aaa", 'a' => 'z', count=1) + replace(buf, "bbb", 'a' => 'z') + replace(buf, "aaa", 'a' => 'z') + @test String(take!(buf)) == "aaazaabbbzzz" + end + let tempfile = tempname() + open(tempfile, "w") do f + replace(f, "aaa", 'a' => 'z', count=0) + replace(f, "aaa", 'a' => 'z', count=1) + replace(f, "bbb", 'a' => 'z') + replace(f, "aaa", 'a' => 'z') + print(f, "\n") + end + @test read(tempfile, String) == "aaazaabbbzzz\n" + end end @testset "replace many" begin