1
use crate::ast::Expr;
2
use crate::runtime::Value;
3

            
4
use super::{format_expr, format_runtime_value};
5

            
6
8
fn sym(name: &str) -> Expr {
7
8
    Expr::Symbol(name.into())
8
8
}
9

            
10
#[test]
11
1
fn nil_and_the_empty_list_print_as_nil() {
12
1
    assert_eq!(format_expr(&Expr::Nil), "nil");
13
1
    assert_eq!(format_expr(&Expr::List(vec![])), "nil");
14
1
    assert_eq!(format_runtime_value(&Value::Nil), "nil");
15
1
}
16

            
17
#[test]
18
1
fn a_cons_chain_ending_in_nil_prints_as_a_proper_list() {
19
1
    assert_eq!(format_expr(&Expr::cons(sym("A"), Expr::Nil)), "(A)");
20
1
    assert_eq!(
21
1
        format_expr(&Expr::cons(sym("A"), Expr::cons(sym("B"), Expr::Nil))),
22
        "(A B)"
23
    );
24
1
}
25

            
26
#[test]
27
1
fn a_cons_chain_ending_in_an_atom_keeps_its_dot() {
28
1
    assert_eq!(format_expr(&Expr::cons(sym("A"), sym("B"))), "(A . B)");
29
1
    assert_eq!(
30
1
        format_expr(&Expr::cons(sym("A"), Expr::cons(sym("B"), sym("C")))),
31
        "(A B . C)"
32
    );
33
1
}