Feat: integrating workshop fixes
All checks were successful
Deploy Website / deploy (push) Has been skipped
All checks were successful
Deploy Website / deploy (push) Has been skipped
This commit is contained in:
@@ -66,3 +66,6 @@ mod case_statement;
|
||||
|
||||
#[path = "forth/harmony.rs"]
|
||||
mod harmony;
|
||||
|
||||
#[path = "forth/map.rs"]
|
||||
mod map;
|
||||
|
||||
55
tests/forth/map.rs
Normal file
55
tests/forth/map.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user