@@ -732,6 +732,11 @@ mod tests {
732732 config
733733 }
734734
735+ /// `insta` ignores whitespace in the beginning or end of a snapshot
736+ fn surround < S : AsRef < str > > ( text : S ) -> String {
737+ format ! ( "|{}|" , text. as_ref( ) )
738+ }
739+
735740 #[ test]
736741 fn test_plaintext_formatter ( ) {
737742 // Test that PlainTextFormatter ignores labels.
@@ -857,7 +862,8 @@ mod tests {
857862 formatter. pop_label ( ) . unwrap ( ) ;
858863 write ! ( formatter, " after " ) . unwrap ( ) ;
859864 drop ( formatter) ;
860- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @" before [38;5;2m inside [39m after " ) ;
865+ insta:: assert_snapshot!( surround( String :: from_utf8( output) . unwrap( ) ) ,
866+ @"| before [38;5;2m inside [39m after |" ) ;
861867 }
862868
863869 #[ test]
@@ -937,7 +943,8 @@ mod tests {
937943 write ! ( formatter, " not bold again " ) . unwrap ( ) ;
938944 formatter. pop_label ( ) . unwrap ( ) ;
939945 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" ) ;
946+ insta:: assert_snapshot!( surround( String :: from_utf8( output) . unwrap( ) ) ,
947+ @"|[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|" ) ;
941948 }
942949
943950 #[ test]
@@ -960,7 +967,8 @@ mod tests {
960967 formatter. pop_label ( ) . unwrap ( ) ;
961968 write ! ( formatter, "after" ) . unwrap ( ) ;
962969 drop ( formatter) ;
963- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @"before[38;5;1mfirst[39m[38;5;2msecond[39mafter" ) ;
970+ insta:: assert_snapshot!( surround( String :: from_utf8( output) . unwrap( ) ) ,
971+ @"|before[38;5;1mfirst[39m[38;5;2msecond[39mafter|" ) ;
964972 }
965973
966974 #[ test]
@@ -977,7 +985,8 @@ mod tests {
977985 write ! ( formatter, "\x1b [1mnot actually bold\x1b [0m" ) . unwrap ( ) ;
978986 formatter. pop_label ( ) . unwrap ( ) ;
979987 drop ( formatter) ;
980- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @"[38;5;1m␛[1mnot actually bold␛[0m[39m" ) ;
988+ insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) ,
989+ @"[38;5;1m␛[1mnot actually bold␛[0m[39m" ) ;
981990 }
982991
983992 #[ test]
@@ -1004,8 +1013,8 @@ mod tests {
10041013 formatter. pop_label ( ) . unwrap ( ) ;
10051014 write ! ( formatter, " after outer " ) . unwrap ( ) ;
10061015 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 " ) ;
1016+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) ,
1017+ @"| before outer [38;5;4m before inner [38;5;2m inside inner [38;5;4m after inner [39m after outer | " ) ;
10091018 }
10101019
10111020 #[ test]
@@ -1026,8 +1035,8 @@ mod tests {
10261035 write ! ( formatter, " not colored " ) . unwrap ( ) ;
10271036 formatter. pop_label ( ) . unwrap ( ) ;
10281037 drop ( formatter) ;
1029- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) ,
1030- @" not colored [38;5;2m colored [39m not colored " ) ;
1038+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) ,
1039+ @"| not colored [38;5;2m colored [39m not colored | " ) ;
10311040 }
10321041
10331042 #[ test]
@@ -1129,8 +1138,8 @@ mod tests {
11291138 formatter. pop_label ( ) . unwrap ( ) ;
11301139 formatter. pop_label ( ) . unwrap ( ) ;
11311140 drop ( formatter) ;
1132- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) ,
1133- @"[38;5;2m hello [39m" ) ;
1141+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) ,
1142+ @"| [38;5;2m hello [39m| " ) ;
11341143 }
11351144
11361145 #[ test]
@@ -1149,7 +1158,7 @@ mod tests {
11491158 formatter. pop_label ( ) . unwrap ( ) ;
11501159 formatter. pop_label ( ) . unwrap ( ) ;
11511160 drop ( formatter) ;
1152- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @" hello " ) ;
1161+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) , @"| hello | " ) ;
11531162 }
11541163
11551164 #[ test]
@@ -1177,8 +1186,8 @@ mod tests {
11771186 write ! ( formatter, " a2 " ) . unwrap ( ) ;
11781187 formatter. pop_label ( ) . unwrap ( ) ;
11791188 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" ) ;
1189+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) ,
1190+ @"| [38;5;1m a1 [38;5;2m b1 [38;5;3m c [38;5;2m b2 [38;5;1m a2 [39m| " ) ;
11821191 }
11831192
11841193 #[ test]
@@ -1241,9 +1250,10 @@ mod tests {
12411250 write ! ( writer, "Message" ) . unwrap ( ) ;
12421251 writeln ! ( writer, " continues" ) . unwrap ( ) ;
12431252 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- "### ) ;
1253+ insta:: assert_snapshot!( surround( String :: from_utf8( output) . unwrap( ) ) , @r"
1254+ |[38;5;1mHeading: [38;5;2mMessage[39m[38;5;2m continues[39m
1255+ |
1256+ " ) ;
12471257 }
12481258
12491259 #[ test]
@@ -1259,7 +1269,7 @@ mod tests {
12591269 write ! ( writer, "" ) . unwrap ( ) ;
12601270 write ! ( writer, "" ) . unwrap ( ) ;
12611271 drop ( formatter) ;
1262- insta:: assert_snapshot!( String :: from_utf8( output) . unwrap( ) , @"Heading: " ) ;
1272+ insta:: assert_snapshot!( surround ( String :: from_utf8( output) . unwrap( ) ) , @"| Heading: | " ) ;
12631273 }
12641274
12651275 #[ test]
@@ -1273,8 +1283,8 @@ mod tests {
12731283 write ! ( recorder, " outer2 " ) . unwrap ( ) ;
12741284
12751285 insta:: assert_snapshot!(
1276- str :: from_utf8( recorder. data( ) ) . unwrap( ) ,
1277- @" outer1 inner1 inner2 outer2 " ) ;
1286+ surround ( str :: from_utf8( recorder. data( ) ) . unwrap( ) ) ,
1287+ @"| outer1 inner1 inner2 outer2 | " ) ;
12781288
12791289 // Replayed output should be labeled.
12801290 let config = config_from_string ( r#" colors.inner = "red" "# ) ;
@@ -1283,8 +1293,8 @@ mod tests {
12831293 recorder. replay ( & mut formatter) . unwrap ( ) ;
12841294 drop ( formatter) ;
12851295 insta:: assert_snapshot!(
1286- String :: from_utf8( output) . unwrap( ) ,
1287- @" outer1 [38;5;1m inner1 inner2 [39m outer2 " ) ;
1296+ surround ( String :: from_utf8( output) . unwrap( ) ) ,
1297+ @"| outer1 [38;5;1m inner1 inner2 [39m outer2 | " ) ;
12881298
12891299 // Replayed output should be split at push/pop_label() call.
12901300 let mut output: Vec < u8 > = vec ! [ ] ;
@@ -1297,8 +1307,8 @@ mod tests {
12971307 . unwrap ( ) ;
12981308 drop ( formatter) ;
12991309 insta:: assert_snapshot!(
1300- String :: from_utf8( output) . unwrap( ) ,
1301- @"<< outer1 >>[38;5;1m<< inner1 inner2 >>[39m<< outer2 >>" ) ;
1310+ surround ( String :: from_utf8( output) . unwrap( ) ) ,
1311+ @"| << outer1 >>[38;5;1m<< inner1 inner2 >>[39m<< outer2 >>| " ) ;
13021312 }
13031313
13041314 #[ test]
@@ -1319,7 +1329,8 @@ mod tests {
13191329 recorder. replay ( & mut formatter) . unwrap ( ) ;
13201330 drop ( formatter) ;
13211331 insta:: assert_snapshot!(
1322- String :: from_utf8( output) . unwrap( ) , @" outer1 [38;5;1m inner1 inner2 [39m outer2 " ) ;
1332+ surround( String :: from_utf8( output) . unwrap( ) ) ,
1333+ @"| outer1 [38;5;1m inner1 inner2 [39m outer2 |" ) ;
13231334
13241335 let mut output: Vec < u8 > = vec ! [ ] ;
13251336 let mut formatter = ColorFormatter :: for_config ( & mut output, & config, false ) . unwrap ( ) ;
@@ -1333,6 +1344,7 @@ mod tests {
13331344 . unwrap ( ) ;
13341345 drop ( formatter) ;
13351346 insta:: assert_snapshot!(
1336- String :: from_utf8( output) . unwrap( ) , @" outer1 [38;5;1m inner1 inner2 [39m outer2 " ) ;
1347+ surround( String :: from_utf8( output) . unwrap( ) ) ,
1348+ @"| outer1 [38;5;1m inner1 inner2 [39m outer2 |" ) ;
13371349 }
13381350}
0 commit comments