Skip to content

Commit

Permalink
Add closure test
Browse files Browse the repository at this point in the history
  • Loading branch information
asynchroza committed Nov 15, 2023
1 parent 6e2c16f commit 158807c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions closures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// const a = (x) => (y) => { return x + y; };

function a(x) {
return function(y) {
return x + y;
}
}

const b = a(5);

console.log(b(5))


16 changes: 14 additions & 2 deletions nulascript/tests/eval_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <type_traits>

// #define MULTILINE_STRING(s) #s
#define MULTILINE_STRING(s) #s

Storage* getEvaluatedStorage(std::string input) {
Lexer l(input);
Expand Down Expand Up @@ -108,7 +108,19 @@ TEST(EvalSuite, TestFunction) {
};

std::vector<Test> tests = {
{"let something = fn(x) {x;}; something(69);", "69"}};
{"let something = fn(x) {x;}; something(69);", "69"},
{
// clang-format off
MULTILINE_STRING(
let something = fn(a) {
fn(b) { a == b };
};

let result = something(10);
result(10);
), "true"
// clang-format on
}};

for (auto test : tests) {
auto result = getEvaluatedStorage(test.input);
Expand Down

0 comments on commit 158807c

Please sign in to comment.