@@ -732,6 +732,10 @@ mod tests {
732732 config
733733 }
734734
735+ fn surround < S : AsRef < str > > ( text : S ) -> String {
736+ format ! ( "|{}|" , text. as_ref( ) )
737+ }
738+
735739 #[ test]
736740 fn test_plaintext_formatter ( ) {
737741 // Test that PlainTextFormatter ignores labels.
@@ -857,7 +861,8 @@ mod tests {
857861 formatter. pop_label ( ) . unwrap ( ) ;
858862 write ! ( formatter, " after " ) . unwrap ( ) ;
859863 drop ( formatter) ;
860- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @" before [38;5;2m inside [39m after " ) ;
864+ insta:: assert_snapshot!( surround( String :: from_utf8( output) . unwrap( ) ) ,
865+ @"| before [38;5;2m inside [39m after |" ) ;
861866 }
862867
863868 #[ test]
@@ -937,7 +942,8 @@ mod tests {
937942 write ! ( formatter, " not bold again " ) . unwrap ( ) ;
938943 formatter. pop_label ( ) . unwrap ( ) ;
939944 drop ( formatter) ;
940- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @"[3m[4m[38;5;1m[48;5;4m not bold [1m bold [0m[3m[4m[38;5;1m[48;5;4m not bold again [23m[24m[39m[49m" ) ;
945+ insta:: assert_snapshot!( surround( String :: from_utf8( output) . unwrap( ) ) ,
946+ @"|[3m[4m[38;5;1m[48;5;4m not bold [1m bold [0m[3m[4m[38;5;1m[48;5;4m not bold again [23m[24m[39m[49m|" ) ;
941947 }
942948
943949 #[ test]
@@ -960,7 +966,8 @@ mod tests {
960966 formatter. pop_label ( ) . unwrap ( ) ;
961967 write ! ( formatter, "after" ) . unwrap ( ) ;
962968 drop ( formatter) ;
963- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @"before[38;5;1mfirst[39m[38;5;2msecond[39mafter" ) ;
969+ insta:: assert_snapshot!( surround( String :: from_utf8( output) . unwrap( ) ) ,
970+ @"|before[38;5;1mfirst[39m[38;5;2msecond[39mafter|" ) ;
964971 }
965972
966973 #[ test]
@@ -977,7 +984,8 @@ mod tests {
977984 write ! ( formatter, "\x1b [1mnot actually bold\x1b [0m" ) . unwrap ( ) ;
978985 formatter. pop_label ( ) . unwrap ( ) ;
979986 drop ( formatter) ;
980- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @"[38;5;1m␛[1mnot actually bold␛[0m[39m" ) ;
987+ insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) ,
988+ @"[38;5;1m␛[1mnot actually bold␛[0m[39m" ) ;
981989 }
982990
983991 #[ test]
@@ -1004,8 +1012,8 @@ mod tests {
10041012 formatter. pop_label ( ) . unwrap ( ) ;
10051013 write ! ( formatter, " after outer " ) . unwrap ( ) ;
10061014 drop ( formatter) ;
1007- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) ,
1008- @" before outer [38;5;4m before inner [38;5;2m inside inner [38;5;4m after inner [39m after outer " ) ;
1015+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) ,
1016+ @"| before outer [38;5;4m before inner [38;5;2m inside inner [38;5;4m after inner [39m after outer | " ) ;
10091017 }
10101018
10111019 #[ test]
@@ -1026,8 +1034,8 @@ mod tests {
10261034 write ! ( formatter, " not colored " ) . unwrap ( ) ;
10271035 formatter. pop_label ( ) . unwrap ( ) ;
10281036 drop ( formatter) ;
1029- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) ,
1030- @" not colored [38;5;2m colored [39m not colored " ) ;
1037+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) ,
1038+ @"| not colored [38;5;2m colored [39m not colored | " ) ;
10311039 }
10321040
10331041 #[ test]
@@ -1129,8 +1137,8 @@ mod tests {
11291137 formatter. pop_label ( ) . unwrap ( ) ;
11301138 formatter. pop_label ( ) . unwrap ( ) ;
11311139 drop ( formatter) ;
1132- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) ,
1133- @"[38;5;2m hello [39m" ) ;
1140+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) ,
1141+ @"| [38;5;2m hello [39m| " ) ;
11341142 }
11351143
11361144 #[ test]
@@ -1149,7 +1157,7 @@ mod tests {
11491157 formatter. pop_label ( ) . unwrap ( ) ;
11501158 formatter. pop_label ( ) . unwrap ( ) ;
11511159 drop ( formatter) ;
1152- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @" hello " ) ;
1160+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) , @"| hello | " ) ;
11531161 }
11541162
11551163 #[ test]
@@ -1177,8 +1185,8 @@ mod tests {
11771185 write ! ( formatter, " a2 " ) . unwrap ( ) ;
11781186 formatter. pop_label ( ) . unwrap ( ) ;
11791187 drop ( formatter) ;
1180- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) ,
1181- @"[38;5;1m a1 [38;5;2m b1 [38;5;3m c [38;5;2m b2 [38;5;1m a2 [39m" ) ;
1188+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) ,
1189+ @"| [38;5;1m a1 [38;5;2m b1 [38;5;3m c [38;5;2m b2 [38;5;1m a2 [39m| " ) ;
11821190 }
11831191
11841192 #[ test]
@@ -1241,9 +1249,10 @@ mod tests {
12411249 write ! ( writer, "Message" ) . unwrap ( ) ;
12421250 writeln ! ( writer, " continues" ) . unwrap ( ) ;
12431251 drop ( formatter) ;
1244- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @r###"
1245- [38;5;1mHeading: [38;5;2mMessage[39m[38;5;2m continues[39m
1246- "### ) ;
1252+ insta:: assert_snapshot!( surround( String :: from_utf8( output) . unwrap( ) ) , @r"
1253+ |[38;5;1mHeading: [38;5;2mMessage[39m[38;5;2m continues[39m
1254+ |
1255+ " ) ;
12471256 }
12481257
12491258 #[ test]
@@ -1259,7 +1268,7 @@ mod tests {
12591268 write ! ( writer, "" ) . unwrap ( ) ;
12601269 write ! ( writer, "" ) . unwrap ( ) ;
12611270 drop ( formatter) ;
1262- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @"Heading: " ) ;
1271+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) , @"| Heading: | " ) ;
12631272 }
12641273
12651274 #[ test]
@@ -1273,8 +1282,8 @@ mod tests {
12731282 write ! ( recorder, " outer2 " ) . unwrap ( ) ;
12741283
12751284 insta:: assert_snapshot!(
1276- str :: from_utf8( recorder. data( ) ) . unwrap( ) ,
1277- @" outer1 inner1 inner2 outer2 " ) ;
1285+ surround ( str :: from_utf8( recorder. data( ) ) . unwrap( ) ) ,
1286+ @"| outer1 inner1 inner2 outer2 | " ) ;
12781287
12791288 // Replayed output should be labeled.
12801289 let config = config_from_string ( r#" colors.inner = "red" "# ) ;
@@ -1283,8 +1292,8 @@ mod tests {
12831292 recorder. replay ( & mut formatter) . unwrap ( ) ;
12841293 drop ( formatter) ;
12851294 insta:: assert_snapshot!(
1286- String :: from_utf8( output) . unwrap( ) ,
1287- @" outer1 [38;5;1m inner1 inner2 [39m outer2 " ) ;
1295+ surround ( String :: from_utf8( output) . unwrap( ) ) ,
1296+ @"| outer1 [38;5;1m inner1 inner2 [39m outer2 | " ) ;
12881297
12891298 // Replayed output should be split at push/pop_label() call.
12901299 let mut output: Vec < u8 > = vec ! [ ] ;
@@ -1297,8 +1306,8 @@ mod tests {
12971306 . unwrap ( ) ;
12981307 drop ( formatter) ;
12991308 insta:: assert_snapshot!(
1300- String :: from_utf8( output) . unwrap( ) ,
1301- @"<< outer1 >>[38;5;1m<< inner1 inner2 >>[39m<< outer2 >>" ) ;
1309+ surround ( String :: from_utf8( output) . unwrap( ) ) ,
1310+ @"| << outer1 >>[38;5;1m<< inner1 inner2 >>[39m<< outer2 >>| " ) ;
13021311 }
13031312
13041313 #[ test]
@@ -1319,7 +1328,8 @@ mod tests {
13191328 recorder. replay ( & mut formatter) . unwrap ( ) ;
13201329 drop ( formatter) ;
13211330 insta:: assert_snapshot!(
1322- String :: from_utf8( output) . unwrap( ) , @" outer1 [38;5;1m inner1 inner2 [39m outer2 " ) ;
1331+ surround( String :: from_utf8( output) . unwrap( ) ) ,
1332+ @"| outer1 [38;5;1m inner1 inner2 [39m outer2 |" ) ;
13231333
13241334 let mut output: Vec < u8 > = vec ! [ ] ;
13251335 let mut formatter = ColorFormatter :: for_config ( & mut output, & config, false ) . unwrap ( ) ;
@@ -1333,6 +1343,7 @@ mod tests {
13331343 . unwrap ( ) ;
13341344 drop ( formatter) ;
13351345 insta:: assert_snapshot!(
1336- String :: from_utf8( output) . unwrap( ) , @" outer1 [38;5;1m inner1 inner2 [39m outer2 " ) ;
1346+ surround( String :: from_utf8( output) . unwrap( ) ) ,
1347+ @"| outer1 [38;5;1m inner1 inner2 [39m outer2 |" ) ;
13371348 }
13381349}
0 commit comments