Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert e2e_update_node.cpp to e2e test files #1597

Merged
merged 5 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions test/include/test_runner/test_parser.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cstring>
#include <numeric>

#include "common/file_utils.h"
#include "test_runner/test_group.h"
Expand All @@ -7,13 +8,16 @@ namespace kuzu {
namespace testing {

enum class TokenType {
GROUP,
DATASET,
TEST,
/* header */
BEGIN_WRITE_TRANSACTION,
DATASET,
GROUP,
SKIP,
/* body */
BUFFER_POOL_SIZE,
CASE,
CHECK_ORDER,
DEFINE,
DEFINE_STATEMENT_BLOCK,
EMPTY,
ENCODED_JOIN,
Expand All @@ -22,29 +26,24 @@ enum class TokenType {
NAME,
PARALLELISM,
QUERY,
READ_ONLY,
RESULT,
SEPARATOR,
SKIP,
STATEMENT,
STATEMENT_BLOCK
};

const std::unordered_map<std::string, TokenType> tokenMap = {{"-GROUP", TokenType::GROUP},
{"-TEST", TokenType::TEST}, {"-DATASET", TokenType::DATASET}, {"-CASE", TokenType::CASE},
{"-DATASET", TokenType::DATASET}, {"-CASE", TokenType::CASE},
{"-CHECK_ORDER", TokenType::CHECK_ORDER}, {"-ENCODED_JOIN", TokenType::ENCODED_JOIN},
{"-DEFINE_STATEMENT_BLOCK", TokenType::DEFINE_STATEMENT_BLOCK},
{"-ENUMERATE", TokenType::ENUMERATE}, {"-NAME", TokenType::NAME},
{"-BEGIN_WRITE_TRANSACTION", TokenType::BEGIN_WRITE_TRANSACTION},
{"-PARALLELISM", TokenType::PARALLELISM}, {"-QUERY", TokenType::QUERY},
{"-READ_ONLY", TokenType::READ_ONLY}, {"-SKIP", TokenType::SKIP},
{"-SKIP", TokenType::SKIP}, {"-DEFINE", TokenType::DEFINE},
{"-STATEMENT", TokenType::STATEMENT}, {"-STATEMENT_BLOCK", TokenType::STATEMENT_BLOCK},
{"-BUFFER_POOL_SIZE", TokenType::BUFFER_POOL_SIZE}, {"]", TokenType::END_OF_STATEMENT_BLOCK},
{"----", TokenType::RESULT}, {"--", TokenType::SEPARATOR}, {"#", TokenType::EMPTY}};

const std::unordered_map<std::string, std::string> variableMap = {
{"${KUZU_ROOT_DIRECTORY}", KUZU_ROOT_DIRECTORY}};

class LogicToken {
public:
TokenType type;
Expand All @@ -64,9 +63,10 @@ class TestParser {
std::string line;
std::string name;
std::unique_ptr<TestGroup> testGroup;
std::string paramsToString();
std::string extractTextBeforeNextStatement();
std::string parseCommand();
LogicToken currentToken;

void openFile();
void tokenize();
void parseHeader();
Expand All @@ -75,21 +75,40 @@ class TestParser {
void extractStatementBlock();
void addStatementBlock(const std::string& blockName, const std::string& testGroupName);
void replaceVariables(std::string& str);

inline bool endOfFile() { return fileStream.eof(); }
inline void setCursorToPreviousLine() { fileStream.seekg(previousFilePosition); }

inline bool nextLine() {
previousFilePosition = fileStream.tellg();
return static_cast<bool>(getline(fileStream, line));
}

inline void checkMinimumParams(int minimumParams) {
if (currentToken.params.size() - 1 < minimumParams) {
throw common::TestException("Minimum number of parameters is " +
std::to_string(minimumParams) + ". [" + path + ":" + line +
"]");
}
}

inline std::string paramsToString(int startParamIdx) {
return std::accumulate(std::next(currentToken.params.begin(), startParamIdx),
currentToken.params.end(), std::string(),
[](const std::string& a, const std::string& b) {
return a + (a.empty() ? "" : " ") + b;
});
}

TestStatement* extractStatement(TestStatement* currentStatement);
TestStatement* addNewStatement(std::string& name);

// Any value here will be replaced inside the .test files
// in queries/statements and expected error message.
// Example: ${KUZU_ROOT_DIRECTORY} will be replaced by
// KUZU_ROOT_DIRECTORY
std::unordered_map<std::string, std::string> variableMap = {
{"KUZU_ROOT_DIRECTORY", KUZU_ROOT_DIRECTORY}};
};

} // namespace testing
Expand Down
1 change: 0 additions & 1 deletion test/runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ add_kuzu_test(e2e_ddl_test e2e_ddl_test.cpp)
add_kuzu_test(e2e_delete_create_transaction_test e2e_delete_create_transaction_test.cpp)
add_kuzu_test(e2e_read_test e2e_read_test.cpp)
add_kuzu_test(e2e_set_transaction_test e2e_set_transaction_test.cpp)
add_kuzu_test(e2e_update_node_test e2e_update_node_test.cpp)
add_kuzu_test(e2e_update_rel_test e2e_update_rel_test.cpp)
add_kuzu_test(e2e_delete_rel_test e2e_delete_rel_test.cpp)
add_kuzu_test(e2e_create_rel_test e2e_create_rel_test.cpp)
Loading
Loading