1
- using MacroTools: textwalk, @capture , isexpr
1
+ using MacroTools: textmap, textwalk, @capture , isexpr
2
2
using Test
3
3
4
+ testrep (ex, text) = textmap (_ -> Expr (:file , ex), text)
5
+
4
6
# Replacement
5
7
6
8
@test textwalk (x -> x== :a ? :b : x, " a*2" ) == " b*2"
@@ -19,20 +21,20 @@ using Test
19
21
20
22
# Insertion
21
23
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)"
24
26
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)"
29
31
30
32
# Deletion
31
33
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()"
34
36
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