diff options
author | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-18 21:51:57 +0100 |
---|---|---|
committer | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-18 21:51:57 +0100 |
commit | 442d8c640fdde22d9f6bf5d1a729d8e17e2fa407 (patch) | |
tree | ae71033602234fec2c414b1c2cb214a8c3159f4e | |
parent | 9b28dfa8ddbb5fbf4ecb16fa481490f30d480754 (diff) | |
download | sencha-lang-442d8c640fdde22d9f6bf5d1a729d8e17e2fa407.tar.gz sencha-lang-442d8c640fdde22d9f6bf5d1a729d8e17e2fa407.tar.bz2 sencha-lang-442d8c640fdde22d9f6bf5d1a729d8e17e2fa407.tar.xz sencha-lang-442d8c640fdde22d9f6bf5d1a729d8e17e2fa407.zip |
Tidying up main function. Moving tests.
-rw-r--r-- | Sencha-lang/Tests/TestASTInspector.cpp | 13 | ||||
-rw-r--r-- | Sencha-lang/Tests/tests.h | 76 | ||||
-rw-r--r-- | Sencha-lang/main.cpp | 54 |
3 files changed, 94 insertions, 49 deletions
diff --git a/Sencha-lang/Tests/TestASTInspector.cpp b/Sencha-lang/Tests/TestASTInspector.cpp index 875fe76..4194dbe 100644 --- a/Sencha-lang/Tests/TestASTInspector.cpp +++ b/Sencha-lang/Tests/TestASTInspector.cpp @@ -18,14 +18,27 @@ TestASTInspector::~TestASTInspector() { std::string TestASTInspector::test_inspecting_basic_expression() { + + std::string test_report = ""; + + BasicExpression * be = build_basic_expression("+", SenchaObject(9), SenchaObject(122)); + be->accept(&inspector); + std::string assert_report = "Report: " + inspector.inspection_report; + muu_assert("dd", inspector.inspection_report == "tralala"); + + return test_report; } virtual std::string TestASTInspector::all_tests() { + std::string test_report = ""; + + mu_run_test(test_inspecting_basic_expression); + return test_report; } BasicExpression * TestASTInspector::build_basic_expression(std::string oper, SenchaObject arg1, SenchaObject arg2) diff --git a/Sencha-lang/Tests/tests.h b/Sencha-lang/Tests/tests.h new file mode 100644 index 0000000..0fb7aa3 --- /dev/null +++ b/Sencha-lang/Tests/tests.h @@ -0,0 +1,76 @@ +/* + * tests.h + * + * Created on: Dec 18, 2012 + * Author: att + */ + +#ifndef TESTS_H_ +#define TESTS_H_ +#include <string> +#include "Lexer.h" +#include "Parser.h" + + +using namespace std; + +void test_lexer() +{ + string test_line = "dupa"; + string test_line2 = "def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree( num how_many) {return how_many -1; != <=}"; + Lexer lexer; + vector<Token> tokens = lexer.parse_line(test_line); + + + for(unsigned int i=0; i< tokens.size(); i++) + { + cout << tokens[i].get_value() << " type: " << tokens[i].get_type() << endl; + } + + + tokens = lexer.parse_line(test_line2); + +} + +void test_parser() +{ + vector<string> lines; + lines.push_back("def i; bulb; i + 3; string banan = \"kartofel\"; banan = \"banan\"; string kaboom(num how_many_times) { def z; }"); + lines.push_back("num pun"); + lines.push_back("def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree(num how_many) {return how_many -1}"); + Lexer lexer; + Context context; + vector<Token> tokens; + + for(unsigned int i=0; i<lines.size(); i++) + { + tokens = lexer.parse_line(lines[i]); + Parser parser(&context); + parser.add_tokens(tokens); + parser.interpret(); + cout << "<<<Parsing number: " << i << " >>>" << endl; + cout << "Instructions: " << endl ; + cout << lines[i] << endl << endl; + cout << parser.report_message; + cout << parser.error_message << endl; + } + +} + +void run_test_suites() +{ + TestLexer test_l; + test_l.run_tests(); + + + +} + +void run_tests() +{ + run_test_suites(); +} + + + +#endif /* TESTS_H_ */ diff --git a/Sencha-lang/main.cpp b/Sencha-lang/main.cpp index 6269f0a..baf455d 100644 --- a/Sencha-lang/main.cpp +++ b/Sencha-lang/main.cpp @@ -7,7 +7,7 @@ #include "Parser.h" #include "Tests/TestLexer.h" #include "Context.h" -
+#include "Tests/tests.h"
using namespace std;
@@ -97,49 +97,8 @@ SenchaObject s_tan(vector<ASTExpression *> arguments) return result; } -void test_lexer() -{ - string test_line = "dupa"; - string test_line2 = "def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree( num how_many) {return how_many -1; != <=}"; - Lexer lexer; - vector<Token> tokens = lexer.parse_line(test_line); - - - for(unsigned int i=0; i< tokens.size(); i++) - { - cout << tokens[i].get_value() << " type: " << tokens[i].get_type() << endl; - } - tokens = lexer.parse_line(test_line2); - -} - -void test_parser() -{ - vector<string> lines; - lines.push_back("def i; bulb; i + 3; string banan = \"kartofel\"; banan = \"banan\"; string kaboom(num how_many_times) { def z; }"); - lines.push_back("num pun"); - lines.push_back("def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree(num how_many) {return how_many -1}"); - Lexer lexer; - Context context; - vector<Token> tokens; - - for(unsigned int i=0; i<lines.size(); i++) - { - tokens = lexer.parse_line(lines[i]); - Parser parser(&context); - parser.add_tokens(tokens); - parser.interpret(); - cout << "<<<Parsing number: " << i << " >>>" << endl; - cout << "Instructions: " << endl ; - cout << lines[i] << endl << endl; - cout << parser.report_message; - cout << parser.error_message << endl; - } - -} - int how_depth_change(vector<Token> tokens) { int change = 0; @@ -208,17 +167,14 @@ int main(int argc, char *argv[]) { if(argc <= 1) { - //TestLexer test_l; - //test_l.run_tests(); - - - //test_parser(); - //test_lexer(); cout << "Sencha-lang interpreter, version 0.12" << endl; interactive(); } - else + else if(argv[1] == "--test") { + run_tests(); + } + else { auto name = argv[1]; Lexer lexer; Context context; |