summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Tests/TestParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Sencha-lang/Tests/TestParser.cpp')
-rw-r--r--Sencha-lang/Tests/TestParser.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/Sencha-lang/Tests/TestParser.cpp b/Sencha-lang/Tests/TestParser.cpp
index 3f58cda..1de0a91 100644
--- a/Sencha-lang/Tests/TestParser.cpp
+++ b/Sencha-lang/Tests/TestParser.cpp
@@ -54,14 +54,22 @@ std::string TestParser::test_adding_new_function()
std::string TestParser::test_calling_funtion()
{
std::string test_report = "";
- register_some_functions();
- std::string call = "print_hello(77);";
+ Lexer lexer;
+ ContextManager context;
+ Parser parser(&context);
+ std::string call = " max(77, 12);";
+ auto tokens = lexer.parse_line(prepare_some_function_declarations() + call);
+ parser.add_tokens(tokens);
+ parser.interpret();
+ auto value = parser.program->execute_last();
+ muu_assert("function max doesn't work", value.integer == 77);
+ std::cout << "function call returned " << value.repr() << std::endl;
return test_report;
}
-void TestParser::register_some_functions()
+std::string TestParser::prepare_some_function_declarations()
{
- std::string print_hello_declaration ="def print_hello(how_many_times) {";
+ /*std::string print_hello_declaration ="def print_hello(how_many_times) {";
print_hello_declaration += " repeat(how_many_times) { print(\"Hello\");}";
std::string how_long_declaration = "def how_long(some_text) {";
@@ -79,8 +87,13 @@ void TestParser::register_some_functions()
std::string multiply_string_declaration = "def multiply_string(text, i) {";
multiply_string_declaration += "result = \"\"; ";
multiply_string_declaration += "repeats(i) { result = result + text }";
- multiply_string_declaration += " return result; ";
+ multiply_string_declaration += " return result; ";*/
+
+ std::string max_declaration = "def max(a, b) { ";
+ max_declaration += "if(a > b) return a; ";
+ max_declaration += "else return b; }";
+ return max_declaration;
}
std::vector<TestParser::SInputOutputPair> TestParser::prepare_function_call_input()
@@ -120,7 +133,7 @@ std::string TestParser::all_tests()
std::string test_report = "";
mu_run_test(test_parsing_and_evaluating_logical_expressions);
-
+ mu_run_test(test_calling_funtion);
return test_report;
}