blob: 6d9d66a71ba291fb7204ce04bc149485c13049b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
* TestParser.cpp
*
* Created on: Dec 22, 2012
* Author: att
*/
#include "TestParser.h"
TestParser::TestParser() {
}
TestParser::~TestParser() {
}
std::string TestParser::test_parsing_and_evaluating_logical_expressions()
{
std::string test_report = "";
std::vector<InputOutputPair> logical_inputs = prepare_logical_input();
Lexer lexer;
ContextManager context;
Parser parser(&context);
for(auto logical_case : logical_inputs)
{
auto tokens = lexer.parse_line(logical_case.first);
parser.add_tokens(tokens);
parser.interpret();
SenchaObject value = parser.program->evaluate_last();
parser.erase_all();
muu_assert("Logical value isn't correct", value.truthy == logical_case.second);
}
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\");}";
return test_report;
}
std::vector<TestParser::InputOutputPair> TestParser::prepare_logical_input()
{
std::vector<InputOutputPair> logical_inputs;
logical_inputs.push_back(InputOutputPair("false and false", false));
logical_inputs.push_back(InputOutputPair("false and true", false));
logical_inputs.push_back(InputOutputPair("true and false", false));
logical_inputs.push_back(InputOutputPair("true and true", true));
logical_inputs.push_back(InputOutputPair("false or false", false));
logical_inputs.push_back(InputOutputPair("false or true", true));
logical_inputs.push_back(InputOutputPair("true or false", true));
logical_inputs.push_back(InputOutputPair("true or true", true));
logical_inputs.push_back(InputOutputPair("(true or false) and (true or false)", true));
logical_inputs.push_back(InputOutputPair("7 + 2 > 55 or 6-5 == 1", true));
return logical_inputs;
}
std::string TestParser::all_tests()
{
std::string test_report = "";
mu_run_test(test_parsing_and_evaluating_logical_expressions);
return test_report;
}
/*TODO
* write test of evaluating logical expression
* possible input:
*
* some variable == "g" and other != "a"
*
* some easy expression like:
* if("aaa" != "bbb" and 2 < 5) {
>> print(1);
>> } else {
>> print(0);
>> }
*/
|