diff options
Diffstat (limited to 'Sencha-lang/Tests/TestParser.cpp')
-rw-r--r-- | Sencha-lang/Tests/TestParser.cpp | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/Sencha-lang/Tests/TestParser.cpp b/Sencha-lang/Tests/TestParser.cpp index 6d9d66a..3f58cda 100644 --- a/Sencha-lang/Tests/TestParser.cpp +++ b/Sencha-lang/Tests/TestParser.cpp @@ -38,13 +38,64 @@ std::string TestParser::test_parsing_and_evaluating_logical_expressions() std::string TestParser::test_adding_new_function() { std::string test_report = ""; - std::string function_declaration =+ "def print_hello(how_many_times) {"; - function_declaration =+ " repeat(how_many_times) { print(\"Hello\");}"; + std::string function_declaration = "def print_hello(how_many_times) {"; + function_declaration += " repeat(how_many_times) { print(\"Hello\");}"; + ContextManager context; + Parser parser(&context); + Lexer lexer; + auto tokens = lexer.parse_line(function_declaration); + parser.add_tokens(tokens); + parser.interpret(); return test_report; } +std::string TestParser::test_calling_funtion() +{ + std::string test_report = ""; + register_some_functions(); + std::string call = "print_hello(77);"; + return test_report; +} + +void TestParser::register_some_functions() +{ + 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) {"; + how_long_declaration += " return len(some_text);}"; + + + std::string max_declaration = "def max(a, b) { "; + max_declaration += "if(a > b) return a;"; + max_declaration += "else return b; }"; + + std::string min_declaration = "def min(a, b) { "; + min_declaration += "if(a < b) return a;"; + min_declaration += "else return b; }"; + + 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; "; + +} + +std::vector<TestParser::SInputOutputPair> TestParser::prepare_function_call_input() +{ + std::vector<SInputOutputPair> function_calls; + + function_calls.push_back(SInputOutputPair("print_hello(77);", SenchaObject())); + function_calls.push_back(SInputOutputPair("how_long(\"elephant\");", SenchaObject(8))); + function_calls.push_back(SInputOutputPair("max(77, 12);", SenchaObject(77))); + function_calls.push_back(SInputOutputPair("min(12, 1);", SenchaObject(1))); + function_calls.push_back(SInputOutputPair("multiply_string(\"alfa\", 3);", SenchaObject("alfaalfaalfa"))); + + return function_calls; + +} std::vector<TestParser::InputOutputPair> TestParser::prepare_logical_input() { |