1
use std::sync::{Arc, RwLock};
2

            
3
use conjure_cp_core::ast::{DeclarationKind, Name};
4
use conjure_cp_core::context::Context;
5
use conjure_cp_essence_parser::parse_essence_file_native;
6

            
7
#[test]
8
1
fn parses_find_aux_as_find_auxiliary() {
9
1
    let dir = std::env::temp_dir().join(format!("conjure-oxide-findaux-{}", std::process::id()));
10
1
    let _ = std::fs::remove_dir_all(&dir);
11
1
    std::fs::create_dir_all(&dir).expect("create temp dir");
12
1
    let path = dir.join("model.essence");
13
1
    std::fs::write(
14
1
        &path,
15
1
        "language Essence 1.0\nfindAux a: bool\nfind x: int(1..3)\nsuch that a -> (x = 1)\n",
16
1
    )
17
1
    .expect("write model");
18

            
19
1
    let context = Arc::new(RwLock::new(Context::default()));
20
    let model =
21
1
        parse_essence_file_native(path.to_str().unwrap(), context).expect("parse findAux model");
22

            
23
1
    let _ = std::fs::remove_dir_all(&dir);
24

            
25
1
    let a = model
26
1
        .symbols()
27
1
        .lookup(&Name::user("a"))
28
1
        .expect("a should be declared");
29
1
    let x = model
30
1
        .symbols()
31
1
        .lookup(&Name::user("x"))
32
1
        .expect("x should be declared");
33

            
34
1
    assert!(
35
1
        matches!(
36
1
            &a.kind() as &DeclarationKind,
37
            DeclarationKind::FindAuxiliary(_)
38
        ),
39
        "findAux should parse as FindAuxiliary, got {:?}",
40
        a.kind()
41
    );
42
1
    assert!(
43
1
        matches!(&x.kind() as &DeclarationKind, DeclarationKind::Find(_)),
44
        "find should parse as Find, got {:?}",
45
        x.kind()
46
    );
47
1
    assert!(a.is_find_auxiliary());
48
1
    assert!(!x.is_find_auxiliary());
49
1
}