1
//! 0014 Stage 3.1b (ISS-125): LIST and CONS keep a quoted member's datum, not
2
//! the evaluation wrapper of the quote that produced it.
3

            
4
use crate::ast::Expr;
5
use crate::compiler::expr::eval_value;
6
use crate::reader::Reader;
7
use crate::runtime::SymbolTable;
8

            
9
12
fn form(source: &str) -> Expr {
10
12
    Reader::parse(source)
11
12
        .ok()
12
12
        .and_then(|program| program.exprs.into_iter().next())
13
12
        .unwrap_or(Expr::Nil)
14
12
}
15

            
16
12
fn eval(source: &str) -> Expr {
17
12
    let mut symbols = SymbolTable::with_builtins_for_wasm();
18
12
    eval_value(&mut symbols, &form(source)).unwrap_or(Expr::Nil)
19
12
}
20

            
21
#[test]
22
1
fn list_members_are_data_symbols() {
23
1
    assert_eq!(eval("(list 'a 'b)"), eval("'(a b)"));
24
1
}
25

            
26
#[test]
27
1
fn list_keeps_a_member_list_as_data() {
28
1
    assert_eq!(eval("(list 'let '((b 1)) 'b)"), eval("'(let ((b 1)) b)"));
29
1
}
30

            
31
#[test]
32
1
fn list_keeps_a_quote_that_is_part_of_the_datum() {
33
1
    assert_eq!(eval("(list ''a)"), eval("'('a)"));
34
1
}
35

            
36
#[test]
37
1
fn cons_car_is_a_data_symbol() {
38
1
    assert_eq!(eval("(cons 'quote (list 'b))"), eval("'(quote b)"));
39
1
}
40

            
41
#[test]
42
1
fn cons_onto_a_constant_list_keeps_a_data_member() {
43
1
    assert_eq!(eval("(cons 'a '(b))"), eval("'(a b)"));
44
1
}
45

            
46
#[test]
47
1
fn append_of_lists_with_data_symbols_is_data() {
48
1
    assert_eq!(
49
1
        eval("(append (list 'return-from 'b) (list 9))"),
50
1
        eval("'(return-from b 9)")
51
    );
52
1
}