@@ -8,13 +8,22 @@ using TensorKitSectors
88@isdefined (TestSetup) || include (" ../setup.jl" )
99using . TestSetup
1010
11- parse_show (x) = Meta. parse (sprint (show, x; context = (:module => @__MODULE__ )))
11+ """
12+ eval_show(x)
13+
14+ Use `show` to generate a string representation of `x`, then parse and evaluate the resulting expression.
15+ """
16+ function eval_show (x)
17+ str = sprint (show, x; context = (:module => @__MODULE__ ))
18+ ex = Meta. parse (str)
19+ return eval (ex)
20+ end
1221
1322@timedtestset " Fields" begin
1423 @test isa (ℝ, Field)
1524 @test isa (ℂ, Field)
16- @test eval ( parse_show (ℝ) ) == ℝ
17- @test eval ( parse_show (ℂ) ) == ℂ
25+ @test eval_show (ℝ ) == ℝ
26+ @test eval_show (ℂ ) == ℂ
1827 @test ℝ ⊆ ℝ
1928 @test ℝ ⊆ ℂ
2029 @test ℂ ⊆ ℂ
5564@timedtestset " ElementarySpace: CartesianSpace" begin
5665 d = 2
5766 V = ℝ^ d
58- @test eval ( parse_show (V) ) == V
59- @test eval ( parse_show ( typeof (V) )) == typeof (V)
67+ @test eval_show (V ) == V
68+ @test eval_show ( typeof (V)) == typeof (V)
6069 @test isa (V, VectorSpace)
6170 @test isa (V, ElementarySpace)
6271 @test isa (InnerProductStyle (V), HasInnerProduct)
99108@timedtestset " ElementarySpace: ComplexSpace" begin
100109 d = 2
101110 V = ℂ^ d
102- @test eval ( parse_show (V) ) == V
103- @test eval ( parse_show (V ' ) ) == V'
104- @test eval ( parse_show ( typeof (V) )) == typeof (V)
111+ @test eval_show (V ) == V
112+ @test eval_show (V ' ) == V'
113+ @test eval_show ( typeof (V)) == typeof (V)
105114 @test isa (V, VectorSpace)
106115 @test isa (V, ElementarySpace)
107116 @test isa (InnerProductStyle (V), HasInnerProduct)
@@ -151,10 +160,10 @@ end
151160@timedtestset " ElementarySpace: GeneralSpace" begin
152161 d = 2
153162 V = GeneralSpace {ℂ} (d)
154- @test eval ( parse_show (V) ) == V
155- @test eval ( parse_show ( dual (V) )) == dual (V)
156- @test eval ( parse_show ( conj (V) )) == conj (V)
157- @test eval ( parse_show ( typeof (V) )) == typeof (V)
163+ @test eval_show (V ) == V
164+ @test eval_show ( dual (V)) == dual (V)
165+ @test eval_show ( conj (V)) == conj (V)
166+ @test eval_show ( typeof (V)) == typeof (V)
158167 @test ! isdual (V)
159168 @test isdual (V' )
160169 @test ! isdual (conj (V))
185194 end
186195 V = GradedSpace (gen)
187196 @test eval (Meta. parse (type_repr (typeof (V)))) == typeof (V)
188- @test eval ( parse_show (V) ) == V
189- @test eval ( parse_show (V ' ) ) == V'
197+ @test eval_show (V ) == V
198+ @test eval_show (V ' ) == V'
190199 @test V' == GradedSpace (gen; dual = true )
191200 @test V == @constinferred GradedSpace (gen... )
192201 @test V' == @constinferred GradedSpace (gen... ; dual = true )
207216 end
208217 @test @constinferred (hash (V)) == hash (deepcopy (V)) != hash (V' )
209218 @test V == GradedSpace (reverse (collect (gen))... )
210- @test eval ( parse_show (V) ) == V
211- @test eval ( parse_show ( typeof (V) )) == typeof (V)
219+ @test eval_show (V ) == V
220+ @test eval_show ( typeof (V)) == typeof (V)
212221 # space with no sectors
213222 @test dim (@constinferred (zerospace (V))) == 0
214223 # space with a single sector
218227 @test @constinferred (zerospace (V)) == GradedSpace (unit (I) => 0 )
219228 # randsector never returns trivial sector, so this cannot error
220229 @test_throws ArgumentError GradedSpace (unit (I) => 1 , randsector (I) => 0 , unit (I) => 3 )
221- @test eval ( parse_show (W) ) == W
230+ @test eval_show (W ) == W
222231 @test isa (V, VectorSpace)
223232 @test isa (V, ElementarySpace)
224233 @test isa (InnerProductStyle (V), HasInnerProduct)
263272@timedtestset " ProductSpace{ℂ}" begin
264273 V1, V2, V3, V4 = ℂ^ 1 , ℂ^ 2 , ℂ^ 3 , ℂ^ 4
265274 P = @constinferred ProductSpace (V1, V2, V3, V4)
266- @test eval ( parse_show (P) ) == P
267- @test eval ( parse_show ( typeof (P) )) == typeof (P)
275+ @test eval_show (P ) == P
276+ @test eval_show ( typeof (P)) == typeof (P)
268277 @test isa (P, VectorSpace)
269278 @test isa (P, CompositeSpace)
270279 @test spacetype (P) == ComplexSpace
@@ -291,11 +300,11 @@ end
291300 @test fuse (flip (V1), V2, flip (V3)) ≅ V1 ⊗ V2 ⊗ V3
292301 @test @constinferred (⊗ (P)) == P
293302 @test @constinferred (⊗ (V1)) == ProductSpace (V1)
294- @test eval ( parse_show ( ⊗ (V1) )) == ⊗ (V1)
303+ @test eval_show ( ⊗ (V1)) == ⊗ (V1)
295304 @test @constinferred (one (V1)) == @constinferred (one (typeof (V1))) ==
296305 @constinferred (one (P)) == @constinferred (one (typeof (P))) ==
297306 ProductSpace {ComplexSpace} (())
298- @test eval ( parse_show ( one (P) )) == one (P)
307+ @test eval_show ( one (P)) == one (P)
299308 @test @constinferred (⊗ (one (P), P)) == P
300309 @test @constinferred (⊗ (P, one (P))) == P
301310 @test @constinferred (⊗ (one (P), one (P))) == one (P)
330339 V1, V2, V3 = SU₂Space (0 => 3 , 1 // 2 => 1 ), SU₂Space (0 => 2 , 1 => 1 ),
331340 SU₂Space (1 // 2 => 1 , 1 => 1 )'
332341 P = @constinferred ProductSpace (V1, V2, V3)
333- @test eval ( parse_show (P) ) == P
334- @test eval ( parse_show ( typeof (P) )) == typeof (P)
342+ @test eval_show (P ) == P
343+ @test eval_show ( typeof (P)) == typeof (P)
335344 @test isa (P, VectorSpace)
336345 @test isa (P, CompositeSpace)
337346 @test spacetype (P) == SU₂Space
409418 @test W == (V3 ⊗ V4 ⊗ V5 → V1 ⊗ V2)
410419 @test W == (V1 ⊗ V2 ← V3 ⊗ V4 ⊗ V5)
411420 @test W' == (V1 ⊗ V2 → V3 ⊗ V4 ⊗ V5)
412- @test eval ( parse_show (W) ) == W
413- @test eval ( parse_show ( typeof (W) )) == typeof (W)
421+ @test eval_show (W ) == W
422+ @test eval_show ( typeof (W)) == typeof (W)
414423 @test spacetype (W) == typeof (V1)
415424 @test sectortype (W) == sectortype (V1)
416425 @test W[1 ] == V1
0 commit comments