Skip to content

Commit

Permalink
Tweak alignment and format:off/on
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwe committed Jan 22, 2025
1 parent beb033a commit 95cf652
Showing 1 changed file with 62 additions and 58 deletions.
120 changes: 62 additions & 58 deletions test/recursive_maps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,70 +190,70 @@ const inactivebits = (1, Empty())
const inactivetup = (inactivebits, "a", MutableEmpty())
const inactivearr = [inactivetup]

#! format: off
const wrappers = [
#! format: off
(name="Tuple{X}", f=tuple, N=1, mutable=false, typed=true, bitsonly=false),
(name="@NamedTuple{x::X}", f=(NamedTuple{(:x,)} tuple), N=1, mutable=false, typed=true, bitsonly=false),
(name="struct{X}", f=Wrapper, N=1, mutable=false, typed=true, bitsonly=false),
(name = "Tuple{X}", f = tuple, N = 1, mutable = false, typed = true, bitsonly = false),
(name = "@NamedTuple{x::X}", f = (NamedTuple{(:x,)} tuple), N = 1, mutable = false, typed = true, bitsonly = false),
(name = "struct{X}", f = Wrapper, N = 1, mutable = false, typed = true, bitsonly = false),

(name="@NamedTuple{x}", f=(@NamedTuple{x} tuple), N=1, mutable=false, typed=false, bitsonly=false),
(name="struct{Any}", f=Wrapper{Any}, N=1, mutable=false, typed=false, bitsonly=false),
(name = "@NamedTuple{x}", f = (@NamedTuple{x} tuple), N = 1, mutable = false, typed = false, bitsonly = false),
(name = "struct{Any}", f = Wrapper{Any}, N = 1, mutable = false, typed = false, bitsonly = false),

(name="Array{X}", f=(x -> [x]), N=1, mutable=true, typed=true, bitsonly=false),
(name="Base.RefValue{X}", f=Ref, N=1, mutable=true, typed=true, bitsonly=false),
(name="mutable struct{X}", f=MutableWrapper, N=1, mutable=true, typed=true, bitsonly=false),
(name = "Array{X}", f = (x -> [x]), N = 1, mutable = true, typed = true, bitsonly = false),
(name = "Base.RefValue{X}", f = Ref, N = 1, mutable = true, typed = true, bitsonly = false),
(name = "mutable struct{X}", f = MutableWrapper, N = 1, mutable = true, typed = true, bitsonly = false),

(name="Array{Any}", f=(x -> Any[x]), N=1, mutable=true, typed=false, bitsonly=false),
(name="Base.RefValue{Any}", f=Ref{Any}, N=1, mutable=true, typed=false, bitsonly=false),
(name="Core.Box", f=Core.Box, N=1, mutable=true, typed=false, bitsonly=false),
(name="mutable struct{Any}", f=MutableWrapper{Any}, N=1, mutable=true, typed=false, bitsonly=false),
(name = "Array{Any}", f = (x -> Any[x]), N = 1, mutable = true, typed = false, bitsonly = false),
(name = "Base.RefValue{Any}", f = Ref{Any}, N = 1, mutable = true, typed = false, bitsonly = false),
(name = "Core.Box", f = Core.Box, N = 1, mutable = true, typed = false, bitsonly = false),
(name = "mutable struct{Any}", f = MutableWrapper{Any}, N = 1, mutable = true, typed = false, bitsonly = false),

(name="Tuple{X,Y}", f=tuple, N=2, mutable=false, typed=true, bitsonly=false),
(name="@NamedTuple{x::X,y::Y}", f=(NamedTuple{(:x, :y)} tuple), N=2, mutable=false, typed=true, bitsonly=false),
(name="struct{X,Y}", f=DualWrapper, N=2, mutable=false, typed=true, bitsonly=false),
(name = "Tuple{X,Y}", f = tuple, N = 2, mutable = false, typed = true, bitsonly = false),
(name = "@NamedTuple{x::X,y::Y}", f = (NamedTuple{(:x, :y)} tuple), N = 2, mutable = false, typed = true, bitsonly = false),
(name = "struct{X,Y}", f = DualWrapper, N = 2, mutable = false, typed = true, bitsonly = false),

(name="@NamedTuple{x,y::Y}", f=((x, y) -> @NamedTuple{x,y::typeof(y)}((x, y))), N=2, mutable=false, typed=:partial, bitsonly=false),
(name="struct{Any,Y}", f=DualWrapper{Any}, N=2, mutable=false, typed=:partial, bitsonly=false),
(name = "@NamedTuple{x,y::Y}", f = ((x, y) -> @NamedTuple{x,y::typeof(y)}((x, y))), N = 2, mutable = false, typed = :partial, bitsonly = false),
(name = "struct{Any,Y}", f = DualWrapper{Any}, N = 2, mutable = false, typed = :partial, bitsonly = false),

(name="@NamedTuple{x,y}", f=(@NamedTuple{x,y} tuple), N=2, mutable=false, typed=false, bitsonly=false),
(name="struct{Any}", f=DualWrapper{Any,Any}, N=2, mutable=false, typed=false, bitsonly=false),
(name = "@NamedTuple{x,y}", f = (@NamedTuple{x,y} tuple), N = 2, mutable = false, typed = false, bitsonly = false),
(name = "struct{Any}", f = DualWrapper{Any,Any}, N = 2, mutable = false, typed = false, bitsonly = false),

(name="mutable struct{X,Y}", f=MutableDualWrapper, N=2, mutable=true, typed=true, bitsonly=false),
(name = "mutable struct{X,Y}", f = MutableDualWrapper, N = 2, mutable = true, typed = true, bitsonly = false),

(name="Array{promote_type(X,Y)}", f=((x, y) -> [x, y]), N=2, mutable=true, typed=:promoted, bitsonly=false),
(name="mutable struct{Any,Y}", f=MutableDualWrapper{Any}, N=2, mutable=true, typed=:partial, bitsonly=false),
(name = "Array{promote_type(X,Y)}", f = ((x, y) -> [x, y]), N = 2, mutable = true, typed = :promoted, bitsonly = false),
(name = "mutable struct{Any,Y}", f = MutableDualWrapper{Any}, N = 2, mutable = true, typed = :partial, bitsonly = false),

(name="Array{Any}", f=((x, y) -> Any[x, y]), N=2, mutable=true, typed=false, bitsonly=false),
(name="mutable struct{Any,Any}", f=MutableDualWrapper{Any,Any}, N=2, mutable=true, typed=false, bitsonly=false),
(name = "Array{Any}", f = ((x, y) -> Any[x, y]), N = 2, mutable = true, typed = false, bitsonly = false),
(name = "mutable struct{Any,Any}", f = MutableDualWrapper{Any,Any}, N = 2, mutable = true, typed = false, bitsonly = false),

# StaticArrays extension
(name="SVector{1,X}", f=(SVector{1} tuple), N=1, mutable=false, typed=true, bitsonly=false),
(name="SVector{1,Any}", f=(SVector{1,Any} tuple), N=1, mutable=false, typed=false, bitsonly=false),
(name="MVector{1,X}", f=(MVector{1} tuple), N=1, mutable=true, typed=true, bitsonly=false),
(name="MVector{1,Any}", f=(MVector{1,Any} tuple), N=1, mutable=true, typed=false, bitsonly=false),
(name="SVector{2,promote_type(X,Y)}", f=(SVector{2} tuple), N=2, mutable=false, typed=:promoted, bitsonly=false),
(name="SVector{2,Any}", f=(SVector{2,Any} tuple), N=2, mutable=false, typed=false, bitsonly=false),
(name="MVector{2,promote_type(X,Y)}", f=(MVector{2} tuple), N=2, mutable=true, typed=:promoted, bitsonly=false),
(name="MVector{2,Any}", f=(MVector{2,Any} tuple), N=2, mutable=true, typed=false, bitsonly=false),
(name = "SVector{1,X}", f = (SVector{1} tuple), N = 1, mutable = false, typed = true, bitsonly = false),
(name = "SVector{1,Any}", f = (SVector{1,Any} tuple), N = 1, mutable = false, typed = false, bitsonly = false),
(name = "MVector{1,X}", f = (MVector{1} tuple), N = 1, mutable = true, typed = true, bitsonly = false),
(name = "MVector{1,Any}", f = (MVector{1,Any} tuple), N = 1, mutable = true, typed = false, bitsonly = false),
(name = "SVector{2,promote_type(X,Y)}", f = (SVector{2} tuple), N = 2, mutable = false, typed = :promoted, bitsonly = false),
(name = "SVector{2,Any}", f = (SVector{2,Any} tuple), N = 2, mutable = false, typed = false, bitsonly = false),
(name = "MVector{2,promote_type(X,Y)}", f = (MVector{2} tuple), N = 2, mutable = true, typed = :promoted, bitsonly = false),
(name = "MVector{2,Any}", f = (MVector{2,Any} tuple), N = 2, mutable = true, typed = false, bitsonly = false),

# GPUArrays extension
(name="JLArray{X}", f=(x -> JLArray([x])), N=1, mutable=true, typed=true, bitsonly=true),
(name="JLArray{promote_type(X,Y)}", f=((x, y) -> JLArray([x, y])), N=2, mutable=true, typed=:promoted, bitsonly=true),
#! format: on
(name = "JLArray{X}", f = (x -> JLArray([x])), N = 1, mutable = true, typed = true, bitsonly = true),
(name = "JLArray{promote_type(X,Y)}", f = ((x, y) -> JLArray([x, y])), N = 2, mutable = true, typed = :promoted, bitsonly = true),
]
#! format: on

