use pnc_engine::{parse, value::Value};
#[test]
fn over_copies_second() {
let mut stack = Vec::new();
parse::eval_line(&mut stack, "1 2 over").unwrap();
assert_eq!(
stack,
vec![
Value::Int(1.into()),
Value::Int(2.into()),
Value::Int(1.into())
]
);
}
#[test]
fn rot_rotates_three() {
let mut stack = Vec::new();
parse::eval_line(&mut stack, "1 2 3 rot").unwrap();
assert_eq!(
stack,
vec![
Value::Int(2.into()),
Value::Int(3.into()),
Value::Int(1.into())
]
);
}
#[test]
fn to_rational_converts_int() {
let mut stack = Vec::new();
parse::eval_line(&mut stack, "5 to_rational").unwrap();
assert_eq!(
stack,
vec![Value::Rational(num_rational::BigRational::new(
5.into(),
1.into()
))]
);
}
#[test]
fn to_int_truncates() {
let mut stack = Vec::new();
parse::eval_line(&mut stack, "7 2 / to_int").unwrap();
assert_eq!(stack, vec![Value::Int(3.into())]);
}
#[test]
fn history_capacity_zero_disables_snapshots() {
use pnc_engine::stack::History;
use pnc_engine::value::Value;
let mut history = History::with_capacity(0);
history.record(vec![Value::Int(1.into())]);
assert_eq!(history.len(), 0);
assert!(history.undo().is_none());
assert!(!history.is_enabled());
}