From 7f9dbc37dd7803aabe0dfec86f0828951a6a4518 Mon Sep 17 00:00:00 2001 From: Denis-Cosmin NUTIU Date: Sun, 27 Oct 2024 11:49:53 +0200 Subject: [PATCH] add unit tests --- src/line.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/line.rs b/src/line.rs index 53c7b08..b758048 100644 --- a/src/line.rs +++ b/src/line.rs @@ -17,6 +17,7 @@ impl Default for MissingLineIndicator { } /// The line enum models a file line. +#[derive(PartialEq, Debug)] pub(crate) enum Line { /// MatchedLine represents a line that matches when comparing the files. /// @@ -102,3 +103,36 @@ pub fn compare_lines(left_text: &str, right_text: &str) -> Vec { }) .collect() } + +#[cfg(test)] +mod test { + use super::*; + use crate::line::Line::{DifferingLine, MatchedLine}; + + #[test] + fn it_should_compare_one_matched_line() { + let lines = compare_lines("asd", "asd"); + assert_eq!(lines, vec![MatchedLine(1, String::from("asd"))]) + } + + #[test] + fn it_should_compare_one_differing_line() { + let lines = compare_lines("asd", "basd"); + assert_eq!( + lines, + vec![DifferingLine(1, String::from("asd"), String::from("basd"))] + ) + } + + #[test] + fn it_should_compare_one_matching_and_one_differing_line() { + let lines = compare_lines("one\ntwo", "zero\ntwo"); + assert_eq!( + lines, + vec![ + DifferingLine(1, String::from("one"), String::from("zero")), + MatchedLine(2, String::from("two")) + ] + ) + } +}