Lines
100 %
Functions
Branches
use super::compile_upcase_string;
use crate::ast::Expr;
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
use crate::error::Error;
use crate::reader::Reader;
use crate::runtime::SymbolTable;
fn upcase(arg: &str) -> Result<bool, Error> {
let mut ctx = CompileContext::new_with_host_fns(&[])?;
let mut emit = FunctionEmitter::new();
let mut symbols = SymbolTable::with_builtins();
let arg = Reader::parse_expr(arg)?;
compile_upcase_string(&mut ctx, &mut emit, &mut symbols, &[arg])?;
Ok(emit.is_reachable())
}
#[test]
fn a_constant_string_folds() {
assert!(upcase("\"a\"").unwrap());
fn a_plain_non_string_stays_a_compile_error() {
assert!(matches!(upcase("1"), Err(Error::Compile(_))));
fn an_effectful_non_string_is_a_compile_error() {
// user decision ISS-087: was the operand's effects, then a runtime TYPE-ERROR.
let err = upcase("(progn (print \"x\") 1)");
assert!(
matches!(&err, Err(Error::Compile(message)) if message == "UPCASE-STRING expects a string, got i32"),
"{err:?}"
);
fn a_wrong_arity_is_an_arity_error() {
let mut ctx = CompileContext::new_with_host_fns(&[]).unwrap();
let err = compile_upcase_string(&mut ctx, &mut emit, &mut symbols, &[Expr::Nil, Expr::Nil]);
assert!(matches!(err, Err(Error::Arity { .. })));