Skip to content

Commit

Permalink
Merge branch 'master' into lg/wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens authored May 15, 2024
2 parents 648cddc + c53585e commit e02d1e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/julia_to_gap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ julia_to_gap(obj::Any, recursion_dict::IdDict{Any,Any}; recursive::Bool = true)

## Arrays (including BitVector)
function julia_to_gap(
obj::Vector{T},
obj::AbstractVector{T},
recursion_dict::IdDict{Any,Any} = IdDict();
recursive::Bool = false,
) where {T}
Expand Down Expand Up @@ -172,12 +172,20 @@ function julia_to_gap(
end

## Ranges
function julia_to_gap(r::AbstractRange{<:Integer})
function julia_to_gap(r::AbstractRange{<:Integer}, recursive::Bool = false)
res = NewRange(length(r), first(r), step(r))
Wrappers.IsRange(res) || throw(ConversionError(r, GapObj))
return res
end

function julia_to_gap(
r::AbstractRange{<:Integer},
recursion_dict::IdDict{Any,Any};
recursive::Bool = false)

return julia_to_gap(r)
end

## Dictionaries
function julia_to_gap(
obj::Dict{T,S},
Expand Down
10 changes: 10 additions & 0 deletions test/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ end
y = GAP.julia_to_gap([true, false])
@test y == x
@test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(y)) == "list (boolean)"

v = BitVector([true, false])
gap_v = GAP.julia_to_gap(v)
@test gap_v == x
@test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(gap_v)) == "list (boolean)"
end

@testset "Tuples" begin
Expand All @@ -409,6 +414,11 @@ end
r = GAP.evalstr("[ 1, 4 .. 10 ]")
@test GAP.julia_to_gap(1:3:10) == r
@test_throws GAP.ConversionError GAP.julia_to_gap(1:2^62)

r = GAP.julia_to_gap(1:2:11, IdDict(), recursive = false)
@test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(r)) == "list (range,ssort)"
r = GAP.Obj(1:10)
@test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(r)) == "list (range,ssort)"
end

@testset "Dictionaries" begin
Expand Down

0 comments on commit e02d1e4

Please sign in to comment.