summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Tests/TestParser.cpp
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-12 22:16:30 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-12 22:16:30 +0100
commit53f8ba2097355f7f488ed04b1d86d037e47216f2 (patch)
tree533fd39064f4148b61c943fdc25d0338a4d5b5d4 /Sencha-lang/Tests/TestParser.cpp
parent3a449cb09b812ef7017f584ff3968c40a4f6a83a (diff)
downloadsencha-lang-imports.tar.gz
sencha-lang-imports.tar.bz2
sencha-lang-imports.tar.xz
sencha-lang-imports.zip
Some new examples. New tests. Small improvements.imports
Diffstat (limited to 'Sencha-lang/Tests/TestParser.cpp')
-rw-r--r--Sencha-lang/Tests/TestParser.cpp72
1 files changed, 71 insertions, 1 deletions
diff --git a/Sencha-lang/Tests/TestParser.cpp b/Sencha-lang/Tests/TestParser.cpp
index d656306..633fcc6 100644
--- a/Sencha-lang/Tests/TestParser.cpp
+++ b/Sencha-lang/Tests/TestParser.cpp
@@ -35,18 +35,85 @@ std::string TestParser::test_parsing_and_evaluating_logical_expressions()
return test_report;
}
+std::string TestParser::test_changing_letters_in_string()
+{
+ std::string test_report = "";
+ std::string preparations = "text = \"AlfaBetaGamma\";";
+ std::string changes = "text[0] = \"a\";";
+ changes += "text[4] = \"b\";";
+ changes += "text[8] = \"g\";";
+ changes += "text;";
+
+ ContextManager context_manager;
+ Parser parser(&context_manager);
+ Lexer lexer;
+ auto tokens = lexer.parse_line(preparations + changes);
+ parser.add_tokens(tokens);
+ parser.interpret();
+ SenchaObject value = parser.program->execute();
+ //std::cout << value.repr() << std::endl;
+ muu_assert("Changed text isn't alfabetagamma", value.text == "alfabetagamma");
+
+ return test_report;
+}
+
+
+
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\");}";
+ ContextManager context_manager;
+ Parser parser(&context_manager);
+ Lexer lexer;
+ auto tokens = lexer.parse_line(function_declaration);
+ parser.add_tokens(tokens);
+ parser.interpret();
+
+ muu_assert("Function couldn't be added", context_manager.get_top()->contains_function("print_hello"));
+
+ return test_report;
+}
+
+std::string TestParser::test_writing_and_accessing_array_elements()
+{
+ std::string test_report = "";
+ std::string table_definition = "array data[4];";
+ table_definition += "data[0] = 3; data[1] = -88; data[2] = true; data[3] = 1.222;";
+
+ std::string data_access = "data[0];";
ContextManager context;
Parser parser(&context);
Lexer lexer;
- auto tokens = lexer.parse_line(function_declaration);
+ auto tokens = lexer.parse_line(table_definition + data_access);
parser.add_tokens(tokens);
parser.interpret();
+ SenchaObject value = parser.program->execute();
+
+ muu_assert("data[0] != 3", (value == SenchaObject(3)).truthy );
+ data_access = "data[1];";
+ tokens = lexer.parse_line(data_access);
+ parser.add_tokens(tokens);
+ parser.interpret();
+ value = parser.program->execute();
+ muu_assert("data[1] != -88", (value == SenchaObject(-88)).truthy );
+
+ data_access = "data[2];";
+ tokens = lexer.parse_line(data_access);
+ parser.add_tokens(tokens);
+ parser.interpret();
+ value = parser.program->execute();
+ muu_assert("data[2] != true", (value == SenchaObject(true)).truthy );
+
+ data_access = "data[3];";
+ tokens = lexer.parse_line(data_access);
+ parser.add_tokens(tokens);
+ parser.interpret();
+ value = parser.program->execute();
+ muu_assert("data[3] != 1.222", (value == SenchaObject(1.222)).truthy );
+
return test_report;
}
@@ -123,6 +190,9 @@ std::string TestParser::all_tests()
mu_run_test(test_parsing_and_evaluating_logical_expressions);
mu_run_test(test_calling_funtion);
+ mu_run_test(test_changing_letters_in_string);
+ //mu_run_test(test_adding_new_function);
+ mu_run_test(test_writing_and_accessing_array_elements);
return test_report;
}