@@ -17,6 +17,35 @@ using Test, BlockArrays
17
17
@test blocks (mortar (matrix_blocks)) === matrix_blocks
18
18
end
19
19
20
+ @testset " blocks::BlockMatrix{::MyString}" begin
21
+ # test printing with ANSI escape sequences & textwidth(::Char) ≠ 1
22
+ struct MyString
23
+ s:: String
24
+ end
25
+ function Base. show (io:: IO , x:: MyString )
26
+ if all (isnumeric, x. s)
27
+ printstyled (io, x. s; bold= true , color= :green )
28
+ elseif all (isascii, x. s)
29
+ printstyled (io, x. s, color= :red )
30
+ print (io, " ascii!" )
31
+ else
32
+ print (io, x. s)
33
+ end
34
+ end
35
+
36
+ B = BlockArray (undef_blocks, Matrix{MyString}, [1 ,2 ], [1 ,2 ])
37
+ B[Block (1 ), Block (1 )] = [MyString (" abc" );;]
38
+ B[Block (1 ), Block (2 )] = [MyString (" 123" ) MyString (" γ" );]
39
+ B[Block (2 ), Block (1 )] = [MyString (" γ" ); MyString (" 1" );;]
40
+ B[Block (2 ), Block (2 )] = [MyString (" ⛵⛵⛵⛵⛵" ) MyString (" x" ); MyString (" ⛵⛵⛵" ) MyString (" 4" )]
41
+
42
+ strip_ansi (s) = reduce (* , filter (c-> ! (c isa Base. ANSIDelimiter),
43
+ map (last, Base. ANSIIterator (s))))
44
+ reference_str = " 2×2-blocked 3×3 BlockMatrix{$(@__MODULE__ ) .MyString}:\n \e [31mabc\e [39m ascii! │ \e [32m\e [1m123\e [22m\e [39m γ \n ────────────┼──────────────────────\n γ │ ⛵⛵⛵⛵⛵ \e [31mx\e [39m ascii!\n \e [32m\e [1m1\e [22m\e [39m │ ⛵⛵⛵ \e [32m\e [1m4\e [22m\e [39m "
45
+ @test strip_ansi (sprint (show, " text/plain" , B; context= stdout )) == strip_ansi (reference_str)
46
+ @test strip_ansi (sprint (show, " text/plain" , B)) == strip_ansi (reference_str)
47
+ end
48
+
20
49
@testset " blocks(::BlockedVector)" begin
21
50
v0 = rand (3 )
22
51
vb = BlockedArray (v0, [1 , 2 ])
0 commit comments