diff --git a/src/common/string_utils.cpp b/src/common/string_utils.cpp index dc532b7c01a..f0143074701 100644 --- a/src/common/string_utils.cpp +++ b/src/common/string_utils.cpp @@ -19,7 +19,7 @@ std::vector StringUtils::split( return result; } -std::vector StringUtils::splitByAnySpace(const std::string& input) { +std::vector StringUtils::splitBySpace(const std::string& input) { std::istringstream iss(input); std::vector result; std::string token; diff --git a/src/include/common/string_utils.h b/src/include/common/string_utils.h index 1c6de49afc3..c31b936fe7d 100644 --- a/src/include/common/string_utils.h +++ b/src/include/common/string_utils.h @@ -21,7 +21,7 @@ class StringUtils { static std::vector split(const std::string& input, const std::string& delimiter); - static std::vector splitByAnySpace(const std::string& input); + static std::vector splitBySpace(const std::string& input); static void toUpper(std::string& input) { std::transform(input.begin(), input.end(), input.begin(), ::toupper); diff --git a/test/common/string_test.cpp b/test/common/string_test.cpp index 1e52eb637ff..181519b02ec 100644 --- a/test/common/string_test.cpp +++ b/test/common/string_test.cpp @@ -5,9 +5,9 @@ using namespace kuzu::common; -TEST(StringTest, splitByAnySpace) { +TEST(StringTest, splitBySpace) { std::string str = " a b c\td "; - std::vector result = StringUtils::splitByAnySpace(str); + std::vector result = StringUtils::splitBySpace(str); EXPECT_EQ(result.size(), 4); EXPECT_EQ(result[0], "a"); EXPECT_EQ(result[1], "b"); diff --git a/test/include/test_runner/test_case.h b/test/include/test_runner/test_case.h index 844d5011a28..b9fe7bd4908 100644 --- a/test/include/test_runner/test_case.h +++ b/test/include/test_runner/test_case.h @@ -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; @@ -27,7 +26,7 @@ struct TestCase { std::string name; std::string dataset; std::vector> statements; - std::vector> variableStatements; + std::unordered_map>> variableStatements; bool skipTest = false; diff --git a/test/include/test_runner/test_parser.h b/test/include/test_runner/test_parser.h index 74804ec8aa3..7fc997fceeb 100644 --- a/test/include/test_runner/test_parser.h +++ b/test/include/test_runner/test_parser.h @@ -1,11 +1,8 @@ #include #include "common/file_utils.h" -#include "main/kuzu.h" #include "test_runner/test_case.h" -using namespace kuzu::main; - namespace kuzu { namespace testing { @@ -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(getline(fileStream, line)); } @@ -87,7 +86,7 @@ class TestParser { TestStatement* extractStatement(TestStatement* currentStatement); - TestStatement* addNewStatement(std::vector>& statements); + TestStatement* addNewStatement(); }; } // namespace testing diff --git a/test/include/test_runner/test_runner.h b/test/include/test_runner/test_runner.h index 8c20641c0b1..e7622ca5840 100644 --- a/test/include/test_runner/test_runner.h +++ b/test/include/test_runner/test_runner.h @@ -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 { diff --git a/test/test_files/tinysnb/agg/hash.test b/test/test_files/tinysnb/agg/hash.test index 157e360279e..a432e7050a7 100644 --- a/test/test_files/tinysnb/agg/hash.test +++ b/test/test_files/tinysnb/agg/hash.test @@ -1,5 +1,5 @@ -GROUP TinySnbReadTest --TEST Agg +-TEST AggHash -DATASET tinysnb -- diff --git a/test/test_files/tinysnb/agg/multi_label.test b/test/test_files/tinysnb/agg/multi_label.test index fcb150a7f1a..818c5c92fcd 100644 --- a/test/test_files/tinysnb/agg/multi_label.test +++ b/test/test_files/tinysnb/agg/multi_label.test @@ -1,5 +1,5 @@ -GROUP TinySnbReadTest --TEST Agg +-TEST AggMultiLabel -DATASET tinysnb -- diff --git a/test/test_runner/test_parser.cpp b/test/test_runner/test_parser.cpp index c88e0d46f2d..c51a0b11da5 100644 --- a/test/test_runner/test_parser.cpp +++ b/test/test_runner/test_parser.cpp @@ -51,7 +51,6 @@ void TestParser::parseHeader() { } case TokenType::SEPARATOR: { return; - break; } default: { throw Exception("Invalid statement in test header"); @@ -96,7 +95,6 @@ TestStatement* TestParser::extractStatement(TestStatement* statement) { case TokenType::RESULT: { extractExpectedResult(statement); return statement; - break; } case TokenType::CHECK_ORDER: { statement->checkOutputOrder = true; @@ -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(); + extractStatement(statement.get()); + testCase->variableStatements[blockName].push_back(std::move(statement)); } } } @@ -157,20 +155,15 @@ 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(*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); } @@ -178,12 +171,20 @@ void TestParser::parseBody() { } } -TestStatement* TestParser::addNewStatement( - std::vector>& 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(*statementPtr)); + } + } else { + throw Exception("Statement block not found [" + blockName + "]"); + } +} + +TestStatement* TestParser::addNewStatement() { auto statement = std::make_unique(); - currentStatement = statement.get(); - statementsVector.push_back(std::move(statement)); + TestStatement* currentStatement = statement.get(); + testCase->statements.push_back(std::move(statement)); return currentStatement; } @@ -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 {