Skip to content

Commit 558becb

Browse files
committed
Remove coveralls and add tests
1 parent 7c945df commit 558becb

5 files changed

Lines changed: 41 additions & 20 deletions

File tree

.github/workflows/CI.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,3 @@ jobs:
3838
- uses: codecov/codecov-action@v3
3939
with:
4040
files: lcov.info
41-
- uses: julia-actions/julia-uploadcoveralls@v1
42-
env:
43-
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![Build Status](https://github.com/devmotion/SimpleUnPack.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/devmotion/SimpleUnPack.jl/actions/workflows/CI.yml?query=branch%3Amain)
44
[![Coverage](https://codecov.io/gh/devmotion/SimpleUnPack.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/devmotion/SimpleUnPack.jl)
5-
[![Coverage](https://coveralls.io/repos/github/devmotion/SimpleUnPack.jl/badge.svg?branch=main)](https://coveralls.io/github/devmotion/SimpleUnPack.jl?branch=main)
65
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
76

87
This package provides the `@unpack` macro for destructuring properties.

src/SimpleUnPack.jl

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,62 @@ module SimpleUnPack
33
export @unpack
44

55
"""
6-
@unpack a, b, ... = rhs
6+
@unpack a, b, ... = x
77
8-
Destructure properties `a`, `b`, ... of `rhs` into variables of the same name.
8+
Destructure properties `a`, `b`, ... of `x` into variables of the same name.
99
10-
The behaviour of the macro is equivalent to `(; a, b, ...) = rhs` which was introduced in [Julia#39285](https://github.com/JuliaLang/julia/pull/39285) and is available in Julia >= 1.7.0-DEV.364.
10+
The behaviour of the macro is equivalent to `(; a, b, ...) = x` which was introduced in [Julia#39285](https://github.com/JuliaLang/julia/pull/39285) and is available in Julia >= 1.7.0-DEV.364.
1111
"""
12-
macro unpack(args::Expr)
12+
macro unpack(args)
1313
return unpack(args)
1414
end
1515

16-
function unpack(args::Expr)
16+
function unpack(args)
1717
# Extract properties and RHS
1818
if !Meta.isexpr(args, :(=), 2)
19-
throw(ArgumentError("`@unpack` can only be applied to expressions of the form `a, b = c`"))
19+
throw(
20+
ArgumentError(
21+
"`@unpack` can only be applied to expressions of the form `a, b, ... = x`"
22+
),
23+
)
2024
end
2125
lhs, rhs = args.args
2226
properties = if lhs isa Symbol
2327
[lhs]
24-
elseif Meta.isexpr(lhs, :tuple) && !isempty(lhs.args) && all(x -> x isa Symbol, lhs.args)
28+
elseif Meta.isexpr(lhs, :tuple) &&
29+
!isempty(lhs.args) &&
30+
all(x -> x isa Symbol, lhs.args)
2531
lhs.args
2632
else
27-
throw(ArgumentError("`@unpack` can only be applied to expressions of the form `a, b = c`"))
33+
throw(
34+
ArgumentError(
35+
"`@unpack` can only be applied to expressions of the form `a, b, ... = x`",
36+
),
37+
)
2838
end
2939

3040
if VERSION >= v"1.7.0-DEV.364"
3141
# Fall back to destructuring in Base when available:
3242
# https://github.com/JuliaLang/julia/pull/39285
33-
return Expr(:(=), Expr(:tuple, Expr(:parameters, (esc(p) for p in properties)...)), esc(rhs))
43+
return Expr(
44+
:(=), Expr(:tuple, Expr(:parameters, (esc(p) for p in properties)...)), esc(rhs)
45+
)
3446
else
3547
@gensym object
3648
block = Expr(:block)
3749
for p in properties
38-
push!(block.args, Expr(:(=), esc(p), Expr(:call, :getproperty, esc(object), QuoteNode(p))))
50+
push!(
51+
block.args,
52+
Expr(:(=), esc(p), Expr(:call, :getproperty, esc(object), QuoteNode(p))),
53+
)
3954
end
40-
return quote
41-
$(esc(object)) = $(esc(rhs)) # In case the RHS is an expression
42-
$block
43-
$(esc(object)) # Return evaluation of rhs to ensure the behaviour is the same as (; ...) = rhs
44-
end |> Base.remove_linenums!
55+
return Base.remove_linenums!(
56+
quote
57+
$(esc(object)) = $(esc(rhs)) # In case the RHS is an expression
58+
$block
59+
$(esc(object)) # Return evaluation of rhs to ensure the behaviour is the same as (; ...) = rhs
60+
end,
61+
)
4562
end
4663
end
4764

test/runtests.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,12 @@ end
6161
@test @inferred(f(Struct(42, 1.0, "z"))) == (42, 1.0)
6262
@test @inferred(f(Property(42))) == (42, 1.0)
6363
end
64-
end
64+
65+
@testset "Errors" begin
66+
d = (; x=42, y=1.0)
67+
@test_throws ArgumentError @macroexpand @unpack d
68+
@test_throws ArgumentError @macroexpand @unpack (; x=42, y=1.0)
69+
@test_throws ArgumentError @macroexpand @unpack x, y, (; x=42, y=1.0)
70+
@test_throws ArgumentError @macroexpand @unpack x, 1 = (; x=42, y=1.0)
71+
end
72+
end

0 commit comments

Comments
 (0)