diff --git a/CHANGES.md b/CHANGES.md index 75fdac37..6165aaa8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ simpler and safer and - restrict the necessity to create dictionaries to situations where recursive conversions make sense. - For that, the function `julia_to_gap_internal`, the macro `GAP.@install`, + For that, the function `GAP.GapObj_internal`, the macro `GAP.@install`, and the type `GapCacheDict` were introduced. ## Version 0.11.1 (released 2024-06-06) diff --git a/docs/src/conversion.md b/docs/src/conversion.md index 1f02dbff..663f09da 100644 --- a/docs/src/conversion.md +++ b/docs/src/conversion.md @@ -11,7 +11,8 @@ For a few types of objects, such conversions are unavoidable, see [Automatic GAP-to-Julia and Julia-to-GAP Conversions](@ref). In all other situations, the conversions between GAP objects and corresponding Julia objects -can be performed using [`gap_to_julia`](@ref) and [`julia_to_gap`](@ref), +can be performed using [`gap_to_julia`](@ref) and +[`GapObj(x, cache::GapCacheDict = nothing; recursive::Bool = false)`](@ref), see [Explicit GAP-to-Julia and Julia-to-GAP Conversions](@ref), respectively. For convenience, also constructor methods are provided, @@ -46,7 +47,7 @@ The exceptions are as follows. ```@docs gap_to_julia -julia_to_gap +GapObj(x, cache::GapCacheDict = nothing; recursive::Bool = false) ``` ## Constructor Methods for GAP-to-Julia Conversions diff --git a/docs/src/examples.md b/docs/src/examples.md index 42923a70..224bb224 100644 --- a/docs/src/examples.md +++ b/docs/src/examples.md @@ -99,7 +99,7 @@ julia> Vector{Vector{Int}}(cf) Next let us investigate the operation of the group on the 48 points. ```jldoctest rubik -julia> orbs = GAP.Globals.Orbits(cube, GAP.GapObj(1:48)) +julia> orbs = GAP.Globals.Orbits(cube, GapObj(1:48)) GAP: [ [ 1, 3, 17, 14, 8, 38, 9, 41, 19, 48, 22, 6, 30, 33, 43, 11, 46, 40, 24, 27, 25, 35, 16, 32 ], [ 2, 5, 12, 7, 36, 10, 47, 4, 28, 45, 34, 13, 29, 44, 20, 42, 26, 21, 37, 15, 31, 18, 23, 39 ] ] julia> length(orbs) @@ -315,7 +315,7 @@ For this purpose we introduce a free group and a homomorphism of it onto the cube group. ```jldoctest rubik -julia> f = GAP.Globals.FreeGroup(GAP.GapObj(["t", "l", "f", "r", "e", "b"], recursive = true)) +julia> f = GAP.Globals.FreeGroup(GapObj(["t", "l", "f", "r", "e", "b"], recursive = true)) GAP: julia> fhom = GAP.Globals.GroupHomomorphismByImages(f, cube) diff --git a/docs/src/other.md b/docs/src/other.md index 9f9613d5..fbd5de69 100644 --- a/docs/src/other.md +++ b/docs/src/other.md @@ -95,10 +95,10 @@ regarding the mutability of the result but here we have to choose one behaviour for the Julia function. ```jldoctest -julia> l = GAP.julia_to_gap( [ 1, 3, 7, 15 ] ) +julia> l = GapObj( [ 1, 3, 7, 15 ] ) GAP: [ 1, 3, 7, 15 ] -julia> m = GAP.julia_to_gap( [ 1 2; 3 4 ] ) +julia> m = GapObj( [ 1 2; 3 4 ] ) GAP: [ [ 1, 2 ], [ 3, 4 ] ] julia> length( l ) diff --git a/pkg/JuliaInterface/gap/JuliaInterface.gd b/pkg/JuliaInterface/gap/JuliaInterface.gd index 5772cb11..86e3b4ae 100644 --- a/pkg/JuliaInterface/gap/JuliaInterface.gd +++ b/pkg/JuliaInterface/gap/JuliaInterface.gd @@ -170,10 +170,10 @@ DeclareAttribute( "JuliaPointer", IsJuliaWrapper ); #! #! gap> IsJuliaModule( Julia.GAP ); #! true -#! gap> Julia.GAP.julia_to_gap; -#! -#! gap> JuliaFunction( "julia_to_gap", "GAP" ); # the same function -#! +#! gap> Julia.GAP.gap_to_julia; +#! +#! gap> JuliaFunction( "gap_to_julia", "GAP" ); # the same function +#! #! @EndExampleSession DeclareCategory( "IsJuliaModule", IsJuliaWrapper and IsRecord ); diff --git a/pkg/JuliaInterface/gap/convert.gd b/pkg/JuliaInterface/gap/convert.gd index aab9d196..16619de0 100644 --- a/pkg/JuliaInterface/gap/convert.gd +++ b/pkg/JuliaInterface/gap/convert.gd @@ -39,7 +39,7 @@ #! On the &Julia; side, there is usually no need for a wrapper, #! as (thanks to the shared garbage collector) #! most ⪆ objects are valid &Julia; objects of type -#! GAP.GapObj. +#! GapObj. #! The exception to that rule are immediate ⪆ objects, #! more on that in the next section. #! @@ -84,7 +84,7 @@ #! in the ⪆ Reference Manual. #! Since these are not valid pointers, &Julia; cannot treat them like other #! ⪆ objects, which are simply &Julia; objects of type -#! GAP.GapObj. +#! GapObj. #! Instead, a conversion is unavoidable, at least when immediate objects #! are passed as stand-alone arguments to a function. #!

@@ -135,7 +135,7 @@ #! &Julia; function wrapper to &Julia; function, #! #! -#! other ⪆ objects to GAP.GapObj. +#! other ⪆ objects to GapObj. #! #! #! @@ -156,7 +156,7 @@ #! &Julia; false to ⪆ false, #! #! -#! GAP.GapObj to Obj, +#! GapObj to Obj, #! #! #! other &Julia; objects to &Julia; object wrapper. @@ -169,7 +169,7 @@ #! and #! . #! In &Julia;, conversion is done via gap_to_julia and -#! julia_to_gap. +#! GapObj. #! #! Conversion from ⪆ to &Julia; #! @@ -289,7 +289,7 @@ #! of nested objects. #! Various methods for this constructor then take care of input validation #! and the actual conversion, either by delegating to the &Julia; function -#! julia_to_gap +#! GapObj #! (which takes just one or two arguments and chooses the ⪆ filters of #! its result depending on the &Julia; type), #! or by automatic conversion. @@ -370,7 +370,7 @@ #! #! #! -#! +#! #! a ⪆ object #! #! The &Julia; constructor takes an object @@ -403,7 +403,7 @@ #! via suitable methods for . #!

