Files
Cagire/tests/forth/map.rs
Raphaël Forment e8cf8c506b
All checks were successful
Deploy Website / deploy (push) Has been skipped
Feat: integrating workshop fixes
2026-03-03 19:46:50 +01:00

56 lines
1002 B
Rust

use crate::harness::{expect_error, expect_int, expect_stack, run};
use cagire::forth::Value;
#[test]
fn map_add() {
expect_stack(
"1 2 3 4 5 ( 2 + ) map",
&[
Value::Int(3, None),
Value::Int(4, None),
Value::Int(5, None),
Value::Int(6, None),
Value::Int(7, None),
],
);
}
#[test]
fn map_multiply() {
expect_stack(
"1 2 3 ( 10 * ) map",
&[
Value::Int(10, None),
Value::Int(20, None),
Value::Int(30, None),
],
);
}
#[test]
fn map_single_element() {
expect_int("42 ( 1 + ) map", 43);
}
#[test]
fn map_empty_stack() {
run("( 1 + ) map");
}
#[test]
fn map_identity() {
expect_stack(
"1 2 3 ( ) map",
&[
Value::Int(1, None),
Value::Int(2, None),
Value::Int(3, None),
],
);
}
#[test]
fn map_missing_quotation() {
expect_error("1 2 3 map", "expected quotation");
}