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-02-28T13·15+0200
committertazjin <mail@tazj.in>2021-02-28T14·36+0000
commit47ffa8071152bcafb4b6ff87a3142bf12dbce12b (patch)
treea97b223762525febc0a2cfefa5be413a7b80e901 /users/tazjin/rlox/src/bytecode/tests.rs
parent127ef984865500d70176347861b2e8bad29a39be (diff)
feat(tazjin/rlox): Support trivial literals in bytecode compiler r/2252
Adds support for true, false & nil. These each come with a new
separate opcode and are pushed directly on the stack.

Change-Id: I405b5b09496dcf99d514d3411c083e0834377167
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2571
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.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/users/tazjin/rlox/src/bytecode/tests.rs b/users/tazjin/rlox/src/bytecode/tests.rs
index 5a0901be6d79..d9a752b38788 100644
--- a/users/tazjin/rlox/src/bytecode/tests.rs
+++ b/users/tazjin/rlox/src/bytecode/tests.rs
@@ -1,12 +1,17 @@
+use super::value::Value;
 use super::*;
 
 use crate::Lox;
 
-fn expect_num(code: &str, value: f64) {
+fn expect(code: &str, value: Value) {
     let result = Interpreter::create()
         .interpret(code.into())
         .expect("evaluation failed");
-    assert_eq!(result, value::Value::Number(value));
+    assert_eq!(result, value);
+}
+
+fn expect_num(code: &str, value: f64) {
+    expect(code, Value::Number(value))
 }
 
 #[test]
@@ -46,3 +51,10 @@ fn arithmetic() {
     expect_num("-4 * -4 + (14 - 5)", 25.0);
     expect_num("(702 + 408) - ((239 - 734) / -5) + -4", 1007.0);
 }
+
+#[test]
+fn trivial_literals() {
+    expect("true", Value::Bool(true));
+    expect("false", Value::Bool(false));
+    expect("nil", Value::Nil);
+}