#! If one is sure that the result of the conversion to &GAP; is not an -#! immediate &GAP; object then one can call +#! immediate &GAP; object then one can call #! instead of . #! #! diff --git a/pkg/JuliaInterface/gap/convert.gi b/pkg/JuliaInterface/gap/convert.gi index 7edbf9bb..87f89d2c 100644 --- a/pkg/JuliaInterface/gap/convert.gi +++ b/pkg/JuliaInterface/gap/convert.gi @@ -8,7 +8,7 @@ InstallMethod(JuliaToGAP, ["IsInt", "IsJuliaObject"], function(filter, obj) if Julia.isa(obj, Julia.Base.Integer) then - return Julia.GAP.julia_to_gap(obj); + return Julia.GapObj(obj); fi; Error(" must be a Julia integer"); end); @@ -22,7 +22,7 @@ end); InstallMethod(JuliaToGAP, ["IsRat", "IsJuliaObject"], function(filter, obj) if Julia.isa(obj, Julia.Base.Integer) or Julia.isa(obj, Julia.Base.Rational) then - return Julia.GAP.julia_to_gap(obj); + return Julia.GapObj(obj); fi; Error(" must be a Julia integer or rational"); end); @@ -38,7 +38,7 @@ end); InstallMethod(JuliaToGAP, ["IsFloat", "IsJuliaObject"], function(filter, obj) if Julia.isa(obj, Julia.Base.AbstractFloat) then - return Julia.GAP.julia_to_gap(obj); + return Julia.GapObj(obj); fi; Error(" must be a Julia float"); end); @@ -54,10 +54,10 @@ end); InstallMethod(JuliaToGAP, ["IsChar", "IsJuliaObject"], function(filter, obj) if Julia.isa(obj, Julia.Base.Char) then - return Julia.GAP.julia_to_gap(obj); + return Julia.GapObj(obj); elif Julia.isa(obj, Julia.Base.Int8) or Julia.isa(obj, Julia.Base.UInt8) then - return CharInt( Julia.GAP.julia_to_gap(obj) ); + return CharInt( Julia.GapObj(obj) ); fi; Error(" must be a Julia Char or Int8 or UInt8"); @@ -119,7 +119,7 @@ InstallMethod(JuliaToGAP, ["IsString", "IsJuliaObject"], function(filter, obj) if Julia.isa(obj, Julia.Base.AbstractString) or Julia.isa(obj, Julia.Base.Symbol) then - return Julia.GAP.julia_to_gap(obj); + return Julia.GapObj(obj); fi; Error(" must be a Julia string or symbol"); end); diff --git a/pkg/JuliaInterface/gap/juliahelp.g b/pkg/JuliaInterface/gap/juliahelp.g index dd8197b6..e7365755 100644 --- a/pkg/JuliaInterface/gap/juliahelp.g +++ b/pkg/JuliaInterface/gap/juliahelp.g @@ -52,10 +52,10 @@ #! &Julia; functions belong to &Julia; modules. #! Many &Julia; functions can be accessed only relative to their modules, #! and then also the help requests work only for the qualified names. -#! For example, ?Julia:GAP.julia_to_gap yields the description -#! of the &Julia; function julia_to_gap that is defined in the +#! For example, ?Julia:GAP.wrap_rng yields the description +#! of the &Julia; function wrap_rng that is defined in the #! &Julia; module GAP, -#! whereas no match is found for the input ?Julia:julia_to_gap. +#! whereas no match is found for the input ?Julia:wrap_rng. #! #! #! @EndChunk diff --git a/pkg/JuliaInterface/tst/convert.tst b/pkg/JuliaInterface/tst/convert.tst index 6deea470..6dbf2492 100644 --- a/pkg/JuliaInterface/tst/convert.tst +++ b/pkg/JuliaInterface/tst/convert.tst @@ -189,11 +189,11 @@ gap> Julia.GAP.Obj( list ); [ 1, 2, 3 ] ## ranges -gap> Julia.GAP.julia_to_gap( JuliaEvalString( "1:3" ) ); +gap> Julia.GapObj( JuliaEvalString( "1:3" ) ); [ 1 .. 3 ] -gap> Julia.GAP.julia_to_gap( JuliaEvalString( "1:2:5" ) ); +gap> Julia.GapObj( JuliaEvalString( "1:2:5" ) ); [ 1, 3 .. 5 ] -gap> Julia.GAP.julia_to_gap( JuliaEvalString( "3:2" ) ); +gap> Julia.GapObj( JuliaEvalString( "3:2" ) ); [ ] gap> Julia.GAP.Obj( JuliaEvalString( "1:3" ) ); [ 1 .. 3 ] diff --git a/src/adapter.jl b/src/adapter.jl index 9ff0f27b..aaafb394 100644 --- a/src/adapter.jl +++ b/src/adapter.jl @@ -449,7 +449,7 @@ Base.copy(rng::MersenneTwister) = MersenneTwister(state=MersenneTwisterState(Glo Random.rand(rng::AbstractGAPRNG, x::Random.SamplerTrivial{<:Obj}) = Globals.Random(rng.ptr, x[]) Random.rand(rng::AbstractGAPRNG, x::Random.SamplerTrivial{<:AbstractUnitRange}) = - Globals.Random(rng.ptr, julia_to_gap(first(x[])), julia_to_gap(last(x[]))) + Globals.Random(rng.ptr, GapObj(first(x[])), GapObj(last(x[]))) Random.Sampler(::Type{<:AbstractGAPRNG}, x::AbstractUnitRange, ::Random.Repetition) = Random.SamplerTrivial(x) @@ -464,7 +464,7 @@ for U in (Base.BitInteger64, Union{Int128,UInt128}) end Random.Sampler(::Type{<:AbstractGAPRNG}, x::AbstractVector, ::Random.Repetition) = - Random.SamplerTrivial(julia_to_gap(x, recursive=false)) + Random.SamplerTrivial(GapObj(x, recursive=false)) # The following bypasses GAP's redirection of `x^-1` to `InverseSameMutability(x)`. diff --git a/src/ccalls.jl b/src/ccalls.jl index ac5c3836..9215d329 100644 --- a/src/ccalls.jl +++ b/src/ccalls.jl @@ -127,11 +127,11 @@ be a useful escape hatch to access GAP functionality that is otherwise impossible to difficult to reach. But in most typical scenarios it should not be necessary to use it at all. -Instead, use `GAP.GapObj` or `GAP.Obj` for constructing GAP objects +Instead, use `GapObj` or `GAP.Obj` for constructing GAP objects that correspond to given Julia objects, and call GAP functions directly in the Julia session. For example, executing `GAP.evalstr( "x:= []; Add( x, 2 )" )` -can be replaced by the Julia code `x = GAP.GapObj([]); GAP.Globals.Add(x, 2)`. +can be replaced by the Julia code `x = GapObj([]); GAP.Globals.Add(x, 2)`. Note that the variable `x` in the former example lives in the GAP session, i.e., it can be accessed as `GAP.Globals.x` after the call of `GAP.evalstr`, whereas `x` in the latter example lives in the Julia session. diff --git a/src/constructors.jl b/src/constructors.jl index 12749b03..b38a90fc 100644 --- a/src/constructors.jl +++ b/src/constructors.jl @@ -1,16 +1,15 @@ -## Handle "conversion" to GAP.Obj and GAP.GapObj (may occur in recursions). +## Handle "conversion" to GAP.Obj and GapObj (may occur in recursions). Obj(x::Obj) = x GapObj(x::GapObj) = x ## Handle conversion of Julia objects to GAP objects Obj(obj; recursive::Bool = false) = GapObj_internal(obj, nothing, recursive)::Obj -GapObj(obj; recursive::Bool = false) = GapObj_internal(obj, nothing, recursive)::GapObj Obj(obj, recursive::Bool) = GapObj_internal(obj, nothing, recursive)::Obj -GapObj(obj, recursive::Bool) = GapObj_internal(obj, nothing, recursive)::GapObj +GapObj(obj, recursive::Bool) = GapObj_internal(obj, nothing, recursive)::Obj ## Conversion to gap integers -GapInt(x::Integer) = julia_to_gap(x) +GapInt(x::Integer) = GapObj(x) """ diff --git a/src/julia_to_gap.jl b/src/julia_to_gap.jl index af6c7050..4f74dc11 100644 --- a/src/julia_to_gap.jl +++ b/src/julia_to_gap.jl @@ -1,31 +1,53 @@ ## Converters """ - julia_to_gap(input, recursion_dict::GapCacheDict = nothing; recursive::Bool = false) + GapObj(input, recursion_dict::GapCacheDict = nothing; recursive::Bool = false) + GapObj(input, recursive::Bool = false) + +One can use the type [`GapObj`](@ref) as a constructor, +in order to convert the julia object `input` to an appropriate GAP object. + +If `recursive` is set to `true`, recursive conversion of nested Julia objects +(arrays, tuples, and dictionaries) is performed. -Convert a julia object `input` to an appropriate GAP object. -If `recursive` is set to `true`, recursive conversion on -arrays, tuples, and dictionaries is performed. The input `recursion_dict` should never be set by the user, it is meant to keep egality of input data, by converting equal data to identical objects in GAP. # Examples ```jldoctest -julia> GAP.julia_to_gap(1//3) +julia> GapObj(1//3) GAP: 1/3 -julia> GAP.julia_to_gap("abc") +julia> GapObj("abc") GAP: "abc" -julia> GAP.julia_to_gap([ [1, 2], [3, 4]]) +julia> GapObj([1 2; 3 4]) +GAP: [ [ 1, 2 ], [ 3, 4 ] ] + +julia> GapObj([[1, 2], [3, 4]]) GAP: [ , ] -julia> GAP.julia_to_gap([ [1, 2], [3, 4]], recursive = true) +julia> GapObj([[1, 2], [3, 4]], true) +GAP: [ [ 1, 2 ], [ 3, 4 ] ] + +julia> GapObj([[1, 2], [3, 4]], recursive = true) GAP: [ [ 1, 2 ], [ 3, 4 ] ] +``` + +Note that this conversion is *not* restricted to outputs that actually are +of type `GapObj`, +also GAP integers, finite field elements, and booleans can be created +by the constructor `GapObj`. + +```jldoctest +julia> res = GapObj(42); res isa GapObj +false +julia> res isa GAP.Obj +true ``` -The following `julia_to_gap` conversions are supported by GAP.jl. +The following `GapObj` conversions are supported by GAP.jl. (Other Julia packages may provide conversions for more Julia objects.) | Julia type | GAP filter | @@ -46,9 +68,9 @@ The following `julia_to_gap` conversions are supported by GAP.jl. | `UnitRange{T}`, `StepRange{T, S}` | `IsRange` | | `Function` | `IsFunction` | """ -julia_to_gap(x, cache::GapCacheDict = nothing; recursive::Bool = false) = GapObj_internal(x, cache, recursive) +GapObj(x, cache::GapCacheDict = nothing; recursive::Bool = false) = GapObj_internal(x, cache, recursive) -# The calls to `GAP.@install` install methods for `GapObj_internal` +# The calls to `GAP.@install` install methods for `GAP.GapObj_internal` # so we must make sure it is declared before function GapObj_internal end @@ -226,7 +248,7 @@ end ## We have to do something only if recursive conversion is required, ## and if `obj` contains Julia subobjects; ## in this case, `obj` is a GAP list or record. -## An example of such an `obj` is `GAP.julia_to_gap([[1]])`. +## An example of such an `obj` is `GapObj([[1]])`. function GapObj_internal( obj::GapObj, recursion_dict::GapCacheDict, diff --git a/src/macros.jl b/src/macros.jl index e52d4699..3f2209af 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -383,9 +383,9 @@ macro wrap(ex) # type annotations -> split and decide what to do var = x.args[1] typeannot = x.args[2] - if typeannot in [:GapObj, :(GAP.GapObj)] - # the lhs has no type annotation, rhs gets wrapped in `GAP.GapObj(...)::GAP.GapObj` - (var, :(GAP.GapObj($var)::GAP.GapObj)) + if typeannot in [:GapObj, :(GapObj)] + # the lhs has no type annotation, rhs gets wrapped in `GapObj(...)::GapObj` + (var, :(GapObj($var)::GapObj)) elseif typeannot == :(GAP.Obj) # the lhs has no type annotation, rhs gets wrapped in `GAP.Obj(...)::GAP.Obj` (var, :(GAP.Obj($var)::GAP.Obj)) @@ -403,7 +403,7 @@ macro wrap(ex) ] lhsargs = map(first, tempargs) rhsargs = map(last, tempargs) - + # the "outer" part of the body body = MacroTools.@qq begin global $newsym diff --git a/src/types.jl b/src/types.jl index 9c7cee2b..d24cb20c 100644 --- a/src/types.jl +++ b/src/types.jl @@ -84,39 +84,12 @@ Module ``` One can use `GapObj` as a constructor, -in order to convert Julia objects to GAP objects. -Such calls are delegated to [`julia_to_gap`](@ref). - -However, this is restricted to outputs that actually are of type `GapObj`. -To also deal with GAP integers, finite field elements and booleans, use -[`GAP.Obj`](@ref) instead. - -Recursive conversion of nested Julia objects (arrays, tuples, dictionaries) -can be forced either by a second argument `true` -or by the keyword argument `recursive` with value `true`. - -# Examples -```jldoctest -julia> GapObj(1//3) -GAP: 1/3 - -julia> GapObj([1 2; 3 4]) -GAP: [ [ 1, 2 ], [ 3, 4 ] ] - -julia> GapObj([[1, 2], [3, 4]]) -GAP: [ , ] - -julia> GapObj([[1, 2], [3, 4]], true) -GAP: [ [ 1, 2 ], [ 3, 4 ] ] - -julia> GapObj([[1, 2], [3, 4]], recursive=true) -GAP: [ [ 1, 2 ], [ 3, 4 ] ] - -julia> GapObj(42) -ERROR: TypeError: in typeassert, expected GapObj, got a value of type Int64 -``` +in order to convert Julia objects to GAP objects, +see [`GapObj(x, cache::GapCacheDict = nothing; recursive::Bool = false)`](@ref) +for that. """ GapObj + """ GAP.Obj diff --git a/test/adapter.jl b/test/adapter.jl index 26c9a95e..85aea799 100644 --- a/test/adapter.jl +++ b/test/adapter.jl @@ -44,7 +44,7 @@ end @testset "GapObj" begin io = IOBuffer(); - print(io, GAP.GapObj) + print(io, GapObj) @test String(take!(io)) == "GapObj" L = [ GAP.evalstr( "()" ) ] @@ -52,9 +52,9 @@ end @test String(take!(io)) == "GapObj[GAP: ()]" ioc = IOContext(io, :module => nothing); - print(ioc, GAP.GapObj) + print(ioc, GapObj) if GAP.use_jl_reinit_foreign_type() - @test String(take!(io)) == "GAP.GapObj" + @test String(take!(io)) == "GapObj" else @test String(take!(io)) == "GAP_jll.GapObj" end diff --git a/test/basics.jl b/test/basics.jl index d660e545..d7448093 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -2,7 +2,7 @@ @test GAP.CSTR_STRING(GAP.Globals.String(GAP.Globals.PROD(2^59, 2^59))) == "332306998946228968225951765070086144" - l = GAP.julia_to_gap([1, 2, 3]) + l = GapObj([1, 2, 3]) @test l[1] == 1 @test l[end] == 3 @@ -18,10 +18,10 @@ x.a = 1 @test x.a == 1 - xx = GAP.julia_to_gap([1, 2, 3]) + xx = GapObj([1, 2, 3]) @test_throws ErrorException xx[4] - @test string(GAP.julia_to_gap("x")) == "x" + @test string(GapObj("x")) == "x" # equality and hashing x = GAP.evalstr("[]") @@ -74,14 +74,14 @@ end @testset "gapcalls" begin f = GAP.evalstr("{x...} -> x") - @test GAP.julia_to_gap([]) == f() - @test GAP.julia_to_gap([1]) == f(1) - @test GAP.julia_to_gap([1, 2]) == f(1, 2) - @test GAP.julia_to_gap([1, 2, 3]) == f(1, 2, 3) - @test GAP.julia_to_gap([1, 2, 3, 4]) == f(1, 2, 3, 4) - @test GAP.julia_to_gap([1, 2, 3, 4, 5]) == f(1, 2, 3, 4, 5) - @test GAP.julia_to_gap([1, 2, 3, 4, 5, 6]) == f(1, 2, 3, 4, 5, 6) - @test GAP.julia_to_gap([1, 2, 3, 4, 5, 6, 7]) == f(1, 2, 3, 4, 5, 6, 7) + @test GapObj([]) == f() + @test GapObj([1]) == f(1) + @test GapObj([1, 2]) == f(1, 2) + @test GapObj([1, 2, 3]) == f(1, 2, 3) + @test GapObj([1, 2, 3, 4]) == f(1, 2, 3, 4) + @test GapObj([1, 2, 3, 4, 5]) == f(1, 2, 3, 4, 5) + @test GapObj([1, 2, 3, 4, 5, 6]) == f(1, 2, 3, 4, 5, 6) + @test GapObj([1, 2, 3, 4, 5, 6, 7]) == f(1, 2, 3, 4, 5, 6, 7) @test [] == Vector{String}(f()) @test ["1"] == Vector{String}(f("1")) @@ -94,14 +94,14 @@ end g = GAP.evalstr("""{x...} -> [x,ValueOption("option")]""") - @test GAP.julia_to_gap([[], 42], recursive=true) == g(; option=42) - @test GAP.julia_to_gap([[1], 42], recursive=true) == g(1; option=42) - @test GAP.julia_to_gap([[1, 2], 42], recursive=true) == g(1, 2; option=42) - @test GAP.julia_to_gap([[1, 2, 3], 42], recursive=true) == g(1, 2, 3; option=42) - @test GAP.julia_to_gap([[1, 2, 3, 4], 42], recursive=true) == g(1, 2, 3, 4; option=42) - @test GAP.julia_to_gap([[1, 2, 3, 4, 5], 42], recursive=true) == g(1, 2, 3, 4, 5; option=42) - @test GAP.julia_to_gap([[1, 2, 3, 4, 5, 6], 42], recursive=true) == g(1, 2, 3, 4, 5, 6; option=42) - @test GAP.julia_to_gap([[1, 2, 3, 4, 5, 6, 7], 42], recursive=true) == g(1, 2, 3, 4, 5, 6, 7; option=42) + @test GapObj([[], 42], recursive=true) == g(; option=42) + @test GapObj([[1], 42], recursive=true) == g(1; option=42) + @test GapObj([[1, 2], 42], recursive=true) == g(1, 2; option=42) + @test GapObj([[1, 2, 3], 42], recursive=true) == g(1, 2, 3; option=42) + @test GapObj([[1, 2, 3, 4], 42], recursive=true) == g(1, 2, 3, 4; option=42) + @test GapObj([[1, 2, 3, 4, 5], 42], recursive=true) == g(1, 2, 3, 4, 5; option=42) + @test GapObj([[1, 2, 3, 4, 5, 6], 42], recursive=true) == g(1, 2, 3, 4, 5, 6; option=42) + @test GapObj([[1, 2, 3, 4, 5, 6, 7], 42], recursive=true) == g(1, 2, 3, 4, 5, 6, 7; option=42) # check to see if a non-basic object (here: a tuple) can be # passed and then extracted again diff --git a/test/constructors.jl b/test/constructors.jl index 71f57ce8..c07f0e9e 100644 --- a/test/constructors.jl +++ b/test/constructors.jl @@ -4,7 +4,7 @@ @testset "Conversion to GAP.Obj and GAP.GapObj" begin x = GAP.evalstr("2^100") - @test (@inferred GAP.GapObj(x)) == x + @test (@inferred GapObj(x)) == x @test GAP.Obj(true) == true x = GAP.evalstr("Z(3)") @test GAP.Obj(x) == x @@ -17,11 +17,11 @@ @test c == GAP.Obj(m, false) c = GAP.Obj(m, true) @test c[1] isa GAP.Obj - c = GAP.GapObj(m) + c = GapObj(m) @test c[1] isa Vector - @test c == GAP.GapObj(m, false) - c = GAP.GapObj(m, true) - @test c[1] isa GAP.GapObj + @test c == GapObj(m, false) + c = GapObj(m, true) + @test c[1] isa GapObj end @testset "Border cases" begin @@ -100,23 +100,23 @@ end @testset "Vectors" begin - x = GAP.julia_to_gap([1, 2, 3]) + x = GapObj([1, 2, 3]) @test (@inferred Vector{Any}(x)) == [1, 2, 3] @test (@inferred Vector{Int64}(x)) == [1, 2, 3] @test (@inferred Vector{BigInt}(x)) == [1, 2, 3] - n = GAP.julia_to_gap(big(2)^100) + n = GapObj(big(2)^100) @test_throws GAP.ConversionError Vector{Int64}(n) @test_throws GAP.ConversionError Vector{BigInt}(n) x = GAP.evalstr("[ [ 1, 2 ], [ 3, 4 ] ]") - nonrec1 = @inferred Vector{GAP.GapObj}(x) + nonrec1 = @inferred Vector{GapObj}(x) nonrec2 = @inferred Vector{Any}(x; recursive = false) rec = @inferred Vector{Any}(x; recursive = true) - @test all(x -> isa(x, GAP.GapObj), nonrec1) + @test all(x -> isa(x, GapObj), nonrec1) @test nonrec1 == nonrec2 @test nonrec1 != rec @test all(x -> isa(x, Array), rec) x = [1, 2] - y = GAP.julia_to_gap([x, x]; recursive = true) + y = GapObj([x, x]; recursive = true) z = Vector{Any}(y) @test z[1] === z[2] end @@ -125,9 +125,9 @@ n = GAP.evalstr("[[1,2],[3,4]]") @test (@inferred Matrix{Int64}(n)) == [1 2; 3 4] xt = [(1,) (2,); (3,) (4,)] - n = GAP.julia_to_gap(xt; recursive = false) + n = GapObj(xt; recursive = false) @test (@inferred Matrix{Tuple{Int64}}(n)) == xt - n = GAP.julia_to_gap(big(2)^100) + n = GapObj(big(2)^100) @test_throws GAP.ConversionError Matrix{Int64}(n) n = GAP.evalstr("[[1,2],[,4]]") #@test Matrix{Union{Int64,Nothing}}(n) == [1 2; nothing 4] @@ -135,12 +135,12 @@ m = Any[1 2; 3 4] m[1, 1] = x m[2, 2] = x - x = GAP.julia_to_gap(m; recursive = true) + x = GapObj(m; recursive = true) y = @inferred Matrix{Any}(x) - @test !isa(y[1, 1], GAP.GapObj) + @test !isa(y[1, 1], GapObj) @test y[1, 1] === y[2, 2] z = @inferred Matrix{Any}(x; recursive = false) - @test isa(z[1, 1], GAP.GapObj) + @test isa(z[1, 1], GapObj) @test z[1, 1] === z[2, 2] end @@ -149,16 +149,16 @@ @test (@inferred Set{Vector{Int}}(GAP.evalstr("[[1,2],[2,3,4]]"))) == Set([[1, 2], [2, 3, 4]]) @test (@inferred Set{String}(GAP.evalstr("[\"b\", \"a\", \"b\"]"))) == Set(["b", "a", "b"]) x = GAP.evalstr("SymmetricGroup(3)") - #@test (@inferred Set{GAP.GapObj}(x)) == Set{GAP.GapObj}(GAP.Globals.AsSet(x)) + #@test (@inferred Set{GapObj}(x)) == Set{GapObj}(GAP.Globals.AsSet(x)) end @testset "Tuples" begin - x = GAP.julia_to_gap([1, 2, 3]) + x = GapObj([1, 2, 3]) @test (@inferred Tuple{Int64,Int16,Int32}(x)) == (1, 2, 3) @test Tuple{Int64,Any,Int32}(x) == (1, 2, 3) @test_throws ArgumentError Tuple{Any,Any}(x) @test_throws ArgumentError Tuple{Any,Any,Any,Any}(x) - n = GAP.julia_to_gap(big(2)^100) + n = GapObj(big(2)^100) @test_throws GAP.ConversionError Tuple{Int64,Any,Int32}(n) x = GAP.evalstr("[ [ 1, 2 ], [ 3, [ 4, 5 ] ] ]") y = Tuple{GAP.Obj,Any}(x) @@ -198,7 +198,7 @@ x = GAP.evalstr("rec( foo := 1, bar := \"foo\" )") y = Dict{Symbol,Any}(:foo => 1, :bar => "foo") @test (@inferred Dict{Symbol,Any}(x)) == y - n = GAP.julia_to_gap(big(2)^100) + n = GapObj(big(2)^100) @test_throws GAP.ConversionError Dict{Symbol,Any}(n) x = GAP.evalstr("rec( a:= [ 1, 2 ], b:= [ 3, [ 4, 5 ] ] )") y = @inferred Dict{Symbol,Any}(x) @@ -226,7 +226,7 @@ end @testset "GAP lists with Julia objects" begin - xx = GAP.julia_to_gap([(1,)]) + xx = GapObj([(1,)]) yy = @inferred Vector{Tuple{Int64}}(xx) @test [(1,)] == yy @test typeof(yy) == Vector{Tuple{Int64}} diff --git a/test/convenience.jl b/test/convenience.jl index 0cf06708..d12265c9 100644 --- a/test/convenience.jl +++ b/test/convenience.jl @@ -68,7 +68,7 @@ end # Julia object in GAP list l = [ [ 1 2 ], [ 3 4 ] ] - gaplist = GAP.julia_to_gap( l ) # list of Julia arrays + gaplist = GapObj( l ) # list of Julia arrays @test l[1] in gaplist @test !([ 5 6 ] in gaplist) end diff --git a/test/conversion.jl b/test/conversion.jl index a74e2f5a..8272dad7 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -6,9 +6,9 @@ @test GAP.gap_to_julia(Any, "foo") == "foo" end - @testset "Conversion to GAP.Obj and GAP.GapObj" begin + @testset "Conversion to GAP.Obj and GapObj" begin x = GAP.evalstr("2^100") - @test GAP.gap_to_julia(GAP.GapObj, x) == x + @test GAP.gap_to_julia(GapObj, x) == x @test GAP.gap_to_julia(GAP.Obj, true) == true x = GAP.evalstr("Z(3)") @test GAP.gap_to_julia(GAP.Obj, x) == x @@ -93,9 +93,9 @@ @test (@inferred GAP.gap_to_julia(String, x)) == "foo" @test GAP.gap_to_julia(x) == "foo" x = "abc\000def" - @test GAP.gap_to_julia(GAP.julia_to_gap(x)) == x + @test GAP.gap_to_julia(GapObj(x)) == x x = "jμΛIα" - @test GAP.gap_to_julia(GAP.julia_to_gap(x)) == x + @test GAP.gap_to_julia(GapObj(x)) == x end @testset "Symbols" begin @@ -121,24 +121,24 @@ end @testset "Vectors" begin - x = GAP.julia_to_gap([1, 2, 3]) + x = GapObj([1, 2, 3]) @test (@inferred GAP.gap_to_julia(Vector{Any}, x)) == Vector{Any}([1, 2, 3]) @test GAP.gap_to_julia(x) == Vector{Any}([1, 2, 3]) @test (@inferred GAP.gap_to_julia(Vector{Int64}, x)) == [1, 2, 3] @test (@inferred GAP.gap_to_julia(Vector{BigInt}, x)) == [1, 2, 3] - n = GAP.julia_to_gap(big(2)^100) + n = GapObj(big(2)^100) @test_throws GAP.ConversionError GAP.gap_to_julia(Vector{Int64}, n) @test_throws GAP.ConversionError GAP.gap_to_julia(Vector{BigInt}, n) x = GAP.evalstr("[ [ 1, 2 ], [ 3, 4 ] ]") - nonrec1 = @inferred GAP.gap_to_julia(Vector{GAP.GapObj}, x) + nonrec1 = @inferred GAP.gap_to_julia(Vector{GapObj}, x) nonrec2 = @inferred GAP.gap_to_julia(Vector{Any}, x; recursive = false) rec = GAP.gap_to_julia(Vector{Any}, x; recursive = true) - @test all(x -> isa(x, GAP.GapObj), nonrec1) + @test all(x -> isa(x, GapObj), nonrec1) @test nonrec1 == nonrec2 @test nonrec1 != rec @test all(x -> isa(x, Array), rec) x = [1, 2] - y = GAP.julia_to_gap([x, x]; recursive = true) + y = GapObj([x, x]; recursive = true) z = GAP.gap_to_julia(Vector{Any}, y) @test z[1] === z[2] x = GAP.evalstr( "NewVector( IsPlistVectorRep, Integers, [ 0, 2, 5 ] )" ) @@ -150,9 +150,9 @@ n = GAP.evalstr("[[1,2],[3,4]]") @test (@inferred GAP.gap_to_julia(Matrix{Int64}, n)) == [1 2; 3 4] xt = [(1,) (2,); (3,) (4,)] - n = GAP.julia_to_gap(xt; recursive = false) + n = GapObj(xt; recursive = false) @test (@inferred GAP.gap_to_julia(Matrix{Tuple{Int64}}, n)) == xt - n = GAP.julia_to_gap(big(2)^100) + n = GapObj(big(2)^100) @test_throws GAP.ConversionError GAP.gap_to_julia(Matrix{Int64}, n) #n = GAP.evalstr("[[1,2],[,4]]") #@test GAP.gap_to_julia(Matrix{Union{Int64,Nothing}}, n) == [1 2; nothing 4] @@ -160,12 +160,12 @@ m = Any[1 2; 3 4] m[1, 1] = x m[2, 2] = x - x = GAP.julia_to_gap(m; recursive = true) + x = GapObj(m; recursive = true) y = GAP.gap_to_julia(Matrix{Any}, x) - @test !isa(y[1, 1], GAP.GapObj) + @test !isa(y[1, 1], GapObj) @test y[1, 1] === y[2, 2] z = GAP.gap_to_julia(Matrix{Any}, x; recursive = false) - @test isa(z[1, 1], GAP.GapObj) + @test isa(z[1, 1], GapObj) @test z[1, 1] === z[2, 2] m = GAP.evalstr( "NewMatrix( IsPlistMatrixRep, Integers, 2, [ 0, 1, 2, 3 ] )" ) @test GAP.gap_to_julia(m) == Matrix{Any}([0 1; 2 3]) @@ -176,7 +176,7 @@ x = GAP.evalstr("[ [ 1 ], [ 2 ], [ 1 ] ]") y = [GAP.evalstr("[ 1 ]"), GAP.evalstr("[ 2 ]")] @test (@inferred GAP.gap_to_julia(Set{Vector{Int}}, x)) == Set([[1], [2], [1]]) - #@test @inferred GAP.gap_to_julia(Set{GAP.GapObj}, x, recursive = false) == Set(y) + #@test @inferred GAP.gap_to_julia(Set{GapObj}, x, recursive = false) == Set(y) #@test @inferred GAP.gap_to_julia(Set{Any}, x, recursive = false) == Set(y) @test (@inferred GAP.gap_to_julia(Set{Any}, x)) == Set([[1], [2], [1]]) x = GAP.evalstr("[ Z(2), Z(3) ]") # a non-collection @@ -185,11 +185,11 @@ end @testset "Tuples" begin - x = GAP.julia_to_gap([1, 2, 3]) + x = GapObj([1, 2, 3]) @test (@inferred GAP.gap_to_julia(Tuple{Int64,Int16,Int32}, x)) == (1, 2, 3) @test_throws ArgumentError GAP.gap_to_julia(Tuple{Any,Any}, x) @test_throws ArgumentError GAP.gap_to_julia(Tuple{Any,Any,Any,Any}, x) - n = GAP.julia_to_gap(big(2)^100) + n = GapObj(big(2)^100) @test_throws GAP.ConversionError GAP.gap_to_julia(Tuple{Int64,Any,Int32}, n) x = GAP.evalstr("[ [ 1, 2 ], [ 3, [ 4, 5 ] ] ]") y = GAP.gap_to_julia(Tuple{GAP.Obj,Any}, x) @@ -230,7 +230,7 @@ y = Dict{Symbol,Any}(:foo => 1, :bar => "foo") @test (@inferred GAP.gap_to_julia(Dict{Symbol,Any}, x)) == y @test GAP.gap_to_julia(x) == y - n = GAP.julia_to_gap(big(2)^100) + n = GapObj(big(2)^100) @test_throws GAP.ConversionError GAP.gap_to_julia(Dict{Symbol,Any}, n) x = GAP.evalstr("rec( a:= [ 1, 2 ], b:= [ 3, [ 4, 5 ] ] )") y = GAP.gap_to_julia(Dict{Symbol,Any}, x) @@ -265,7 +265,7 @@ end @testset "Catch conversions to types that are not supported" begin - xx = GAP.julia_to_gap("a") + xx = GapObj("a") @test_throws ErrorException GAP.gap_to_julia(Dict{Int64,Int64}, xx) end @@ -281,7 +281,7 @@ end @testset "GAP lists with Julia objects" begin - xx = GAP.julia_to_gap([(1,)]) + xx = GapObj([(1,)]) yy = GAP.gap_to_julia(Vector{Tuple{Int64}}, xx) @test [(1,)] == yy @test typeof(yy) == Vector{Tuple{Int64}} @@ -292,131 +292,131 @@ end end @testset "Defaults" begin - @test GAP.julia_to_gap(true) + @test GapObj(true) end @testset "Integers" begin for i in -2:2 - @test GAP.julia_to_gap(Int128(i)) == i - @test GAP.julia_to_gap(Int64(i)) == i - @test GAP.julia_to_gap(Int32(i)) == i - @test GAP.julia_to_gap(Int16(i)) == i - @test GAP.julia_to_gap(Int8(i)) == i + @test GapObj(Int128(i)) == i + @test GapObj(Int64(i)) == i + @test GapObj(Int32(i)) == i + @test GapObj(Int16(i)) == i + @test GapObj(Int8(i)) == i end end @testset "Int64 corner cases" begin - @test GAP.julia_to_gap(-2^60) === -2^60 - @test GAP.julia_to_gap(2^60 - 1) === 2^60 - 1 + @test GapObj(-2^60) === -2^60 + @test GapObj(2^60 - 1) === 2^60 - 1 - @test GAP.Globals.IsInt(GAP.julia_to_gap(-2^60 - 1)) - @test GAP.Globals.IsInt(GAP.julia_to_gap(2^60)) + @test GAP.Globals.IsInt(GapObj(-2^60 - 1)) + @test GAP.Globals.IsInt(GapObj(2^60)) - @test GAP.Globals.IsInt(GAP.julia_to_gap(-2^63 - 1)) - @test GAP.Globals.IsInt(GAP.julia_to_gap(-2^63)) - @test GAP.Globals.IsInt(GAP.julia_to_gap(2^63 - 1)) - @test GAP.Globals.IsInt(GAP.julia_to_gap(2^63)) + @test GAP.Globals.IsInt(GapObj(-2^63 - 1)) + @test GAP.Globals.IsInt(GapObj(-2^63)) + @test GAP.Globals.IsInt(GapObj(2^63 - 1)) + @test GAP.Globals.IsInt(GapObj(2^63)) # see issue https://github.com/oscar-system/GAP.jl/issues/332 @test 2^60 * GAP.Globals.Factorial(20) == GAP.evalstr("2^60 * Factorial(20)") end @testset "Unsigned integers" begin - @test GAP.julia_to_gap(UInt128(1)) == 1 - @test GAP.julia_to_gap(UInt64(1)) == 1 - @test GAP.julia_to_gap(UInt32(1)) == 1 - @test GAP.julia_to_gap(UInt16(1)) == 1 - @test GAP.julia_to_gap(UInt8(1)) == 1 + @test GapObj(UInt128(1)) == 1 + @test GapObj(UInt64(1)) == 1 + @test GapObj(UInt32(1)) == 1 + @test GapObj(UInt16(1)) == 1 + @test GapObj(UInt8(1)) == 1 end @testset "BigInts" begin for i = -2:2 - @test GAP.julia_to_gap(BigInt(i)) == i + @test GapObj(BigInt(i)) == i end x = GAP.evalstr("2^100") - @test GAP.julia_to_gap(BigInt(2)^100) == x - @test GAP.julia_to_gap(-BigInt(2)^100) == -x + @test GapObj(BigInt(2)^100) == x + @test GapObj(-BigInt(2)^100) == -x end @testset "Rationals" begin x = GAP.evalstr("2^100") - @test GAP.julia_to_gap(Rational{BigInt}(2)^100 // 1) == x + @test GapObj(Rational{BigInt}(2)^100 // 1) == x x = GAP.evalstr("2^100/3") - @test GAP.julia_to_gap(Rational{BigInt}(2)^100 // 3) == x - @test GAP.julia_to_gap(1 // 0) == GAP.Globals.infinity - @test GAP.julia_to_gap(-1 // 0) == -GAP.Globals.infinity + @test GapObj(Rational{BigInt}(2)^100 // 3) == x + @test GapObj(1 // 0) == GAP.Globals.infinity + @test GapObj(-1 // 0) == -GAP.Globals.infinity end @testset "Floats" begin x = GAP.evalstr("2.") - @test GAP.julia_to_gap(2.0) == x - @test GAP.julia_to_gap(Float32(2.0)) == x - @test GAP.julia_to_gap(Float16(2.0)) == x + @test GapObj(2.0) == x + @test GapObj(Float32(2.0)) == x + @test GapObj(Float16(2.0)) == x end @testset "Chars" begin x = GAP.evalstr("'x'") - @test GAP.julia_to_gap('x') == x + @test GapObj('x') == x end @testset "Strings & Symbols" begin x = GAP.evalstr("\"foo\"") - @test GAP.julia_to_gap("foo") == x - @test GAP.julia_to_gap(:foo) == x + @test GapObj("foo") == x + @test GapObj(:foo) == x substr = match(r"a(.*)c", "abc").match # type is `SubString{String}` - @test GAP.julia_to_gap(substr) == GAP.julia_to_gap("abc") - @test length(GAP.julia_to_gap("abc\000def")) == 7 # contains a null character + @test GapObj(substr) == GapObj("abc") + @test length(GapObj("abc\000def")) == 7 # contains a null character x = GAP.evalstr("\"jμΛIα\"") @test length(x) == 8 # in GAP, the number of bytes - @test GAP.julia_to_gap("jμΛIα") == x + @test GapObj("jμΛIα") == x @test length("jμΛIα") == 5 @test sizeof("jμΛIα") == 8 end @testset "Arrays" begin x = GAP.evalstr("[1,\"foo\",2]") - @test GAP.julia_to_gap([1, "foo", BigInt(2)]; recursive = true) == x + @test GapObj([1, "foo", BigInt(2)]; recursive = true) == x x = GAP.evalstr("[1,JuliaEvalString(\"\\\"foo\\\"\"),2]") - @test GAP.julia_to_gap([1, "foo", BigInt(2)]) == x + @test GapObj([1, "foo", BigInt(2)]) == x x = GAP.evalstr("[[1,2],[3,4]]") - @test GAP.julia_to_gap([1 2; 3 4]) == x + @test GapObj([1 2; 3 4]) == x end @testset "BitVectors" begin x = GAP.evalstr("BlistList([1,2],[1])") - y = GAP.julia_to_gap([true, false]) + y = GapObj([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) + gap_v = GapObj(v) @test gap_v == x @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(gap_v)) == "list (boolean)" end @testset "Tuples" begin x = GAP.evalstr("[1,\"foo\",2]") - @test GAP.julia_to_gap((1, "foo", 2); recursive = true) == x + @test GapObj((1, "foo", 2); recursive = true) == x x = GAP.evalstr("[1,JuliaEvalString(\"\\\"foo\\\"\"),2]") - @test GAP.julia_to_gap((1, "foo", 2)) == x + @test GapObj((1, "foo", 2)) == x end @testset "Ranges" begin r = GAP.evalstr("[]") - @test GAP.julia_to_gap(1:0) == r - @test GAP.julia_to_gap(1:1:0) == r + @test GapObj(1:0) == r + @test GapObj(1:1:0) == r r = GAP.evalstr("[ 1 ]") - @test GAP.julia_to_gap(1:1) == r - @test GAP.julia_to_gap(1:1:1) == r + @test GapObj(1:1) == r + @test GapObj(1:1:1) == r r = GAP.evalstr("[ 4 .. 13 ]") - @test GAP.julia_to_gap(4:13) == r - @test GAP.julia_to_gap(4:1:13) == r + @test GapObj(4:13) == r + @test GapObj(4:1:13) == r 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) + @test GapObj(1:3:10) == r + @test_throws GAP.ConversionError GapObj(1:2^62) - r = GAP.julia_to_gap(1:2:11, IdDict(), recursive = false) - @test r == GAP.julia_to_gap(1:2:11) + r = GapObj(1:2:11, IdDict(), recursive = false) + @test r == GapObj(1:2:11) @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)" @@ -427,25 +427,25 @@ end y = Dict{Symbol,Any}(:foo => 1, :bar => "foo") z = GAP.evalstr("rec( foo := 1, bar := JuliaEvalString(\"\\\"foo\\\"\") )") # ... recursive conversion - @test GAP.julia_to_gap(y; recursive = true) == x + @test GapObj(y; recursive = true) == x # ... non-recursive conversion - @test GAP.julia_to_gap(y) == z + @test GapObj(y) == z # also test the case were the top level is a GapObj but inside # there are Julia objects - @test GAP.julia_to_gap(z; recursive=true) == x - @test GAP.julia_to_gap(z; recursive=false) == z # nothing happens without recursion + @test GapObj(z; recursive=true) == x + @test GapObj(z; recursive=false) == z # nothing happens without recursion end @testset "Conversions with identical sub-objects" begin l = [1] yy = [l, l] # ... recursive conversion - conv = GAP.julia_to_gap(yy; recursive = true) - @test conv[1] isa GAP.GapObj + conv = GapObj(yy; recursive = true) + @test conv[1] isa GapObj @test conv[1] === conv[2] # ... non-recursive conversion - conv = GAP.julia_to_gap(yy; recursive = false) + conv = GapObj(yy; recursive = false) @test isa(conv[1], Vector{Int64}) @test conv[1] === conv[2] @@ -455,9 +455,9 @@ end l[1] = x l[2] = x @test l[1] === l[2] - res = GAP.julia_to_gap(l) + res = GapObj(l) @test res[1] === res[2] - res = GAP.julia_to_gap(l, recursive=true) + res = GapObj(l, recursive=true) @test res[1] === res[2] # a GAP record with identical Julia subobjects @@ -465,9 +465,9 @@ end setproperty!(r, :a, x) setproperty!(r, :b, x) @test r.a === r.b - res = GAP.julia_to_gap(r) + res = GapObj(r) @test res.a === res.b - res = GAP.julia_to_gap(r, recursive=true) + res = GapObj(r, recursive=true) @test res.a === res.b end @@ -476,11 +476,11 @@ end yy[1] = yy yy[2] = yy # ... recursive conversion - conv = GAP.julia_to_gap(yy; recursive = true) + conv = GapObj(yy; recursive = true) @test conv[1] === conv @test conv[1] === conv[2] # ... non-recursive conversion - conv = GAP.julia_to_gap(yy; recursive = false) + conv = GapObj(yy; recursive = false) @test conv[1] !== conv @test conv[1] === conv[2] end @@ -488,29 +488,29 @@ end @testset "converting a dictionary with circular refs" begin d = Dict{String,Any}("a" => 1) d["b"] = d - conv = GAP.julia_to_gap(d; recursive = true) + conv = GapObj(d; recursive = true) @test conv === conv.b end @testset "Test converting lists with 'nothing' in them -> should be converted to a hole in the list" begin xx = GAP.evalstr("[1,,1]") - @test GAP.julia_to_gap([1, nothing, 1]) == xx + @test GapObj([1, nothing, 1]) == xx end @testset "Convert GAP objects recursively" begin - val = GAP.julia_to_gap([]) + val = GapObj([]) val[1] = [1, 2] val[2] = [3, 4] - nonrec = GAP.julia_to_gap(val) + nonrec = GapObj(val) @test nonrec[1] == [1, 2] - rec = GAP.julia_to_gap(val, recursive = true) - @test rec[1] == GAP.julia_to_gap([1, 2]) - @test GAP.julia_to_gap(1, recursive = false) == 1 + rec = GapObj(val, recursive = true) + @test rec[1] == GapObj([1, 2]) + @test GapObj(1, recursive = false) == 1 end @testset "Test function conversion" begin return_first(args...) = args[1] - return_first_gap = GAP.julia_to_gap(return_first) + return_first_gap = GapObj(return_first) @test GAP.Globals.IsFunction(return_first) == false @test GAP.Globals.IsFunction(return_first_gap) == true list = GAP.evalstr("[1,2,3]") diff --git a/test/macros.jl b/test/macros.jl index 5c011fe4..8d599ff8 100644 --- a/test/macros.jl +++ b/test/macros.jl @@ -33,7 +33,7 @@ @test ! has_cendersub(G) @test has_dersub(G) # the previous call has set the value ggens = GAP.Globals.GeneratorsOfGroup(G) - set_cendersub(G, GAP.Globals.Subgroup(G, GAP.GapObj([ggens[1]]))) + set_cendersub(G, GAP.Globals.Subgroup(G, GapObj([ggens[1]]))) @test has_cendersub(G) @test GAP.Globals.HasCentre(GAP.Globals.DerivedSubgroup(G)) @test GAP.Globals.Size(GAP.Globals.Centre(G)) == 1 @@ -53,9 +53,9 @@ end @test_throws ErrorException @gap (1,2)(3,4) x = GAP.g"foo" - @test x == GAP.julia_to_gap("foo") + @test x == GapObj("foo") x = GAP.g"1:\n, 2:\", 3:\\, 4:\b, 5:\r, 6:\c, 7:\001" - @test x == GAP.julia_to_gap("1:\n, 2:\", 3:\\, 4:\b, 5:\r, 6:\003, 7:\001") + @test x == GapObj("1:\n, 2:\", 3:\\, 4:\b, 5:\r, 6:\003, 7:\001") @test_throws ErrorException g"\\" end @@ -68,7 +68,7 @@ end @test GapObj(TestType1(a)) === a struct TestType2 X::GapObj end - GAP.@install function GAP.GapObj(x::TestType2) return x.X; end + GAP.@install function GapObj(x::TestType2) return x.X; end @test GapObj(TestType2(a)) === a @test_throws ErrorException @macroexpand GAP.@install Obj(x::Bool) diff --git a/test/packages.jl b/test/packages.jl index 54fab790..5e831439 100644 --- a/test/packages.jl +++ b/test/packages.jl @@ -24,7 +24,7 @@ #TODO: How to guarantee two installed versions with different paths? # - a package that was not yet loaded (only once in a Julia session) - if ! GAP.Globals.IsPackageLoaded(GAP.GapObj("autodoc")) + if ! GAP.Globals.IsPackageLoaded(GapObj("autodoc")) path = string(GAP.Globals.GAPInfo.PackagesInfo.autodoc[1].InstallationPath) @test GAP.Packages.load(path) end