about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/bytecode/tests.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-03-05T20·35+0200
committertazjin <mail@tazj.in>2021-03-06T11·52+0000
commit4162186a1963b0dcf3dc47946a1cd8ad81467ac4 (patch)
tree01dac61eeee9362d3e71c2a1e966da0b01180bfc /users/tazjin/rlox/src/bytecode/tests.rs
parent29b2a547055ba1adaf3f0d79055b7d7657eb3a5e (diff)
feat(tazjin/rlox): Implement global variable access r/2274
This also includes a fix for an issue where the identifiers of
variables were pushed onto the stack, which is incorrect.

Change-Id: Id89b388268efad295f29978d767aa4b33c4ded14
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2594
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/bytecode/tests.rs')
-rw-r--r--users/tazjin/rlox/src/bytecode/tests.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/bytecode/tests.rs b/users/tazjin/rlox/src/bytecode/tests.rs
index b346da19810d..d5b6ab020389 100644
--- a/users/tazjin/rlox/src/bytecode/tests.rs
+++ b/users/tazjin/rlox/src/bytecode/tests.rs
@@ -108,3 +108,13 @@ fn strings() {
     expect_str("\"hello\";", "hello");
     expect_str("\"hello\" + \" world\";", "hello world");
 }
+
+#[test]
+fn variables() {
+    expect_num("var a = 5; a;", 5.0);
+    expect_num("var a = 5; var b = 2; a * b;", 10.0);
+    expect_str(
+        "var greeting = \"hello\"; var name = \"Zubnog\"; greeting + \" \" + name;",
+        "hello Zubnog",
+    );
+}