diff --git a/Cargo.lock b/Cargo.lock index e43ab0d95d9..c5a39eb221a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ name = "rustfmt" version = "0.2.1" dependencies = [ - "diff 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "diff 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -30,7 +30,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "diff" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] diff --git a/Cargo.toml b/Cargo.toml index 17bd20a0561..78b359de177 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ unicode-segmentation = "0.1.2" regex = "0.1.41" term = "0.2.11" strings = "0.0.1" -diff = "0.1.7" +diff = "0.1.8" syntex_syntax = "0.23.0" log = "0.3.2" env_logger = "0.3.1" diff --git a/src/rustfmt_diff.rs b/src/rustfmt_diff.rs index 8c20b8f5a0f..4bb858a6b30 100644 --- a/src/rustfmt_diff.rs +++ b/src/rustfmt_diff.rs @@ -2,12 +2,14 @@ use std::collections::VecDeque; use diff; use term; +#[derive(Debug, PartialEq)] pub enum DiffLine { Context(String), Expected(String), Resulting(String), } +#[derive(Debug, PartialEq)] pub struct Mismatch { pub line_number: u32, pub lines: Vec, diff --git a/tests/system.rs b/tests/system.rs index 6d3c817256c..d6f1ba806f5 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -273,3 +273,17 @@ fn get_target(file_name: &str, target: Option<&str>, write_mode: WriteMode) -> S file_name.to_owned() } } + +#[test] +fn rustfmt_diff_make_diff_tests() { + let diff = make_diff("a\nb\nc\nd", "a\ne\nc\nd", 3); + assert_eq!(diff, + vec![Mismatch { + line_number: 1, + lines: vec![DiffLine::Context("a".into()), + DiffLine::Resulting("b".into()), + DiffLine::Expected("e".into()), + DiffLine::Context("c".into()), + DiffLine::Context("d".into())], + }]); +}