ok
This commit is contained in:
90
seq/tests/forth/stack.rs
Normal file
90
seq/tests/forth/stack.rs
Normal file
@@ -0,0 +1,90 @@
|
||||
use super::harness::*;
|
||||
use seq::model::forth::Value::Int;
|
||||
|
||||
#[test]
|
||||
fn dup() {
|
||||
expect_stack("3 dup", &[Int(3), Int(3)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dup_underflow() {
|
||||
expect_error("dup", "stack underflow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop() {
|
||||
expect_stack("1 2 drop", &[Int(1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_underflow() {
|
||||
expect_error("drop", "stack underflow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn swap() {
|
||||
expect_stack("1 2 swap", &[Int(2), Int(1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn swap_underflow() {
|
||||
expect_error("1 swap", "stack underflow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn over() {
|
||||
expect_stack("1 2 over", &[Int(1), Int(2), Int(1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn over_underflow() {
|
||||
expect_error("1 over", "stack underflow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rot() {
|
||||
expect_stack("1 2 3 rot", &[Int(2), Int(3), Int(1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rot_underflow() {
|
||||
expect_error("1 2 rot", "stack underflow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nip() {
|
||||
expect_stack("1 2 nip", &[Int(2)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nip_underflow() {
|
||||
expect_error("1 nip", "stack underflow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuck() {
|
||||
expect_stack("1 2 tuck", &[Int(2), Int(1), Int(2)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuck_underflow() {
|
||||
expect_error("1 tuck", "stack underflow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stack_persists() {
|
||||
let f = forth();
|
||||
let ctx = default_ctx();
|
||||
f.evaluate("1 2 3", &ctx).unwrap();
|
||||
assert_eq!(f.stack(), vec![Int(1), Int(2), Int(3)]);
|
||||
f.evaluate("4 5", &ctx).unwrap();
|
||||
assert_eq!(f.stack(), vec![Int(1), Int(2), Int(3), Int(4), Int(5)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clear_stack() {
|
||||
let f = forth();
|
||||
f.evaluate("1 2 3", &default_ctx()).unwrap();
|
||||
f.clear_stack();
|
||||
assert!(f.stack().is_empty());
|
||||
}
|
||||
Reference in New Issue
Block a user