From a24ea4d6be0a92f9d2d8e937d08f6ea5575021ef Mon Sep 17 00:00:00 2001 From: martin dobrev Date: Sun, 14 Oct 2018 17:49:22 +0300 Subject: Clean up main.cpp --- JSImpl/src/main.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'JSImpl/src/main.cpp') diff --git a/JSImpl/src/main.cpp b/JSImpl/src/main.cpp index 4263bfa..b51d1a9 100644 --- a/JSImpl/src/main.cpp +++ b/JSImpl/src/main.cpp @@ -1,12 +1,11 @@ #include "Lexer.h" #include "Parser.h" +#include "ASTPrinter.h" #include #define LOG(msg) std::cout << msg << std::endl #define EXECUTE_TEST(test) std::cout << #test << " "; test(); #define CHECK(cond) if (cond) {LOG("PASS");} else {LOG(#cond " FAIL");} -#define CHECK(cond) cond ? LOG("PASS") : LOG("FAIL") - // Lexer Tests void TestLess() { @@ -23,13 +22,13 @@ void TestNumber() void TestNumberStartWithNine() { auto tokens = Tokenize("999"); - CHECK(tokens.size() == 2 && tokens[0].Type == TokenType::Number && tokens[0].Number == 999) + CHECK(tokens.size() == 2 && tokens[0].Type == TokenType::Number && tokens[0].Number == 999); } void TestNumberStartWithZero() { auto tokens = Tokenize("0999"); - CHECK(tokens.size() == 2 && tokens[0].Type == TokenType::Number && tokens[0].Number == 999) + CHECK(tokens.size() == 2 && tokens[0].Type == TokenType::Number && tokens[0].Number == 999); } void TestSpaceNewLineSpace() @@ -73,25 +72,27 @@ void TestVariableDeclaration() void TestParseUnaryExpr() { // TODO make actual test :D - auto expr = Parse(Tokenize("function pesho() { var a = 0; return a; }")); + auto expr = Parse(Tokenize("function pesho(v1) { var a = 0; return a; }")); + ASTPrinter p(std::cout); + expr->Accept(p); } int main() { - EXECUTE_TEST(TestLess); - EXECUTE_TEST(TestNumber); - EXECUTE_TEST(TestNumberStartWithNine); - EXECUTE_TEST(TestNumberStartWithZero); - EXECUTE_TEST(TestString); - EXECUTE_TEST(TestSpaceNewLineSpace); - EXECUTE_TEST(TestStringSingleQuotedStrings); - EXECUTE_TEST(TestKeyWord); - EXECUTE_TEST(TestVariableDeclaration); + //EXECUTE_TEST(TestLess); + //EXECUTE_TEST(TestNumber); + //EXECUTE_TEST(TestNumberStartWithNine); + //EXECUTE_TEST(TestNumberStartWithZero); + //EXECUTE_TEST(TestString); + //EXECUTE_TEST(TestSpaceNewLineSpace); + //EXECUTE_TEST(TestStringSingleQuotedStrings); + //EXECUTE_TEST(TestKeyWord); + //EXECUTE_TEST(TestVariableDeclaration); - //EXECUTE_TEST(TestParseUnaryExpr); + EXECUTE_TEST(TestParseUnaryExpr); #if defined(_WIN32) - std::system("pause"); + //std::system("pause"); #endif return 0; } -- cgit v1.3.1-23-gd82d