Skip to content

Commit

Permalink
Changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
rfdavid committed May 20, 2023
1 parent 798e433 commit ef5512d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/common/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::vector<std::string> StringUtils::split(
return result;
}

std::vector<std::string> StringUtils::splitByAnySpace(const std::string& input) {
std::vector<std::string> StringUtils::splitBySpace(const std::string& input) {
std::istringstream iss(input);
std::vector<std::string> result;
std::string token;
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class StringUtils {

static std::vector<std::string> split(const std::string& input, const std::string& delimiter);

static std::vector<std::string> splitByAnySpace(const std::string& input);
static std::vector<std::string> splitBySpace(const std::string& input);

static void toUpper(std::string& input) {
std::transform(input.begin(), input.end(), input.begin(), ::toupper);
Expand Down
4 changes: 2 additions & 2 deletions test/common/string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

using namespace kuzu::common;

TEST(StringTest, splitByAnySpace) {
TEST(StringTest, splitBySpace) {
std::string str = " a b c\td ";
std::vector<std::string> result = StringUtils::splitByAnySpace(str);
std::vector<std::string> result = StringUtils::splitBySpace(str);
EXPECT_EQ(result.size(), 4);
EXPECT_EQ(result[0], "a");
EXPECT_EQ(result[1], "b");
Expand Down
3 changes: 1 addition & 2 deletions test/include/test_runner/test_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace testing {
struct TestStatement {
std::string name;
std::string query;
std::string blockName;
uint64_t numThreads = 4;
std::string encodedJoin;
uint64_t expectedNumTuples = 0;
Expand All @@ -27,7 +26,7 @@ struct TestCase {
std::string name;
std::string dataset;
std::vector<std::unique_ptr<TestStatement>> statements;
std::vector<std::unique_ptr<TestStatement>> variableStatements;
std::unordered_map<std::string, std::vector<std::unique_ptr<TestStatement>>> variableStatements;

bool skipTest = false;

Expand Down
7 changes: 3 additions & 4 deletions test/include/test_runner/test_parser.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include <cstring>

#include "common/file_utils.h"
#include "main/kuzu.h"
#include "test_runner/test_case.h"

using namespace kuzu::main;

namespace kuzu {
namespace testing {

Expand Down Expand Up @@ -75,6 +72,8 @@ class TestParser {

void extractStatementBlock();

void addStatementBlock(const std::string& blockName);

inline bool endOfFile() { return fileStream.eof(); }

inline bool nextLine() { return static_cast<bool>(getline(fileStream, line)); }
Expand All @@ -87,7 +86,7 @@ class TestParser {

TestStatement* extractStatement(TestStatement* currentStatement);

TestStatement* addNewStatement(std::vector<std::unique_ptr<TestStatement>>& statements);
TestStatement* addNewStatement();
};

} // namespace testing
Expand Down
3 changes: 0 additions & 3 deletions test/include/test_runner/test_runner.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include "common/file_utils.h"
#include "gtest/gtest.h"
#include "main/kuzu.h"
#include "parser/parser.h"
#include "planner/logical_plan/logical_plan_util.h"
#include "planner/planner.h"
#include "test_runner/test_case.h"

using namespace kuzu::main;
using namespace kuzu::common;
using namespace kuzu::planner;

namespace kuzu {
Expand Down
2 changes: 1 addition & 1 deletion test/test_files/tinysnb/agg/hash.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-GROUP TinySnbReadTest
-TEST Agg
-TEST AggHash
-DATASET tinysnb

--
Expand Down
2 changes: 1 addition & 1 deletion test/test_files/tinysnb/agg/multi_label.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-GROUP TinySnbReadTest
-TEST Agg
-TEST AggMultiLabel
-DATASET tinysnb

--
Expand Down
39 changes: 20 additions & 19 deletions test/test_runner/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void TestParser::parseHeader() {
}
case TokenType::SEPARATOR: {
return;
break;
}
default: {
throw Exception("Invalid statement in test header");
Expand Down Expand Up @@ -96,7 +95,6 @@ TestStatement* TestParser::extractStatement(TestStatement* statement) {
case TokenType::RESULT: {
extractExpectedResult(statement);
return statement;
break;
}
case TokenType::CHECK_ORDER: {
statement->checkOutputOrder = true;
Expand Down Expand Up @@ -133,9 +131,9 @@ void TestParser::extractStatementBlock() {
if (currentToken.type == TokenType::END_OF_STATEMENT_BLOCK) {
break;
} else {
TestStatement* statement = addNewStatement(testCase->variableStatements);
statement->blockName = blockName;
extractStatement(statement);
auto statement = std::make_unique<TestStatement>();
extractStatement(statement.get());
testCase->variableStatements[blockName].push_back(std::move(statement));
}
}
}
Expand All @@ -157,33 +155,36 @@ void TestParser::parseBody() {
}
case TokenType::STATEMENT_BLOCK: {
checkMinimumParams(1);
for (auto& statement : testCase->variableStatements) {
if (statement->blockName == currentToken.params[1]) {
statement->name = name;
testCase->statements.push_back(std::make_unique<TestStatement>(*statement));
}
}
addStatementBlock(currentToken.params[1]);
break;
}
case TokenType::EMPTY: {
break;
}
default: {
// if its not special case, then it has to be a statement
TestStatement* statement = addNewStatement(testCase->statements);
// if its not a special case, then it has to be a statement
TestStatement* statement = addNewStatement();
statement->name = name;
extractStatement(statement);
}
}
}
}

TestStatement* TestParser::addNewStatement(
std::vector<std::unique_ptr<TestStatement>>& statementsVector) {
TestStatement* currentStatement;
void TestParser::addStatementBlock(const std::string& blockName) {
if (testCase->variableStatements.find(blockName) != testCase->variableStatements.end()) {
for (const auto& statementPtr : testCase->variableStatements[blockName]) {
testCase->statements.push_back(std::make_unique<TestStatement>(*statementPtr));
}
} else {
throw Exception("Statement block not found [" + blockName + "]");
}
}

TestStatement* TestParser::addNewStatement() {
auto statement = std::make_unique<TestStatement>();
currentStatement = statement.get();
statementsVector.push_back(std::move(statement));
TestStatement* currentStatement = statement.get();
testCase->statements.push_back(std::move(statement));
return currentStatement;
}

Expand All @@ -209,7 +210,7 @@ void TestParser::openFile(const std::string& path) {
}

void TestParser::tokenize() {
currentToken.params = StringUtils::splitByAnySpace(line);
currentToken.params = StringUtils::splitBySpace(line);
if ((currentToken.params.size() == 0) || (currentToken.params[0][0] == '#')) {
currentToken.type = TokenType::EMPTY;
} else {
Expand Down

0 comments on commit ef5512d

Please sign in to comment.