From 587d96be250ff7329899ce0b46b8912fe6a79720 Mon Sep 17 00:00:00 2001 From: Ross Andrews Date: Mon, 14 Aug 2023 00:36:26 -0500 Subject: [PATCH] A couple tests --- forge_core/src/compiler.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/forge_core/src/compiler.rs b/forge_core/src/compiler.rs index 6f08efb..2f831a8 100644 --- a/forge_core/src/compiler.rs +++ b/forge_core/src/compiler.rs @@ -631,6 +631,19 @@ mod test { ) } + #[test] + fn test_string_const() { + let mut state = State::default(); + parse("const foo = \"bar\";") + .unwrap() + .process(&mut state, None) + .unwrap(); + assert_eq!( + state.global_scope, + [("foo".into(), Variable::DirectLabel("_gensym_1".into()))].into() + ) + } + #[test] fn test_global_decl() { let mut state = State::default(); @@ -781,6 +794,26 @@ mod test { ] .join("\n") ) + } + #[test] + fn test_string_exprs() { + let mut state = State::default(); + parse("const foo = \"foo\"; fn blah() { var x = \"bar\" + 3; }") + .unwrap() + .process(&mut state, None) + .expect("Failed to compile"); + let body = body_as_string(state.functions.get("blah").unwrap()); + assert_eq!( + body, + vec![ + "push _gensym_3", // 1 is the label in the string table for "foo", 2 for "blah," + "push 3", // so 3 is the string "bar" + "add", // Add 3 to that address + "loadw frame", // Store it in the first var + "storew" + ] + .join("\n") + ) } }