//! Unit tests for identifier and object name parsing within expressions.

use crate::{Expr, escape_identifier};

#[test]
fn escaper_escapes() {
    assert_eq!(escape_identifier("hello"), r#""hello""#);
    assert_eq!(escape_identifier("hello world"), r#""hello world""#);
    assert_eq!(
        escape_identifier(r#""hello" "world""#),
        r#""""hello"" ""world""""#
    );
}

#[test]
fn qualified_obj_name_parses() {
    assert_eq!(
        Expr::try_from(r#""""Hello"", World! 四十二".deep_thought"#),
        Ok(Expr::ObjName(vec![
            r#""Hello", World! 四十二"#.to_owned(),
            "deep_thought".to_owned(),
        ])),
    );
}

#[test]
fn misquoted_ident_fails_to_parse() {
    assert!(Expr::try_from(r#""Hello, "World!""#).is_err());
}

#[test]
fn unquoted_ident_lowercased() {
    assert_eq!(
        Expr::try_from("HeLlO_WoRlD"),
        Ok(Expr::ObjName(vec!["hello_world".to_owned()])),
    );
}
