1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
mod parser;
pub use parser::{parse, parse_with_resolver, Node, Statement, AST};

mod preprocess;
pub use preprocess::PreProcessor;

mod report;
pub use report::Report;

pub mod render;
pub use render::{RenderOptions, Renderer};

pub mod rapify;
pub mod simplify;

fn get_ident(stmt: Statement) -> Result<String, crate::ArmaLintError> {
    Ok(match stmt {
        Statement::Ident(val) => val,
        Statement::IdentArray(val) => val,
        Statement::InternalStr(val) => val,
        Statement::Processed(val, _) => get_ident(*val)?,
        Statement::Defined(val, _) => get_ident(val.statement)?,
        _ => panic!("get ident wasn't given ident: {:#?}", stmt),
    })
}

// Tests

#[test]
fn basic_statement_ast() {
    let content = r###"something = true;"###;
    let ast = parse("basic.cpp", content).unwrap();
    assert_eq!(
        ast.config.statement,
        Statement::Config(vec![Node {
            file: "basic.cpp".to_string(),
            start: (0, (1, 1)),
            end: (16, (1, 17)),
            line: "something = true".to_string(),
            statement: Statement::Property {
                ident: Box::new(Node {
                    file: "basic.cpp".to_string(),
                    start: (0, (1, 1)),
                    end: (9, (1, 10)),
                    line: "something".to_string(),
                    statement: Statement::Ident("something".to_string())
                }),
                value: Box::new(Node {
                    file: "basic.cpp".to_string(),
                    start: (12, (1, 13)),
                    end: (16, (1, 17)),
                    line: "true".to_string(),
                    statement: Statement::Bool(true)
                }),
                expand: false
            }
        }])
    );
}