diff --git a/test/13_arraycommon.jl b/test/13_arraycommon.jl index 821aec41..39699466 100644 --- a/test/13_arraycommon.jl +++ b/test/13_arraycommon.jl @@ -428,58 +428,34 @@ end end @testset "fill!()" begin - @testset "non-missing" begin - x = categorical(["a", "b", "c"]) - x2 = copy(x) - @test fill!(x2, "a") === x2 - @test x2 == ["a", "a", "a"] - @test levels(x2) == ["a", "b", "c"] + x = CategoricalArray{Union{String, T}}(["a", "b", "c"]) + x2 = copy(x) + @test fill!(x2, "a") === x2 + @test x2 == ["a", "a", "a"] + @test levels(x2) == ["a", "b", "c"] - @test fill!(x2, x[2]) == ["b", "b", "b"] - @test levels(x2) == ["a", "b", "c"] + @test fill!(x2, x[2]) == ["b", "b", "b"] + @test levels(x2) == ["a", "b", "c"] - x2 = copy(x) - @test_throws MethodError fill!(x2, missing) - @test x2 == x - @test_throws MethodError fill!(x2, 3) - @test x2 == x - - fill!(x2, :c) - @test x2 == ["c", "c", "c"] - @test levels(x2) == ["a", "b", "c"] - - fill!(x2, "0") - @test x2 == ["0", "0", "0"] - @test levels(x2) == ["a", "b", "c", "0"] - end - - @testset "missing" begin - x = categorical(Union{String, Missing}["a", "b", "c"]) - - x2 = copy(x) - @test fill!(x2, "a") === x2 - @test x2 == ["a", "a", "a"] - @test levels(x2) == ["a", "b", "c"] - - @test fill!(x2, x[2]) == ["b", "b", "b"] - @test levels(x2) == ["a", "b", "c"] - - x2 = copy(x) - fill!(x2, "0") - @test x2 == ["0", "0", "0"] - @test levels(x2) == ["a", "b", "c", "0"] + x2 = copy(x) + @test_throws MethodError fill!(x2, 3) + @test x2 == x + if T === Missing x2 = fill!(copy(x), missing) @test all(ismissing, x2) - - x2 = copy(x) - @test_throws MethodError fill!(x2, 3.0) + else + @test_throws MethodError fill!(x2, missing) @test x2 == x - - fill!(x2, Symbol(1)) - @test x2 == ["1", "1", "1"] - @test levels(x2) == ["a", "b", "c", "1"] end + + fill!(x2, :c) + @test x2 == ["c", "c", "c"] + @test levels(x2) == ["a", "b", "c"] + + fill!(x2, "0") + @test x2 == ["0", "0", "0"] + @test levels(x2) == ["a", "b", "c", "0"] end @testset "overflow of reftype is detected and doesn't corrupt data and levels" begin