]> git.lizzy.rs Git - rust.git/blobdiff - src/rustfmt_diff.rs
Add test for trailing newline in diff.
[rust.git] / src / rustfmt_diff.rs
index 858fb876f6e2aa3a693d6dde9a3125bde1dc2551..c2dac6c041689d3a6e3c36780c4b8056008a6cab 100644 (file)
@@ -13,7 +13,7 @@
 use std::collections::VecDeque;
 use std::io;
 use term;
-use utils::iscolored;
+use utils::use_colored_tty;
 
 #[derive(Debug, PartialEq)]
 pub enum DiffLine {
@@ -102,7 +102,7 @@ pub fn print_diff<F>(diff: Vec<Mismatch>, get_section_title: F, color: Color)
     F: Fn(u32) -> String,
 {
     match term::stdout() {
-        Some(ref t) if iscolored(color) && t.supports_color() => {
+        Some(ref t) if use_colored_tty(color) && t.supports_color() => {
             print_diff_fancy(diff, get_section_title, term::stdout().unwrap())
         }
         _ => print_diff_basic(diff, get_section_title),
@@ -234,4 +234,20 @@ fn diff_zerocontext() {
             ]
         );
     }
+
+    #[test]
+    fn diff_trailing_newline() {
+        let src = "one\ntwo\nthree\nfour\nfive";
+        let dest = "one\ntwo\nthree\nfour\nfive\n";
+        let diff = make_diff(src, dest, 1);
+        assert_eq!(
+            diff,
+            vec![
+                Mismatch {
+                    line_number: 5,
+                    lines: vec![Context("five".into()), Expected("".into())],
+                },
+            ]
+        );
+    }
 }