2012-12-18 20:51:57 +00:00
|
|
|
/*
|
|
|
|
* tests.h
|
|
|
|
*
|
|
|
|
* Created on: Dec 18, 2012
|
|
|
|
* Author: att
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TESTS_H_
|
|
|
|
#define TESTS_H_
|
|
|
|
#include <string>
|
2012-12-18 21:41:39 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include "TestLexer.h"
|
|
|
|
#include "TestASTInspector.h"
|
2012-12-22 17:52:19 +00:00
|
|
|
#include "TestParser.h"
|
2012-12-18 21:41:39 +00:00
|
|
|
#include "../Lexer.h"
|
|
|
|
#include "../Parser.h"
|
2012-12-18 20:51:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2012-12-22 10:18:47 +00:00
|
|
|
//cout << parser.report_message;
|
2012-12-18 20:51:57 +00:00
|
|
|
cout << parser.error_message << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_test_suites()
|
|
|
|
{
|
|
|
|
TestLexer test_l;
|
|
|
|
test_l.run_tests();
|
|
|
|
|
2012-12-18 21:41:39 +00:00
|
|
|
TestASTInspector test_inspector;
|
|
|
|
test_inspector.run_tests();
|
|
|
|
|
2012-12-22 17:52:19 +00:00
|
|
|
TestParser test_parser;
|
|
|
|
test_parser.run_tests();
|
2012-12-18 20:51:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_tests()
|
|
|
|
{
|
|
|
|
run_test_suites();
|
2012-12-18 21:41:39 +00:00
|
|
|
cout << "derp!" << endl;
|
2012-12-18 20:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* TESTS_H_ */
|