@static if VERSION < v"1.11-"
else
_memory(x::Vector) = Memory{eltype(x)}(x)
#! format: off
push!(
wrappers,
#! format: off
(name="Memory{X}", f=(x -> _memory([x])), N=1, mutable=true, typed=true, bitsonly=false),
(name="Memory{Any}", f=(x -> _memory(Any[x])), N=1, mutable=true, typed=false, bitsonly=false),
(name="Memory{promote_type(X,Y)}", f=((x, y) -> _memory([x, y])), N=2, mutable=true, typed=:promoted, bitsonly=false),
(name="Memory{Any}", f=((x, y) -> _memory(Any[x, y])), N=2, mutable=true, typed=false, bitsonly=false),
#! format: on
(name = "Memory{X}", f = (x -> _memory([x])), N = 1, mutable = true, typed = true, bitsonly = false),
(name = "Memory{Any}", f = (x -> _memory(Any[x])), N = 1, mutable = true, typed = false, bitsonly = false),
(name = "Memory{promote_type(X,Y)}", f = ((x, y) -> _memory([x, y])), N = 2, mutable = true, typed = :promoted, bitsonly = false),
(name = "Memory{Any}", f = ((x, y) -> _memory(Any[x, y])), N = 2, mutable = true, typed = false, bitsonly = false),
)
#! format: on
end

