use std::sync::Arc;

use super::{
    parser::{RawStr, Token, TokenType},
    PathNode, PathNodeRef, Span,
};

#[test]
const fn should_be_send_and_sync() {
    const fn f<T: Send + Sync>() {}

    f::<PathNode<'_>>();
    f::<PathNodeRef<'_>>();
}

#[test]
fn should_display_path() {
    let root = Arc::new(PathNode::Root);
    let path_a = Arc::new(PathNode::Array {
        parent: Arc::clone(&root),
        index: 1,
    });
    let path_b = Arc::new(PathNode::Object {
        parent: Arc::clone(&path_a),
        key: r#""name""#.into(),
    });
    let path_c = Arc::new(PathNode::Object {
        parent: Arc::clone(&path_b),
        key: r#""gene""#.into(),
    });

    assert_eq!(*root, "$");
    assert_eq!(*path_a, "$.1");
    assert_eq!(*path_b, "$.1.name");
    assert_eq!(*path_c, "$.1.name.gene");
}

impl<'buf> From<&'buf str> for RawStr<'buf> {
    #[track_caller]
    fn from(s: &'buf str) -> Self {
        RawStr::from_quoted_str(
            s,
            Token {
                kind: TokenType::String,
                span: Span::default(),
            },
        )
        .unwrap()
    }
}
