Skip to content

Commit

Permalink
tests: keep some vectors alive for references
Browse files Browse the repository at this point in the history
  • Loading branch information
benlorenz authored and barche committed Dec 9, 2024
1 parent 4e36806 commit a4eec02
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions test/stdlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,21 @@ end
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]

svec_ref = CxxRef.(StdString["a", "b", "c"])
vec = StdVector{StdString}(svec_ref)
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]

svec_deref = getindex.(svec_ref)::Vector{CxxWrap.StdLib.StdStringDereferenced}
vec = StdVector{StdString}(svec_deref)
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]

@test_throws MethodError StdVector{Bool}([true])
@test_throws MethodError StdVector{eltype(svec_alloc)}(svec_alloc)
@test_throws MethodError StdVector{eltype(svec_deref)}(svec_deref)
let svec = StdString["a", "b", "c"]
svec_ref = CxxRef.(svec)
vec = StdVector{StdString}(svec_ref)
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]

svec_deref = getindex.(svec_ref)::Vector{CxxWrap.StdLib.StdStringDereferenced}
vec = StdVector{StdString}(svec_deref)
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]

@test_throws MethodError StdVector{Bool}([true])
@test_throws MethodError StdVector{eltype(svec_alloc)}(svec_alloc)
@test_throws MethodError StdVector{eltype(svec_deref)}(svec_deref)
end
end

@testset "constructors" begin
Expand Down Expand Up @@ -231,15 +233,17 @@ end
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]

svec_ref = CxxRef.(StdString["a", "b", "c"])
vec = StdVector(svec_ref)
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]
let svec = StdString["a", "b", "c"]
svec_ref = CxxRef.(svec)
vec = StdVector(svec_ref)
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]

svec_deref = getindex.(svec_ref)::Vector{CxxWrap.StdLib.StdStringDereferenced}
vec = StdVector(svec_deref)
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]
svec_deref = getindex.(svec_ref)::Vector{CxxWrap.StdLib.StdStringDereferenced}
vec = StdVector(svec_deref)
@test vec isa StdVector{StdString}
@test vec == ["a", "b", "c"]
end

@test_throws MethodError StdVector(["a", "b", "c"])
end
Expand Down

0 comments on commit a4eec02

Please sign in to comment.