Skip to content

Commit

Permalink
udpate test
Browse files Browse the repository at this point in the history
  • Loading branch information
chloro-pn committed Jul 28, 2024
1 parent c4f443d commit 2e1379a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 0 additions & 1 deletion test/builtin_function_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "wamon/interpreter.h"
#include "wamon/parser.h"
#include "wamon/scanner.h"
#include "wamon/static_analyzer.h"
#include "wamon/type_checker.h"
#include "wamon/variable.h"

Expand Down
27 changes: 15 additions & 12 deletions test/executable_block_stmt_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@

using namespace wamon;

std::unique_ptr<ExecutableBlockStmt> get_executable_block_stmt() {
auto executable_block_stmt = [](Interpreter& ip) -> std::shared_ptr<Variable> {
auto va = ip.FindVariableById("main$param_a");
auto vref = ip.FindVariableById("main$param_ref");
va = ip.CallFunctionByName("main$update_value_from_script", {va});
int ret = AsIntVariable(va)->GetValue();
AsStringVariable(vref)->SetValue("changed");
return std::make_shared<IntVariable>(ret * 2, Variable::ValueCategory::RValue, "");
};
auto executable_block = std::make_unique<ExecutableBlockStmt>();
executable_block->SetExecutable(std::move(executable_block_stmt));
return executable_block;
}

std::shared_ptr<FunctionDef> generate_func_for_test() {
std::shared_ptr<FunctionDef> fd(new FunctionDef("my_fn"));
fd->AddParamList({
Expand All @@ -34,18 +48,7 @@ std::shared_ptr<FunctionDef> generate_func_for_test() {
});

fd->SetReturnType(TypeFactory<int>::Get());

auto executable_block = std::make_unique<ExecutableBlockStmt>();
executable_block->SetExecutable([](Interpreter& ip) -> std::shared_ptr<Variable> {
auto va = ip.FindVariableById("main$param_a");
auto vref = ip.FindVariableById("main$param_ref");
va = ip.CallFunctionByName("main$update_value_from_script", {va});
int ret = AsIntVariable(va)->GetValue();
AsStringVariable(vref)->SetValue("changed");
return std::make_shared<IntVariable>(ret * 2, Variable::ValueCategory::RValue, "");
});

fd->SetBlockStmt(std::move(executable_block));
fd->SetBlockStmt(get_executable_block_stmt());
return fd;
}

Expand Down
1 change: 0 additions & 1 deletion test/static_analysis_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "wamon/exception.h"
#include "wamon/parser.h"
#include "wamon/scanner.h"
#include "wamon/static_analyzer.h"
#include "wamon/type_checker.h"

TEST(static_analysis, base) {
Expand Down

0 comments on commit 2e1379a

Please sign in to comment.