Lines
100 %
Functions
Branches
use super::{SCRATCH_SIZE, scratch_pieces};
#[test]
fn a_short_message_is_one_piece() {
assert_eq!(scratch_pieces("hello"), vec!["hello"]);
}
fn an_empty_message_still_reaches_the_host() {
assert_eq!(scratch_pieces(""), vec![""]);
fn a_long_message_is_staged_in_pieces_that_fit() {
let text = "A".repeat(2 * SCRATCH_SIZE + 104);
let pieces = scratch_pieces(&text);
assert_eq!(
pieces.iter().map(|p| p.len()).collect::<Vec<_>>(),
vec![SCRATCH_SIZE, SCRATCH_SIZE, 104]
);
assert_eq!(pieces.concat(), text);
fn a_piece_never_splits_a_character() {
let text = format!("{}é{}", "a".repeat(SCRATCH_SIZE - 1), "b".repeat(10));
assert_eq!(pieces[0].len(), SCRATCH_SIZE - 1);
assert!(pieces.iter().all(|p| p.len() <= SCRATCH_SIZE));
fn compile_eval_error(src: &str) -> String {
let program = crate::reader::Reader::parse(src).expect("source parses");
let mut compiler = crate::compiler::Compiler::new();
let mut symbols = crate::runtime::SymbolTable::with_builtins();
match compiler.compile_eval_with_type(&program, &mut symbols) {
Ok(_) => String::new(),
Err(err) => err.to_string(),
fn printing_a_closure_compiles_on_every_surface() {
for name in ["print", "display", "debug"] {
compile_eval_error(&format!("(let ((f (lambda (x) x))) ({name} f))")),
""
fn printing_a_condition_compiles_on_every_surface() {
compile_eval_error(&format!(
"({name} (handler-case (error 'boom \"m\") (t (e) e)))"
)),
fn printing_a_folded_closure_list_compiles() {
compile_eval_error("(let ((n 0)) (print (list (lambda () (setf n (+ n 1)) n))))"),
fn printing_a_runtime_value_compiles() {
compile_eval_error("(defvar g 0) (setf g 3) (print \"n=\" g)"),
fn printing_a_folded_bare_lambda_compiles() {
for source in [
"(print (lambda (x) x))",
"(print 1 (lambda (x) x))",
"(print (if t (lambda (x) x) nil))",
"(let ((f (print (lambda (x) (+ x 1))))) (funcall f 2))",
"(defvar *h* (print (lambda (x) (+ x 1))))",
"(defparameter *f* (print (lambda (x) (+ x 1))))",
"(defun mk () (print (lambda (x) (+ x 1)))) (defvar *k* (mk))",
"(defvar *g* (lambda (x) x)) (defvar *h* (print (lambda (x y) y)))",
"(length (list (print (lambda (x) x))))",
] {
assert_eq!(compile_eval_error(source), "", "{source}");
fn a_printed_constant_list_beyond_the_index_range_is_a_static_error() {
let message = compile_eval_error("(print (list (+ 1073741823 1) 1))");
assert!(message.contains("outside the index range"), "{message}");
assert_eq!(compile_eval_error("(print (quote (1073741823 1)))"), "");