]> git.lizzy.rs Git - rust.git/blobdiff - crates/test_utils/src/lib.rs
translate \n -> \r\n on the way out
[rust.git] / crates / test_utils / src / lib.rs
index ea99ac062933c3337fd73b184dd51afd528880c2..816d01f09ef3dae729c69e9f2d88c6d160ff8026 100644 (file)
@@ -134,21 +134,25 @@ macro_rules! flush {
             }
         };
     };
+
     let margin = fixture
         .lines()
         .filter(|it| it.trim_start().starts_with("//-"))
         .map(|it| it.len() - it.trim_start().len())
         .next()
         .expect("empty fixture");
-    let lines = fixture.lines().filter_map(|line| {
-        if line.len() >= margin {
-            assert!(line[..margin].trim().is_empty());
-            Some(&line[margin..])
-        } else {
-            assert!(line.trim().is_empty());
-            None
-        }
-    });
+
+    let lines = fixture
+        .split('\n') // don't use `.lines` to not drop `\r\n`
+        .filter_map(|line| {
+            if line.len() >= margin {
+                assert!(line[..margin].trim().is_empty());
+                Some(&line[margin..])
+            } else {
+                assert!(line.trim().is_empty());
+                None
+            }
+        });
 
     for line in lines {
         if line.starts_with("//-") {