Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: keep some string vectors alive for references #461

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading