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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use std::ops::{RangeInclusive, Range};

use serde::{Serialize, Deserialize};
use shm_rs::lexer::lexer;
use shm_rs::serializator::serializator;
use shm_rs::static_scheme::init;
use shm_rs::dynamic_scheme::environment;

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct LdActionExec
{
    pub executable: String,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct CommonLevels
{
    pub lvl_a: Vec<Range<i64>>,
    pub lvl_b: Vec<RangeInclusive<i64>>,
    pub action_block: Option<Vec<LdActionExec>>,
    pub action_unblock: Option<Vec<LdActionExec>>,
}

pub fn main()
{
    let mut curdir = std::env::current_dir().unwrap();
    curdir.push("examples/scheme_vector/test_vec1.shm");
    println!("{}", curdir.display());

    let lex = lexer::Lexer::from_file(curdir).unwrap();
    let schm = init::SchemeInit::new().unwrap();

    let res = schm.run(&lex, None).unwrap();

    let resser = res.get("test10").unwrap().clone();

    println!("Static: \n{:?}\n", res);


    let mut curdir = std::env::current_dir().unwrap();
    curdir.push("examples/scheme_vector/test_vec1_data.shm");

    let lex = lexer::Lexer::from_file(curdir).unwrap();

    let dynenv = environment::DynEnvironment::new_root(resser.clone());

    let dynres = environment::DynEnvironment::run(&lex, dynenv).unwrap();

    println!("Dynamic: \n{:?}\n", dynres);

    let ret = serializator::Serialization::serialize(resser, dynres.clone()).unwrap();

    let serialized = serde_json::to_string(&ret).unwrap();


    let tr = 
        CommonLevels
        {
            lvl_a: vec![-2..8, 4..5], 
            lvl_b: vec![-4..=5, -6..=4],
            action_block: 
                Some(
                    vec![
                        LdActionExec{ executable: "test1".to_string()},
                        LdActionExec{ executable: "test2".to_string()},
                    ]
                ),
            action_unblock: None,
        };

    let res = serde_json::to_string(&tr).unwrap();

    println!("control: {}", res);

    let deser: CommonLevels = serde_json::from_str(&serialized).unwrap();

    println!("{:?}", deser);

    if deser != tr 
    {
        panic!("did not match!");
    }
    else
    {
        println!("matched!");
    }
}