use super::{parse, walk};

#[test]
fn should_resolve_to_source_json() {
    const JSON: &str = r#"{
    "name": "David Byrne",
    "hobbies": ["song writing", "thinking about society"]
}"#;

    let doc = parse(JSON.into()).unwrap();

    let mut walk = walk::DepthFirst::from_doc(&doc);

    let root = walk.next().unwrap();
    assert_eq!(root.source_json_value(), JSON);

    let field_name = walk.next().unwrap();
    assert_eq!(field_name.source_json_value(), r#""David Byrne""#);

    let field_hobbies = walk.next().unwrap();
    assert_eq!(
        field_hobbies.source_json_value(),
        r#"["song writing", "thinking about society"]"#
    );

    let hobbies_one = walk.next().unwrap();
    assert_eq!(hobbies_one.source_json_value(), r#""song writing""#);
    assert_eq!(hobbies_one.source_json_value(), r#""song writing""#);

    let hobbies_two = walk.next().unwrap();
    assert_eq!(
        hobbies_two.source_json_value(),
        r#""thinking about society""#
    );
    assert_eq!(
        hobbies_two.source_json_value(),
        r#""thinking about society""#
    );
}
