use crate::ast::*;
use crate::parser::parse;

#[test]
fn test_nested_identifiers() {
    // In Context - using v2 syntax
    let cmd = parse("get users fields * where metadata.theme = \"dark\"").unwrap();
    if let CageKind::Filter = cmd.cages[0].kind {
        assert_eq!(
            cmd.cages[0].conditions[0].left,
            Expr::Named("metadata.theme".to_string())
        );
        match &cmd.cages[0].conditions[0].value {
            Value::String(s) => assert_eq!(s, "dark"),
            _ => panic!("Expected string value"),
        }
    } else {
        panic!("Expected filter cage");
    }
}

#[test]
fn test_quoted_strings_parse_doubled_quote_escapes() {
    let cmd = parse(r#"get users fields id where name = 'O''Reilly'"#).unwrap();
    assert_eq!(
        cmd.cages[0].conditions[0].value,
        Value::String("O'Reilly".to_string())
    );

    let cmd = parse(r#"get users fields id where quote = "say ""hi""""#).unwrap();
    assert_eq!(
        cmd.cages[0].conditions[0].value,
        Value::String("say \"hi\"".to_string())
    );
}
