-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_prettyexpr.jl
43 lines (35 loc) · 934 Bytes
/
test_prettyexpr.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module TestPrettyExpr
using Test
using InitialValues: prettyexpr, def_impl, disambiguate_impl
parseall(code) = Meta.parse("begin $code end")
roundtrip(code::AbstractString) = prettyexpr(parseall(code))
roundtrip(ex::Expr) = parseall(prettyexpr(ex))
isalnn(x) = x isa LineNumberNode
normalize(x) = x
function normalize(x::Expr)
args = normalize.(filter(!isalnn, x.args))
if x.head == :block && length(args) == 1
return args[1]
end
return Expr(x.head, args...)
end
eq(x, y) = normalize(x) == normalize(y)
@testset "$label" for (label, ex) in [
(
label = "f(x) = x",
ex = :(f(x) = x),
),
(
label = "def_impl",
ex = def_impl(:op, :x, :y),
),
(
label = "disambiguate_impl",
ex = disambiguate_impl(:op, :RightType, :x),
),
]
code = prettyexpr(ex)
@test roundtrip(code) === code
@test eq(roundtrip(ex), ex)
end
end # module