summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Sencha-lang/Tests')
-rw-r--r--Sencha-lang/Tests/TestParser.cpp72
-rw-r--r--Sencha-lang/Tests/TestParser.h4
-rw-r--r--Sencha-lang/Tests/TestStdLib.cpp36
-rw-r--r--Sencha-lang/Tests/TestStdLib.h21
-rw-r--r--Sencha-lang/Tests/TestSuite.cpp4
-rw-r--r--Sencha-lang/Tests/tests.h9
-rw-r--r--Sencha-lang/Tests/tests_to_be_written2
7 files changed, 144 insertions, 4 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;
}
diff --git a/Sencha-lang/Tests/TestParser.h b/Sencha-lang/Tests/TestParser.h
index acad6fe..a2a4843 100644
--- a/Sencha-lang/Tests/TestParser.h
+++ b/Sencha-lang/Tests/TestParser.h
@@ -28,6 +28,10 @@ private:
std::string test_adding_new_function();
std::string test_calling_funtion();
std::string prepare_some_function_declarations();
+ std::string test_writing_and_accessing_array_elements();
+ std::string test_changing_letters_in_string();
+
+
std::vector<InputOutputPair> prepare_logical_input();
virtual std::string all_tests();
diff --git a/Sencha-lang/Tests/TestStdLib.cpp b/Sencha-lang/Tests/TestStdLib.cpp
new file mode 100644
index 0000000..f3521e7
--- /dev/null
+++ b/Sencha-lang/Tests/TestStdLib.cpp
@@ -0,0 +1,36 @@
+/*
+ * TestStdLib.cpp
+ *
+ * Created on: Jan 12, 2013
+ * Author: att
+ */
+
+#include "TestStdLib.h"
+
+TestStdLib::TestStdLib() {
+ // TODO Auto-generated constructor stub
+
+}
+
+TestStdLib::~TestStdLib() {
+ // TODO Auto-generated destructor stub
+}
+
+std::string TestStdLib::test_string_lib()
+{
+ std::string test_report = "";
+
+
+ muu_assert("Write this test", false);
+
+ return test_report;
+}
+
+std::string TestStdLib::all_tests()
+{
+ std::string test_report = "";
+
+ mu_run_test(test_string_lib);
+
+ return test_report;
+}
diff --git a/Sencha-lang/Tests/TestStdLib.h b/Sencha-lang/Tests/TestStdLib.h
new file mode 100644
index 0000000..8f86f09
--- /dev/null
+++ b/Sencha-lang/Tests/TestStdLib.h
@@ -0,0 +1,21 @@
+/*
+ * TestStdLib.h
+ *
+ * Created on: Jan 12, 2013
+ * Author: att
+ */
+
+#ifndef TESTSTDLIB_H_
+#define TESTSTDLIB_H_
+
+#include "TestSuite.h"
+
+class TestStdLib: public TestSuite {
+public:
+ TestStdLib();
+ virtual ~TestStdLib();
+ std::string test_string_lib();
+ virtual std::string all_tests();
+};
+
+#endif /* TESTSTDLIB_H_ */
diff --git a/Sencha-lang/Tests/TestSuite.cpp b/Sencha-lang/Tests/TestSuite.cpp
index 3c37b25..f50531c 100644
--- a/Sencha-lang/Tests/TestSuite.cpp
+++ b/Sencha-lang/Tests/TestSuite.cpp
@@ -30,13 +30,13 @@ void TestSuite::run_tests()
std::string result = all_tests();
if(result != "")
{
- std::cout << "\x1b[00;31mSOME TESTS DIDN\'T PASS\x1b[00;00m" << std::endl; //Sets color to red
+ std::cout << "\n\x1b[00;31mSOME TESTS DIDN\'T PASS\x1b[00;00m" << std::endl; //Sets color to red
std::cout << result << std::endl;
}
else
{
- std::cout << "\x1b[00;32mALL TESTS PASSED\x1b[00;00m\n" << std::endl; //Sets color to green
+ std::cout << "\n\x1b[00;32mALL TESTS PASSED\x1b[00;00m" << std::endl; //Sets color to green
}
std::cout << tests_passed << " TESTS PASSED\n";
std::cout << tests_failed << " TESTS FAILED\n";
diff --git a/Sencha-lang/Tests/tests.h b/Sencha-lang/Tests/tests.h
index 49700d1..637da00 100644
--- a/Sencha-lang/Tests/tests.h
+++ b/Sencha-lang/Tests/tests.h
@@ -12,6 +12,7 @@
#include "TestLexer.h"
#include "TestASTInspector.h"
#include "TestParser.h"
+#include "TestStdLib.h"
#include "../Lexer.h"
#include "../Parser.h"
@@ -21,20 +22,26 @@ using namespace std;
void run_test_suites()
{
+ std::cout << "Testing lexer..." << std::endl;
TestLexer test_lexer;
test_lexer.run_tests();
+ std::cout << "Testing ASTInspector..." << std::endl;
TestASTInspector test_inspector;
test_inspector.run_tests();
+ std::cout << "Testing parser..." << std::endl;
TestParser test_parser;
test_parser.run_tests();
+ std::cout << "Testing standard library..." << std::endl;
+ TestStdLib test_standard_library;
+ test_standard_library.run_tests();
}
void run_tests()
{
- cout << "derp!" << endl;
+ cout << "daaarp!" << endl;
run_test_suites();
}
diff --git a/Sencha-lang/Tests/tests_to_be_written b/Sencha-lang/Tests/tests_to_be_written
index 1ab0d83..26a7370 100644
--- a/Sencha-lang/Tests/tests_to_be_written
+++ b/Sencha-lang/Tests/tests_to_be_written
@@ -24,3 +24,5 @@ My lexer doesn't have enough tests, i think. More tests! For example, given, acq
And em, It'd be nice if I could run test from console like ./Sencha-lang --run-tests or something. Done.
+Okay. Let's test some table manipulation.
+