pub mod common;
pub mod factory;
#[cfg(feature = "myers")]
pub mod myers;
#[cfg(feature = "similar")]
pub mod similar;
#[cfg(test)]
pub mod tests;
pub use common::{Algorithm, ChangeTag, DiffAlgorithm};
#[cfg(feature = "myers")]
pub use myers::MyersDiff;
#[cfg(feature = "similar")]
pub use similar::SimilarDiff;
pub use factory::DiffAlgorithmFactory;
#[cfg(test)]
mod feature_tests {
#[test]
#[cfg(all(feature = "myers", not(feature = "similar")))]
fn test_only_myers_algorithm() {
use crate::{diff_with_algorithm, Algorithm, ArrowsTheme};
use std::io::Cursor;
let old = "The quick brown fox";
let new = "The quick red fox";
let mut buffer = Cursor::new(Vec::new());
let theme = ArrowsTheme::default();
diff_with_algorithm(&mut buffer, old, new, &theme, Algorithm::Myers).unwrap();
let output = String::from_utf8(buffer.into_inner()).expect("Not valid UTF-8");
assert!(output.contains("<The quick brown fox"));
assert!(output.contains(">The quick red fox"));
let mut buffer = Cursor::new(Vec::new());
diff_with_algorithm(&mut buffer, old, new, &theme, Algorithm::Similar).unwrap();
let output = String::from_utf8(buffer.into_inner()).expect("Not valid UTF-8");
assert!(output.contains("<The quick brown fox"));
assert!(output.contains(">The quick red fox"));
}
#[test]
#[cfg(all(feature = "similar", not(feature = "myers")))]
fn test_only_similar_algorithm() {
use crate::{diff_with_algorithm, Algorithm, ArrowsTheme};
use std::io::Cursor;
let old = "The quick brown fox";
let new = "The quick red fox";
let mut buffer = Cursor::new(Vec::new());
let theme = ArrowsTheme::default();
diff_with_algorithm(&mut buffer, old, new, &theme, Algorithm::Similar).unwrap();
let output = String::from_utf8(buffer.into_inner()).expect("Not valid UTF-8");
assert!(output.contains("<The quick brown fox"));
assert!(output.contains(">The quick red fox"));
let mut buffer = Cursor::new(Vec::new());
diff_with_algorithm(&mut buffer, old, new, &theme, Algorithm::Myers).unwrap();
let output = String::from_utf8(buffer.into_inner()).expect("Not valid UTF-8");
assert!(output.contains("<The quick brown fox"));
assert!(output.contains(">The quick red fox"));
}
#[test]
#[cfg(not(any(feature = "myers", feature = "similar")))]
fn test_no_algorithms_available() {
use crate::{diff, diff_with_algorithm, Algorithm, ArrowsTheme};
use std::io::Cursor;
let old = "The quick brown fox";
let new = "The quick red fox";
let mut buffer = Cursor::new(Vec::new());
let theme = ArrowsTheme::default();
diff(&mut buffer, old, new, &theme).unwrap();
let output = String::from_utf8(buffer.into_inner()).expect("Not valid UTF-8");
assert!(output.contains("Error: No diff algorithms are available"));
let mut buffer = Cursor::new(Vec::new());
diff_with_algorithm(&mut buffer, old, new, &theme, Algorithm::Myers).unwrap();
let output = String::from_utf8(buffer.into_inner()).expect("Not valid UTF-8");
assert!(output.contains("Error: No diff algorithms are available"));
}
}