summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-10 11:46:41 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-10 11:46:41 +0100
commit3ad07986ff0da5e195da030612b6253fbd12f57f (patch)
treeab35f61472cc56fd20ab104e7b4f28d146bdf375
parentd959b701bf720e0ee2553452576e7cced12623f3 (diff)
downloadsencha-lang-3ad07986ff0da5e195da030612b6253fbd12f57f.tar.gz
sencha-lang-3ad07986ff0da5e195da030612b6253fbd12f57f.tar.bz2
sencha-lang-3ad07986ff0da5e195da030612b6253fbd12f57f.zip
I repaired broken tests.
-rw-r--r--Sencha-lang/AST/ASTStatement.h2
-rw-r--r--Sencha-lang/AST/DeclarationStatement.cpp2
-rw-r--r--Sencha-lang/AST/DeclarationStatement.h3
-rw-r--r--Sencha-lang/AST/IfNode.h1
-rw-r--r--Sencha-lang/AST/ImportStatement.h4
-rw-r--r--Sencha-lang/AST/RepeatStatement.h1
-rw-r--r--Sencha-lang/AST/UnaryExpression.cpp2
-rw-r--r--Sencha-lang/AST/UnaryExpression.h7
-rw-r--r--Sencha-lang/AST/WhileNode.h1
-rw-r--r--Sencha-lang/Tests/TestParser.cpp45
-rw-r--r--Sencha-lang/Tests/TestParser.h1
-rw-r--r--Sencha-lang/Tests/tests_to_be_written2
12 files changed, 36 insertions, 35 deletions
diff --git a/Sencha-lang/AST/ASTStatement.h b/Sencha-lang/AST/ASTStatement.h
index e9e4111..c52cba2 100644
--- a/Sencha-lang/AST/ASTStatement.h
+++ b/Sencha-lang/AST/ASTStatement.h
@@ -13,7 +13,7 @@ class ASTStatement : public ASTNode {
public:
ASTStatement();
virtual SenchaObject execute() = 0;
- virtual SenchaObject evaluate() { return SenchaObject(); }
+ virtual SenchaObject evaluate() = 0;
virtual ~ASTStatement();
};
diff --git a/Sencha-lang/AST/DeclarationStatement.cpp b/Sencha-lang/AST/DeclarationStatement.cpp
index a168383..fdc02d9 100644
--- a/Sencha-lang/AST/DeclarationStatement.cpp
+++ b/Sencha-lang/AST/DeclarationStatement.cpp
@@ -32,7 +32,7 @@ void DeclarationStatement::add_right_value(ASTExpression * right)
DeclarationStatement::DeclarationStatement(ContextManager * context_manager)
{
this->context_manager = context_manager;
- this->name_of_context = "global";//context_manager->create_new_context()->name;
+ this->name_of_context = "global";
is_function = false;
body = NULL;
right_value = SenchaObject();
diff --git a/Sencha-lang/AST/DeclarationStatement.h b/Sencha-lang/AST/DeclarationStatement.h
index bae55c4..a8ed045 100644
--- a/Sencha-lang/AST/DeclarationStatement.h
+++ b/Sencha-lang/AST/DeclarationStatement.h
@@ -37,6 +37,9 @@ public:
void add_body(ASTStatement * statement);
virtual SenchaObject execute();
+ virtual SenchaObject evaluate() {
+ return right_value;
+ }
virtual ~DeclarationStatement();
};
diff --git a/Sencha-lang/AST/IfNode.h b/Sencha-lang/AST/IfNode.h
index 9007bdb..1edd222 100644
--- a/Sencha-lang/AST/IfNode.h
+++ b/Sencha-lang/AST/IfNode.h
@@ -26,6 +26,7 @@ public:
void add_else_block(ASTStatement * statement);
bool is_else;
virtual SenchaObject execute();
+ virtual SenchaObject evaluate() { return execute(); }
bool evaluate_condition();
ASTNode * condition() { return children[0]; }
ASTNode * then_block() { return children[1]; }
diff --git a/Sencha-lang/AST/ImportStatement.h b/Sencha-lang/AST/ImportStatement.h
index f45d92e..c7326c9 100644
--- a/Sencha-lang/AST/ImportStatement.h
+++ b/Sencha-lang/AST/ImportStatement.h
@@ -23,12 +23,16 @@ public:
std::vector<std::string> DEFAULT_LIB_PATHS;
ContextManager * context_manager;
bool correctly_imported;
+
ImportStatement(std::string name_of_module, ContextManager * context_manager);
ASTNode * import_body;
std::string strip_string(std::string text);
void prepare_defaults();
std::vector<std::string> prepare_paths(std::string name_of_module);
SenchaObject execute();
+ SenchaObject evaluate() {
+ return SenchaObject(correctly_imported);
+ }
virtual ~ImportStatement();
};
diff --git a/Sencha-lang/AST/RepeatStatement.h b/Sencha-lang/AST/RepeatStatement.h
index 14906c4..2efb1dd 100644
--- a/Sencha-lang/AST/RepeatStatement.h
+++ b/Sencha-lang/AST/RepeatStatement.h
@@ -22,6 +22,7 @@ public:
ASTStatement * body;
ASTExpression * how_many_times_expr;
virtual SenchaObject execute();
+ virtual SenchaObject evaluate() { return execute(); }
void add_body(ASTStatement * statement);
virtual ~RepeatStatement();
};
diff --git a/Sencha-lang/AST/UnaryExpression.cpp b/Sencha-lang/AST/UnaryExpression.cpp
index 47ef287..14171d0 100644
--- a/Sencha-lang/AST/UnaryExpression.cpp
+++ b/Sencha-lang/AST/UnaryExpression.cpp
@@ -7,7 +7,7 @@
#include "UnaryExpression.h"
-UnaryExpression::UnaryExpression(ASTNode * argument, std::string oper) {
+UnaryExpression::UnaryExpression(ASTExpression * argument, std::string oper) {
type = "UnaryExpression";
children.push_back(argument);
this->oper = oper;
diff --git a/Sencha-lang/AST/UnaryExpression.h b/Sencha-lang/AST/UnaryExpression.h
index 7511d36..65a3ce0 100644
--- a/Sencha-lang/AST/UnaryExpression.h
+++ b/Sencha-lang/AST/UnaryExpression.h
@@ -9,7 +9,10 @@
#define UNARYEXPRESSION_H_
#include "ASTExpression.h"
-
+/**
+ * UnaryExpression is abstraction of unary operator and it's operand (right binding);
+ * It can be build like that: UnaryExpression(some_expression, "-")
+ */
class UnaryExpression: public ASTExpression {
public:
@@ -20,7 +23,7 @@ public:
virtual SenchaObject execute();
virtual SenchaObject evaluate();
- UnaryExpression(ASTNode * argument, std::string oper);
+ UnaryExpression(ASTExpression * argument, std::string oper);
UnaryExpression();
virtual ~UnaryExpression();
};
diff --git a/Sencha-lang/AST/WhileNode.h b/Sencha-lang/AST/WhileNode.h
index 27b8703..55991da 100644
--- a/Sencha-lang/AST/WhileNode.h
+++ b/Sencha-lang/AST/WhileNode.h
@@ -21,6 +21,7 @@ public:
virtual ~WhileNode();
ASTStatement * body;
virtual SenchaObject execute();
+ virtual SenchaObject evaluate() { return execute(); }
bool evaluate_condition();
};
diff --git a/Sencha-lang/Tests/TestParser.cpp b/Sencha-lang/Tests/TestParser.cpp
index 1de0a91..d656306 100644
--- a/Sencha-lang/Tests/TestParser.cpp
+++ b/Sencha-lang/Tests/TestParser.cpp
@@ -57,28 +57,33 @@ std::string TestParser::test_calling_funtion()
Lexer lexer;
ContextManager context;
Parser parser(&context);
- std::string call = " max(77, 12);";
- auto tokens = lexer.parse_line(prepare_some_function_declarations() + call);
+ std::string call_max = " max(77, 12);";
+ std::string declarations = prepare_some_function_declarations();
+ auto tokens = lexer.parse_line( declarations + call_max);
parser.add_tokens(tokens);
parser.interpret();
- auto value = parser.program->execute_last();
- muu_assert("function max doesn't work", value.integer == 77);
- std::cout << "function call returned " << value.repr() << std::endl;
+ auto value1 = parser.program->execute();
+ std::string call_multiply = " multiply_string(\"banana\", 3);";
+ muu_assert("function max doesn't work", value1.integer == 77);
+
+ parser.erase_all();
+ parser.add_tokens(lexer.parse_line(declarations + call_multiply));
+ parser.interpret();
+ auto value2 = parser.program->execute();
+ muu_assert("function multiply_string doesn't work", value2.text == "bananabananabanana");
return test_report;
}
std::string TestParser::prepare_some_function_declarations()
{
- /*std::string print_hello_declaration ="def print_hello(how_many_times) {";
- print_hello_declaration += " repeat(how_many_times) { print(\"Hello\");}";
std::string how_long_declaration = "def how_long(some_text) {";
how_long_declaration += " return len(some_text);}";
std::string max_declaration = "def max(a, b) { ";
- max_declaration += "if(a > b) return a;";
- max_declaration += "else return b; }";
+ max_declaration += "if(a > b) { return a; }";
+ max_declaration += "else { return b;} }";
std::string min_declaration = "def min(a, b) { ";
min_declaration += "if(a < b) return a;";
@@ -86,29 +91,13 @@ std::string TestParser::prepare_some_function_declarations()
std::string multiply_string_declaration = "def multiply_string(text, i) {";
multiply_string_declaration += "result = \"\"; ";
- multiply_string_declaration += "repeats(i) { result = result + text }";
- multiply_string_declaration += " return result; ";*/
+ multiply_string_declaration += "repeat(i) { result = result + text; }";
+ multiply_string_declaration += " return result;} ";
- std::string max_declaration = "def max(a, b) { ";
- max_declaration += "if(a > b) return a; ";
- max_declaration += "else return b; }";
- return max_declaration;
+ return max_declaration + min_declaration + multiply_string_declaration;
}
-std::vector<TestParser::SInputOutputPair> TestParser::prepare_function_call_input()
-{
- std::vector<SInputOutputPair> function_calls;
-
- function_calls.push_back(SInputOutputPair("print_hello(77);", SenchaObject()));
- function_calls.push_back(SInputOutputPair("how_long(\"elephant\");", SenchaObject(8)));
- function_calls.push_back(SInputOutputPair("max(77, 12);", SenchaObject(77)));
- function_calls.push_back(SInputOutputPair("min(12, 1);", SenchaObject(1)));
- function_calls.push_back(SInputOutputPair("multiply_string(\"alfa\", 3);", SenchaObject("alfaalfaalfa")));
-
- return function_calls;
-
-}
std::vector<TestParser::InputOutputPair> TestParser::prepare_logical_input()
{
diff --git a/Sencha-lang/Tests/TestParser.h b/Sencha-lang/Tests/TestParser.h
index e5da753..e481700 100644
--- a/Sencha-lang/Tests/TestParser.h
+++ b/Sencha-lang/Tests/TestParser.h
@@ -29,7 +29,6 @@ private:
std::string test_calling_funtion();
std::string prepare_some_function_declarations();
std::vector<InputOutputPair> prepare_logical_input();
- std::vector<TestParser::SInputOutputPair> prepare_function_call_input();
virtual std::string all_tests();
diff --git a/Sencha-lang/Tests/tests_to_be_written b/Sencha-lang/Tests/tests_to_be_written
index dbde35d..1ab0d83 100644
--- a/Sencha-lang/Tests/tests_to_be_written
+++ b/Sencha-lang/Tests/tests_to_be_written
@@ -22,5 +22,5 @@ What's more?
My lexer doesn't have enough tests, i think. More tests! For example, given, acquired, desired.
-And em, It'd be nice if I could run test from console like ./Sencha-lang --run-tests or something.
+And em, It'd be nice if I could run test from console like ./Sencha-lang --run-tests or something. Done.