Lines
100 %
Functions
Branches
//! A constant list may hold a struct instance leaf: a fold reads the leaf out
//! of it, and answers no list that holds one.
use super::*;
use crate::ast::Number;
use crate::ast::StructId;
fn holding(items: Vec<Expr>) -> SymbolTable {
let mut symbols = table();
symbols.define(Symbol::new("M", SymbolKind::Variable).with_value(Expr::List(items)));
symbols
}
fn mixed() -> SymbolTable {
holding(vec![
Expr::Number(Number::Index(1)),
Expr::Instance(0, StructId(0)),
Expr::String("s".to_string()),
])
#[test]
fn a_car_of_a_carried_list_folds_to_the_instance_leaf() {
let folded = fold_checked(&mut mixed(), "(car (cdr m))");
assert_eq!(folded, Some(Expr::Instance(0, StructId(0))));
fn a_tail_holding_an_instance_is_compiled() {
assert_eq!(fold_checked(&mut mixed(), "(cdr m)"), None);
fn a_stored_list_is_not_read() {
let mut symbols = mixed();
symbols.set_stored_globals(std::collections::HashSet::from(["M".to_string()]));
assert_eq!(fold_checked(&mut symbols, "(car (cdr m))"), None);