From 0f9a9158b7135a3162522cf473a7bad80f141109 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sun, 24 Aug 2025 18:25:10 -0400 Subject: move factorial test to integration test --- tests/forth.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/forth.rs (limited to 'tests') diff --git a/tests/forth.rs b/tests/forth.rs new file mode 100644 index 0000000..4fae28e --- /dev/null +++ b/tests/forth.rs @@ -0,0 +1,28 @@ +use automathon::forth::{ + compiler::Compiler, + vm::{WordList, VM}, +}; + +fn compiler_for(text: &str) -> Compiler { + let mut p = Compiler::new(text); + p.compile().expect("badparse"); + p +} + +fn eprintwordlist(wordlist: &WordList) { + for i in 0..wordlist.0.len() { + eprintln!("wordlist[{}]: {:?}", i, wordlist.0[i]); + } +} + +#[test] +fn factorial() { + let prog = ": fac dup 1 > if dup 1 - fac * then ; 5 fac\n"; + let comp = compiler_for(prog); + eprintwordlist(&comp.wordlist); + let mut vm = VM::new(comp.wordlist); + vm.run().expect("should run to completion"); + eprintln!("stack: {:?}", vm.stack); + assert_eq!(vm.stack.0.len(), 1, "factorial result stack len"); + assert_eq!(vm.stack.0[0], 120, "factorial result value"); +} -- cgit v1.3