1
//! A constant list may hold a struct instance leaf: a fold reads the leaf out
2
//! of it, and answers no list that holds one.
3

            
4
use super::*;
5
use crate::ast::Number;
6
use crate::ast::StructId;
7

            
8
3
fn holding(items: Vec<Expr>) -> SymbolTable {
9
3
    let mut symbols = table();
10
3
    symbols.define(Symbol::new("M", SymbolKind::Variable).with_value(Expr::List(items)));
11
3
    symbols
12
3
}
13

            
14
3
fn mixed() -> SymbolTable {
15
3
    holding(vec![
16
3
        Expr::Number(Number::Index(1)),
17
3
        Expr::Instance(0, StructId(0)),
18
3
        Expr::String("s".to_string()),
19
3
    ])
20
3
}
21

            
22
#[test]
23
1
fn a_car_of_a_carried_list_folds_to_the_instance_leaf() {
24
1
    let folded = fold_checked(&mut mixed(), "(car (cdr m))");
25
1
    assert_eq!(folded, Some(Expr::Instance(0, StructId(0))));
26
1
}
27

            
28
#[test]
29
1
fn a_tail_holding_an_instance_is_compiled() {
30
1
    assert_eq!(fold_checked(&mut mixed(), "(cdr m)"), None);
31
1
}
32

            
33
#[test]
34
1
fn a_stored_list_is_not_read() {
35
1
    let mut symbols = mixed();
36
1
    symbols.set_stored_globals(std::collections::HashSet::from(["M".to_string()]));
37
1
    assert_eq!(fold_checked(&mut symbols, "(car (cdr m))"), None);
38
1
}