summaryrefslogtreecommitdiffstats
path: root/tests/forth.rs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-08-24 18:25:10 -0400
committerBrian Cully <bjc@spork.org>2025-08-24 21:56:16 -0400
commit0f9a9158b7135a3162522cf473a7bad80f141109 (patch)
tree241523674d811fa9c300e0b449de19232267184e /tests/forth.rs
parent9539017ec481653dc47e3e362ae6d240aad1b917 (diff)
downloadautomathon-0f9a9158b7135a3162522cf473a7bad80f141109.tar.gz
automathon-0f9a9158b7135a3162522cf473a7bad80f141109.zip
move factorial test to integration test
Diffstat (limited to 'tests/forth.rs')
-rw-r--r--tests/forth.rs28
1 files changed, 28 insertions, 0 deletions
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");
+}