@@ -53,7 +53,11 @@ macro test_repr(x)
53
53
# this is a macro instead of function so we can avoid getting useful backtraces :)
54
54
return :(test_repr ($ (esc (x))))
55
55
end
56
- function test_repr (x:: String )
56
+ macro weak_test_repr (x)
57
+ # this is a macro instead of function so we can avoid getting useful backtraces :)
58
+ return :(test_repr ($ (esc (x)), true ))
59
+ end
60
+ function test_repr (x:: String , remove_linenums:: Bool = false )
57
61
# Note: We can't just compare x1 and x2 because interpolated
58
62
# strings get converted to string Exprs by the first show().
59
63
# This could produce a few false positives, but until string
@@ -64,14 +68,13 @@ function test_repr(x::String)
64
68
x2 = eval (Meta. parse (repr (x1)))
65
69
x3 = eval (Meta. parse (repr (x2)))
66
70
if ! (x1 == x2 == x3)
67
- # error(string(
68
- print (string (
69
- " repr test failed:" ,
71
+ error (string (
72
+ " \n repr test (Rule 2) failed:" ,
70
73
" \n original: " , x,
71
74
" \n\n preparsed: " , x1, " \n " , sprint (dump, x1),
72
75
" \n\n parsed: " , x2, " \n " , sprint (dump, x2),
73
- " \n\n reparsed: " , x3, " \n " , sprint (dump, x3)
74
- ))
76
+ " \n\n reparsed: " , x3, " \n " , sprint (dump, x3),
77
+ " \n\n " ))
75
78
end
76
79
@test x1 == x2 == x3
77
80
@@ -80,19 +83,47 @@ function test_repr(x::String)
80
83
x6 = eval (Base. remove_linenums! (Meta. parse (repr (x5))))
81
84
if ! (x4 == x5 == x6)
82
85
error (string (
83
- " repr test without line numbers failed:" ,
86
+ " \n repr test (Rule 2) without line numbers failed:" ,
84
87
" \n original: " , x,
85
88
" \n\n preparsed: " , x4, " \n " , sprint (dump, x4),
86
89
" \n\n parsed: " , x5, " \n " , sprint (dump, x5),
87
- " \n\n reparsed: " , x6, " \n " , sprint (dump, x6)
88
- ))
90
+ " \n\n reparsed: " , x6, " \n " , sprint (dump, x6),
91
+ " \n\n " ))
89
92
end
90
93
@test x4 == x5 == x6
91
94
92
95
@test Base. remove_linenums! (x1) ==
93
96
Base. remove_linenums! (x2) ==
94
97
Base. remove_linenums! (x3) ==
95
98
x4 == x5 == x6
99
+
100
+ if isa (x1, Expr) && remove_linenums
101
+ if Base. remove_linenums! (Meta. parse (string (x1))) != x1
102
+ error (string (
103
+ " \n string test (Rule 1) failed:" ,
104
+ " \n original: " , x,
105
+ " \n\n preparsed: " , x1, " \n " , sprint (dump, x4),
106
+ " \n\n string(preparsed): " , string (x1),
107
+ " \n\n Base.remove_linenums!(Meta.parse(string(preparsed))): " ,
108
+ Base. remove_linenums! (Meta. parse (string (x1))), " \n " ,
109
+ sprint (dump, Base. remove_linenums! (Meta. parse (string (x1)))),
110
+ " \n\n " ))
111
+ end
112
+ @test Base. remove_linenums! (Meta. parse (string (x1))) == x1
113
+ elseif isa (x1, Expr)
114
+ if Meta. parse (string (x1)) != x1
115
+ error (string (
116
+ " \n string test (Rule 1) failed:" ,
117
+ " \n original: " , x,
118
+ " \n\n preparsed: " , x1, " \n " , sprint (dump, x4),
119
+ " \n\n string(preparsed): " , string (x1),
120
+ " \n\n Meta.parse(string(preparsed)): " ,
121
+ Meta. parse (string (x1)), " \n " ,
122
+ sprint (dump, Meta. parse (string (x1))),
123
+ " \n\n " ))
124
+ end
125
+ @test Meta. parse (string (x1)) == x1
126
+ end
96
127
end
97
128
98
129
# primitive types
207
238
208
239
209
240
# control structures (shamelessly stolen from base/bitarray.jl)
210
- @test_repr """ mutable struct BitArray{N} <: AbstractArray{Bool, N}
241
+ @weak_test_repr """ mutable struct BitArray{N} <: AbstractArray{Bool, N}
211
242
# line meta
212
243
chunks::Vector{UInt64}
213
244
# line meta
254
285
end
255
286
end"""
256
287
257
- @test_repr """ function copy_chunks(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, pos_s::Integer, numbits::Integer)
288
+ @weak_test_repr """ function copy_chunks(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, pos_s::Integer, numbits::Integer)
258
289
# line meta
259
290
if numbits == 0
260
291
# line meta
@@ -333,13 +364,13 @@ end"""
333
364
return
334
365
end"""
335
366
336
- @test_repr """ if a
367
+ @weak_test_repr """ if a
337
368
# line meta
338
369
b
339
370
end
340
371
"""
341
372
342
- @test_repr """ if a
373
+ @weak_test_repr """ if a
343
374
# line meta
344
375
b
345
376
elseif c
348
379
end
349
380
"""
350
381
351
- @test_repr """ if a
382
+ @weak_test_repr """ if a
352
383
# line meta
353
384
b
354
385
elseif c
360
391
end
361
392
"""
362
393
363
- @test_repr """ if a
394
+ @weak_test_repr """ if a
364
395
# line meta
365
396
b
366
397
elseif c
372
403
end
373
404
"""
374
405
375
- @test_repr """ f(x, y) do z, w
406
+ @weak_test_repr """ f(x, y) do z, w
376
407
# line meta
377
408
a
378
409
# line meta
379
410
b
380
411
end
381
412
"""
382
413
383
- @test_repr """ f(x, y) do z
414
+ @weak_test_repr """ f(x, y) do z
384
415
# line meta
385
416
a
386
417
# line meta
441
472
442
473
@test_repr " [1 2 3; 4 5 6; 7 8 9]'"
443
474
444
- @test_repr " baremodule X
475
+ @weak_test_repr " baremodule X
445
476
# line meta
446
477
# line meta
447
478
import ...B.c
@@ -450,7 +481,7 @@ import D
450
481
# line meta
451
482
import B.C.D.E.F.g
452
483
end"
453
- @test_repr " baremodule Y
484
+ @weak_test_repr " baremodule Y
454
485
# line meta
455
486
# line meta
456
487
export A, B, C
@@ -837,11 +868,11 @@ test_mt(show_f5, "show_f5(A::AbstractArray{T,N}, indices::Vararg{$Int,N})")
837
868
@test_repr " macro m end"
838
869
@test sprint (show, Expr (:macro , Expr (:call , :m , :ex ), Expr (:block , :m ))) ==
839
870
" :(macro m(ex)\n m\n end)"
840
- @test_repr """ macro identity(ex)
871
+ @weak_test_repr """ macro identity(ex)
841
872
# line meta
842
873
esc(ex)
843
874
end"""
844
- @test_repr """ macro m(a,b)
875
+ @weak_test_repr """ macro m(a,b)
845
876
# line meta
846
877
quote
847
878
# line meta
@@ -897,7 +928,7 @@ end""")) ==
897
928
\$\$ x
898
929
end
899
930
end)"""
900
- @test_repr """
931
+ @weak_test_repr """
901
932
quote
902
933
#= none:2 =#
903
934
quote
@@ -907,7 +938,7 @@ quote
907
938
end"""
908
939
909
940
# fallback printing + nested quotes and unquotes
910
- @test_repr repr (Expr (:block , LineNumberNode (0 , :none ),
941
+ @weak_test_repr repr (Expr (:block , LineNumberNode (0 , :none ),
911
942
Expr (:exotic_head , Expr (:$ , :x ))))
912
943
@test_repr repr (Expr (:exotic_head , Expr (:call , :+ , 1 , Expr (:quote , Expr (:$ , Expr (:$ , :y ))))))
913
944
@test_repr repr (Expr (:quote , Expr (:$ , Expr (:exotic_head , Expr (:call , :+ , 1 , Expr (:$ , :y ))))))
@@ -945,20 +976,20 @@ end"""
945
976
946
977
# nested quotes and blocks
947
978
@test_repr " Expr(:quote, Expr(:block, :a, :b))"
948
- @test_repr repr (Expr (:quote , Expr (:block , LineNumberNode (0 , :none ), :a , LineNumberNode (0 , :none ), :b )))
979
+ @weak_test_repr repr (Expr (:quote , Expr (:block , LineNumberNode (0 , :none ), :a , LineNumberNode (0 , :none ), :b )))
949
980
@test repr (Expr (:quote , Expr (:block , :a , :b ))) ==
950
981
" :(quote
951
982
a
952
983
b
953
984
end)"
954
985
@test_repr " Expr(:quote, Expr(:block, :a))"
955
- @test_repr repr (Expr (:quote , Expr (:block , LineNumberNode (0 , :none ), :a )))
986
+ @weak_test_repr repr (Expr (:quote , Expr (:block , LineNumberNode (0 , :none ), :a )))
956
987
@test repr (Expr (:quote , Expr (:block , :a ))) ==
957
988
" :(quote
958
989
a
959
990
end)"
960
991
@test_repr " Expr(:quote, Expr(:block, :(a + b)))"
961
- @test_repr repr (Expr (:quote , Expr (:block , LineNumberNode (0 , :none ), :(a + b))))
992
+ @weak_test_repr repr (Expr (:quote , Expr (:block , LineNumberNode (0 , :none ), :(a + b))))
962
993
@test repr (Expr (:quote , Expr (:block , :(a + b)))) ==
963
994
" :(quote
964
995
a + b
@@ -976,12 +1007,12 @@ end"""
976
1007
# unquoting
977
1008
@test_repr " \$ y"
978
1009
@test_repr " \$\$ y"
979
- @test_repr """
1010
+ @weak_test_repr """
980
1011
begin
981
1012
# line meta
982
1013
\$ y
983
1014
end"""
984
- @test_repr """
1015
+ @weak_test_repr """
985
1016
begin
986
1017
# line meta
987
1018
\$\$ y
@@ -1223,7 +1254,7 @@ test_repr("(+).:-")
1223
1254
test_repr (" (!).:~" )
1224
1255
test_repr (" a.:(begin
1225
1256
#= none:3 =#
1226
- end)" )
1257
+ end)" , true )
1227
1258
test_repr (" a.:(=)" )
1228
1259
test_repr (" a.:(:)" )
1229
1260
test_repr (" (:).a" )
0 commit comments