diff --git a/src/saving_files.jl b/src/saving_files.jl index 8e1179c3..036d5500 100644 --- a/src/saving_files.jl +++ b/src/saving_files.jl @@ -137,10 +137,10 @@ function append_prefix_suffix(name, prefix, suffix) return prefix*'.'*suffix end end - if prefix != "" + if prefix != "" && !startswith(name, prefix) name = prefix*'_'*name end - if suffix != "" + if suffix != "" && !endswith(name, suffix) name *= '.'*suffix end return name diff --git a/test/savefiles_tests.jl b/test/savefiles_tests.jl index d3c4d649..4b0a5ec6 100644 --- a/test/savefiles_tests.jl +++ b/test/savefiles_tests.jl @@ -315,14 +315,18 @@ end x y end + simulation = Dummy(1,2) - DrWatson.default_prefix(d::Dummy) = "Prefix_" + DrWatson.default_prefix(d::Dummy) = "Prefix" - sim, path = produce_or_load(f, simulation, "") - @test path == savename(simulation, "jld2") - - rm(path) - DrWatson.default_prefix(ntuple::NamedTuple) = "" + _, file = produce_or_load(f, simulation, path) + @test basename(file) == "Prefix_x=1_y=2.jld2" + + filename = x -> savename(x; connector = " ") + _, file = produce_or_load(f, simulation, path; filename) + @test basename(file) == "Prefix x=1 y=2.jld2" + + rm(path; recursive = true, force = true) end