pub fn display_diff(expected: &String, actual: &String, path: &String) -> String {
    let expected_body = Value::from_str(expected).unwrap();
    let actual_body = Value::from_str(actual).unwrap();
    let path = path.split('.').skip(2);
    let expected_fragment = match walk_json(&expected_body, &mut path.clone()) {
        Some(json) => format!("{:?}", serde_json::to_string_pretty(&json)),
        None => s!("")
    };
    let actual_fragment = match walk_json(&actual_body, &mut path.clone()) {
        Some(json) => format!("{:?}", serde_json::to_string_pretty(&json)),
        None => s!("")
    };
    let changeset = Changeset::new(&expected_fragment, &actual_fragment, "\n");
    let mut output = String::new();
    for change in changeset.diffs {
        match change {
            Difference::Same(ref x) => output.push_str(&format!(" {}\n", x)),
            Difference::Add(ref x) => output.push_str(&Green.paint(format!("+{}\n", x)).to_string()),
            Difference::Rem(ref x) => output.push_str(&Red.paint(format!("-{}\n", x)).to_string())
        }
    }
    output
}
/// Returns a diff of the expected versus the actual JSON bodies, focusing on a particular path
Returns a diff of the expected versus the actual JSON bodies, focusing on a particular path
Returns a diff of the expected versus the actual JSON bodies focusing on a particular path
pub fn display_diff(expected: &String, actual: &String, path: &String) -> String {
    let expected_body = Value::from_str(expected).unwrap();
    let actual_body = Value::from_str(actual).unwrap();
    let path = path.split('.').skip(2);
    let expected_fragment = match walk_json(&expected_body, &mut path.clone()) {
        Some(json) => format!("{:?}", serde_json::to_string_pretty(&json)),
        None => s!("")
    };
    let actual_fragment = match walk_json(&actual_body, &mut path.clone()) {
        Some(json) => format!("{:?}", serde_json::to_string_pretty(&json)),
        None => s!("")
    };
    let changeset = Changeset::new(&expected_fragment, &actual_fragment, "\n");
    let mut output = String::new();
    for change in changeset.diffs {
        match change {
            Difference::Same(ref x) => output.push_str(&format!(" {}\n", x)),
            Difference::Add(ref x) => output.push_str(&Green.paint(format!("+{}\n", x)).to_string()),
            Difference::Rem(ref x) => output.push_str(&Red.paint(format!("-{}\n", x)).to_string())
        }
    }
    output
}
pub fn display_diff ( expected : & String , actual : & String , path : & String ) -> String { let expected_body = Value :: from_str ( expected ) . unwrap ( ) ; let actual_body = Value :: from_str ( actual ) . unwrap ( ) ; let path = path . split ( '.' ) . skip ( 2 ) ; let expected_fragment = match walk_json ( & expected_body , & mut path . clone ( ) ) { Some ( json ) => format ! ( " " serde_json to_string_pretty ( json ) ) , None => s ! ( " " ) } ; let actual_fragment = match walk_json ( & actual_body , & mut path . clone ( ) ) { Some ( json ) => format ! ( " " serde_json to_string_pretty ( json ) ) , None => s ! ( " " ) } ; let changeset = Changeset :: new ( & expected_fragment , & actual_fragment , " \n " ) ; let mut output = String :: new ( ) ; for change in changeset . diffs { match change { Difference :: Same ( ref x ) => output . push_str ( & format ! ( " \n " x ) ) , Difference :: Add ( ref x ) => output . push_str ( & Green . paint ( format ! ( " \n " x ) ) . to_string ( ) ) , Difference :: Rem ( ref x ) => output . push_str ( & Red . paint ( format ! ( " \n " x ) ) . to_string ( ) ) } } output }
Returns a diff of the expected versus the actual JSON bodies, focusing on a particular path
Returns a diff of the expected versus the actual JSON bodies focusing on a particular path
expected
&String
actual
&String
path
&String
expected
&String
actual
&String
path
&String