@@ -2001,6 +2001,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20012001 types : & Vec < Type > ,
20022002 column_names : Option < & Vec < ColumnName > > ,
20032003 actual_output : & Vec < String > ,
2004+ multiline : bool ,
20042005 ) {
20052006 buf. append_header ( input, expected_output, column_names) ;
20062007
@@ -2013,20 +2014,46 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20132014 buf. append ( "\n " ) ;
20142015 }
20152016
2016- if row. len ( ) <= 1 {
2017- buf. append ( & row. iter ( ) . join ( " " ) ) ;
2017+ if row. len ( ) == 0 {
2018+ // nothing to do
2019+ } else if row. len ( ) == 1 {
2020+ // If there is only one column, then there is no need for space
2021+ // substitution, so we only do newline substitution.
2022+ if multiline {
2023+ buf. append ( & row[ 0 ] ) ;
2024+ } else {
2025+ buf. append ( & row[ 0 ] . replace ( '\n' , "⏎" ) )
2026+ }
20182027 } else {
2019- buf. append ( & row. iter ( ) . map ( |col| col. replace ( ' ' , "␠" ) ) . join ( " " ) ) ;
2028+ // Substitute spaces with ␠ to avoid mistaking the spaces in the result
2029+ // values with spaces that separate columns.
2030+ buf. append (
2031+ & row. iter ( )
2032+ . map ( |col| {
2033+ let mut col = col. replace ( ' ' , "␠" ) ;
2034+ if !multiline {
2035+ col = col. replace ( '\n' , "⏎" ) ;
2036+ }
2037+ col
2038+ } )
2039+ . join ( " " ) ,
2040+ ) ;
20202041 }
20212042 }
20222043 // In standard mode, output each value on its own line,
20232044 // and ignore row boundaries.
2045+ // No need to substitute spaces, because every value (not row) is on a separate
2046+ // line. But we do need to substitute newlines.
20242047 Mode :: Standard => {
20252048 for ( j, col) in row. iter ( ) . enumerate ( ) {
20262049 if i != 0 || j != 0 {
20272050 buf. append ( "\n " ) ;
20282051 }
2029- buf. append ( col) ;
2052+ buf. append ( & if multiline {
2053+ col. clone ( )
2054+ } else {
2055+ col. replace ( '\n' , "⏎" )
2056+ } ) ;
20302057 }
20312058 }
20322059 }
@@ -2048,6 +2075,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20482075 output_str : expected_output,
20492076 types,
20502077 column_names,
2078+ multiline,
20512079 ..
20522080 } ) ,
20532081 ..
@@ -2065,6 +2093,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20652093 types,
20662094 column_names. as_ref ( ) ,
20672095 actual_output,
2096+ * multiline,
20682097 ) ;
20692098 }
20702099 (
@@ -2075,6 +2104,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20752104 output : Output :: Values ( _) ,
20762105 output_str : expected_output,
20772106 types,
2107+ multiline,
20782108 ..
20792109 } ) ,
20802110 ..
@@ -2093,6 +2123,7 @@ pub async fn rewrite_file(runner: &mut Runner<'_>, filename: &Path) -> Result<()
20932123 types,
20942124 Some ( actual_column_names) ,
20952125 actual_output,
2126+ * multiline,
20962127 ) ;
20972128 }
20982129 (
0 commit comments