Skip to content

Commit b2fc524

Browse files
committed
nicer testing
1 parent 312b2aa commit b2fc524

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/patch/cst.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ end
113113

114114
sourcewalk(f, file) = sourcemap(x -> postwalk(f, x), file)
115115

116+
textmap(f, text) = sourcemap(f, SourceFile("", text))
117+
116118
textwalk(f, text) = sourcewalk(f, SourceFile("", text))

test/patch.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using MacroTools: textwalk, @capture, isexpr
1+
using MacroTools: textmap, textwalk, @capture, isexpr
22
using Test
33

4+
testrep(ex, text) = textmap(_ -> Expr(:file, ex), text)
5+
46
# Replacement
57

68
@test textwalk(x -> x==:a ? :b : x, "a*2") == "b*2"
@@ -19,20 +21,20 @@ using Test
1921

2022
# Insertion
2123

22-
@test textwalk(x -> isexpr(x, :call) ? :(f(a,b)) : x, "f(a)") == "f(a, b)"
23-
@test textwalk(x -> isexpr(x, :call) ? :(f(a)) : x, "f()") == "f(a)"
24+
@test testrep(:(f(a,b)), "f(a)") == "f(a, b)"
25+
@test testrep(:(f(a)), "f()") == "f(a)"
2426

25-
@test textwalk(x -> isexpr(x, :call) ? :(f(a, b, c)) : x, "f(a, b)") == "f(a, b, c)"
26-
@test textwalk(x -> isexpr(x, :call) ? :(f(a, c, b)) : x, "f(a, b)") == "f(a, c, b)"
27-
@test textwalk(x -> isexpr(x, :call) ? :(f(c, a, b)) : x, "f(a, b)") == "f(c, a, b)"
28-
@test textwalk(x -> isexpr(x, :call) ? :(c(f, a, b)) : x, "f(a, b)") == "c(f, a, b)"
27+
@test testrep(:(f(a, b, c)), "f(a, b)") == "f(a, b, c)"
28+
@test testrep(:(f(a, c, b)), "f(a, b)") == "f(a, c, b)"
29+
@test testrep(:(f(c, a, b)), "f(a, b)") == "f(c, a, b)"
30+
@test testrep(:(c(f, a, b)), "f(a, b)") == "c(f, a, b)"
2931

3032
# Deletion
3133

32-
@test textwalk(x -> isexpr(x, :call) ? :(f()) : x, "f(a)") == "f()"
33-
@test textwalk(x -> isexpr(x, :call) ? :(f()) : x, "f(a,)") == "f()"
34+
@test testrep(:(f()), "f(a)") == "f()"
35+
@test testrep(:(f()), "f(a,)") == "f()"
3436

35-
@test textwalk(x -> isexpr(x, :call) ? :(f(a, b)) : x, "f(a, b, c)") == "f(a, b)"
36-
@test textwalk(x -> isexpr(x, :call) ? :(f(a, c)) : x, "f(a, b, c)") == "f(a, c)"
37-
@test textwalk(x -> isexpr(x, :call) ? :(f(b, c)) : x, "f(a, b, c)") == "f(b, c)"
38-
@test textwalk(x -> isexpr(x, :call) ? :(a(b, c)) : x, "f(a, b, c)") == "a(b, c)"
37+
@test testrep(:(f(a, b)), "f(a, b, c)") == "f(a, b)"
38+
@test testrep(:(f(a, c)), "f(a, b, c)") == "f(a, c)"
39+
@test testrep(:(f(b, c)), "f(a, b, c)") == "f(b, c)"
40+
@test testrep(:(a(b, c)), "f(a, b, c)") == "a(b, c)"

0 commit comments

Comments
 (0)