about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/interpreter/tests.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-01-14T15·16+0300
committertazjin <mail@tazj.in>2021-01-14T15·19+0000
commit1d8e3f4f8b4479a47e744b3d153fe0e624958817 (patch)
tree06d2747cf725fe6e2606c90355c8c1af25305e9c /users/tazjin/rlox/src/interpreter/tests.rs
parent56d8fa97ed936aacb66b13bb4a8c849a9797db93 (diff)
feat(tazjin/rlox): Implement function definitions r/2106
... with this, functions now work.

Note that this bubbled up another weird code structure nit: The
parser::Function type should probably not carry its name directly.

However this doesn't matter much and I don't care right now.

Change-Id: If8e3b23f07033260433b9acd45f37c0e61fd2ff8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2393
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/interpreter/tests.rs')
-rw-r--r--users/tazjin/rlox/src/interpreter/tests.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/interpreter/tests.rs b/users/tazjin/rlox/src/interpreter/tests.rs
index 93a025c5e832..bf2cf61b0a76 100644
--- a/users/tazjin/rlox/src/interpreter/tests.rs
+++ b/users/tazjin/rlox/src/interpreter/tests.rs
@@ -70,3 +70,18 @@ fn test_binary_operators() {
         parse_eval(&code("\"foo\" + \"bar\";"))
     );
 }
+
+#[test]
+fn test_functions() {
+    let code = code(
+        r#"
+fun add(a, b, c) {
+  a + b + c;
+}
+
+add(1, 2, 3);
+"#,
+    );
+
+    assert_eq!(Value::Literal(Literal::Number(6.0)), parse_eval(&code));
+}