function test_make_zero()
Expand Down Expand Up @@ -438,15 +438,14 @@ function test_make_zero()
end
end
end
#! format: off
@testset "copy_if_inactive $value" for (value, args, kwargs) in [
#! format: off
("unspecified", (), (;)),
("= false", (Val(false),), (;)),
("= false (kwarg)", (), (; copy_if_inactive=Val(false))),
("= true", (Val(true),), (;)),
("= true (kwarg)", (), (; copy_if_inactive=Val(true))),
#! format: on
]
("unspecified", (), (;)),
("= false", (Val(false),), (;)),
("= false (kwarg)", (), (; copy_if_inactive = Val(false))),
("= true", (Val(true),), (;)),
("= true (kwarg)", (), (; copy_if_inactive = Val(true))),
]
a = [1.0]
w = Any[a, inactivearr, inactivearr]
w_makez = make_zero(w, args...; kwargs...)
Expand All @@ -467,6 +466,7 @@ function test_make_zero()
@test w_makez[2] === inactivearr # correct value/type/identity
end
end
#! format: on
end
@testset "heterogeneous containers" begin
scalars, scalarsz = oneunit.(scalartypes), zero.(scalartypes)
Expand All @@ -475,11 +475,12 @@ function test_make_zero()
items = (inactivetup..., scalars..., wraps..., mwraps...)
itemsz = (inactivetup..., scalarsz..., wrapsz..., mwrapsz...)
labels = Symbol.("i" .* string.(1:length(items)))
#! format: off
@testset "$name" for (name, c, cz) in [
("Tuple", Tuple(items), Tuple(itemsz)),
("NamedTuple", NamedTuple(labels .=> items), NamedTuple(labels .=> itemsz)),
("Array", collect(items), collect(itemsz)),
]
("Tuple", Tuple(items), Tuple(itemsz)),
("NamedTuple", NamedTuple(labels .=> items), NamedTuple(labels .=> itemsz)),
("Array", collect(items), collect(itemsz)),
]
c_makez = make_zero(c)
@test typeof(c_makez) === typeof(c) # correct type
@test all(typeof(czj) === typeof(cj) for (czj, cj) in zip(c_makez, c)) # correct type
Expand All @@ -488,6 +489,7 @@ function test_make_zero()
@test all(cj === itj for (cj, itj) in zip(c, items)) # no mutation of original
@test all(m.x == oneunit(m.x) for m in mwraps) # no mutation of original
end
#! format: on
end
@testset "heterogeneous float arrays" begin
b1r, b2r = big"1.0", big"2.0"
Expand Down Expand Up @@ -802,15 +804,17 @@ function test_make_zero!()
items = (inactivetup..., mwraps...)
itemsz = (inactivetup..., mwrapsz...)
labels = Symbol.("i" .* string.(1:length(items)))
#! format: off
@testset "$name" for (name, c, cz) in [
("Tuple", Tuple(items), Tuple(itemsz)),
("NamedTuple", NamedTuple(labels .=> items), NamedTuple(labels .=> itemsz)),
("Array", collect(items), collect(itemsz)),
]
("Tuple", Tuple(items), Tuple(itemsz)),
("NamedTuple", NamedTuple(labels .=> items), NamedTuple(labels .=> itemsz)),
("Array", collect(items), collect(itemsz)),
]
make_zero!(c)
@test all(cj === itj for (cj, itj) in zip(c, items)) # preserved identities
@test c == cz # correct value
end
#! format: on
end
@testset "heterogeneous float arrays" begin
b1r, b2r = big"1.0", big"2.0"
Expand Down

0 comments on commit 95cf652

Please sign in to comment.