diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f0c2545d..fe189bfb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,60 @@ string(REPLACE " " "_" ProjectId ${ProjectId}) # set project name project(${ProjectId}) -INCLUDE(ExternalProject) +# external dependencies + +include(ExternalProject) +set(libs_dir "${CMAKE_SOURCE_DIR}/libs") + +# lemon +set(lemon_dir "${libs_dir}/lemon") +set(lemon_tag "f38a55106d79b7a4c063abb958517d6c47dc6ac7") +set(lemon_url "http://www.sqlite.org/src/raw/tool/lemon.c?name=${lemon_tag}") +ExternalProject_Add( + lemon + DOWNLOAD_COMMAND wget ${lemon_url} -O lemon.c + DOWNLOAD_DIR ${lemon_dir} + SOURCE_DIR ${lemon_dir} + BINARY_DIR ${lemon_dir} + CONFIGURE_COMMAND "" + BUILD_COMMAND clang lemon.c -o lemon -O2 + INSTALL_COMMAND "" + TEST_COMMAND "" +) + +# lempar +set(lempar_dir "${libs_dir}/lemon") +set(lempar_tag "404ea3dc27dbeed343f0e61b1d36e97b9f5f0fb6") +set(lempar_url "http://www.sqlite.org/src/raw/tool/lempar.c?name=${lempar_tag}") +ExternalProject_Add( + lempar + DOWNLOAD_COMMAND wget ${lempar_url} -O lempar.c + DOWNLOAD_DIR ${lempar_dir} + SOURCE_DIR ${lempar_dir} + BINARY_DIR ${lempar_dir} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) + +# build memgraph's cypher grammer +FILE(COPY ${CMAKE_SOURCE_DIR}/src/cypher/cypher.y DESTINATION ${CMAKE_BINARY_DIR}) +EXECUTE_PROCESS( + COMMAND ${lemon_dir}/lemon ${CMAKE_BINARY_DIR}/cypher.y -s + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +) +FILE(RENAME ${CMAKE_BINARY_DIR}/cypher.c ${CMAKE_BINARY_DIR}/cypher.cpp) + +# lexertl +ExternalProject_Add( + lexertl + GIT_REPOSITORY "https://github.com/BenHanson/lexertl.git" + GIT_TAG "7d4d36a357027df0e817453cc9cf948f71047ca9" + SOURCE_DIR "${libs_dir}/lexertl" + TEST_COMMAND "" + INSTALL_COMMAND "" +) # compiler options SET(COMPILE_OPTIONS "-O0 -g3 -Wall -Werror -fmessage-length=0") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 04053305c..277bce937 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,9 +28,13 @@ foreach(test_file ${test_files}) endforeach() MESSAGE(STATUS "Available tests are: ${tests}") +# copy test data +file(COPY ${CMAKE_SOURCE_DIR}/tests/data DESTINATION ${CMAKE_BINARY_DIR}/tests) + # build tests foreach(test ${tests}) add_executable(${test} ${test}.cpp) + target_link_libraries(${test} stdc++fs) add_test(NAME ${test} COMMAND ${test}) set_property(TARGET ${test} PROPERTY CXX_STANDARD 14) endforeach() diff --git a/tests/cypher_traversal.cpp b/tests/cypher_traversal.cpp index b5e798477..e2f024fb5 100644 --- a/tests/cypher_traversal.cpp +++ b/tests/cypher_traversal.cpp @@ -4,27 +4,46 @@ #include "cypher/compiler.hpp" #include "cypher/debug/tree_print.hpp" +#include +#include +#include +#include +#include +#include + +namespace fs = std::experimental::filesystem; + using std::cout; using std::endl; -int calc(int i) +std::vector load_queries() { - return i + 1; + std::vector queries; + fs::path queries_path = "data/cypher_queries"; + for (auto& directory_entry : + fs::recursive_directory_iterator(queries_path)) { + if (!fs::is_regular_file(directory_entry)) + continue; + std::ifstream infile(directory_entry.path().c_str()); + if (infile) { + std::string file_text((std::istreambuf_iterator(infile)), + std::istreambuf_iterator()); + queries.emplace_back(file_text); + } + } + return queries; } int main() { - // TODO - // auto print_visitor = new PrintVisitor(cout); + auto queries = load_queries(); - // // create AST - // cypher::Compiler compiler; - // auto tree = compiler.syntax_tree("MATCH (n) DELETE n"); - - // // traverser the tree - // tree.root->accept(*print_visitor); - // - assert(calc(0) == 1); + for (auto& query : queries) { + auto print_visitor = new PrintVisitor(cout); + cypher::Compiler compiler; + auto tree = compiler.syntax_tree(query); + tree.root->accept(*print_visitor); + } return 0; } diff --git a/src/cypher/query/read-write/match-delete.cypher b/tests/data/cypher_queries/read-write/match-delete.cypher similarity index 100% rename from src/cypher/query/read-write/match-delete.cypher rename to tests/data/cypher_queries/read-write/match-delete.cypher diff --git a/src/cypher/query/read-write/match-set-return.cypher b/tests/data/cypher_queries/read-write/match-set-return.cypher similarity index 100% rename from src/cypher/query/read-write/match-set-return.cypher rename to tests/data/cypher_queries/read-write/match-set-return.cypher diff --git a/src/cypher/query/read-write/match-set.cypher b/tests/data/cypher_queries/read-write/match-set.cypher similarity index 100% rename from src/cypher/query/read-write/match-set.cypher rename to tests/data/cypher_queries/read-write/match-set.cypher diff --git a/src/cypher/query/read-write/match-where-delete.cypher b/tests/data/cypher_queries/read-write/match-where-delete.cypher similarity index 100% rename from src/cypher/query/read-write/match-where-delete.cypher rename to tests/data/cypher_queries/read-write/match-where-delete.cypher diff --git a/src/cypher/query/read/match/match-custom1.cypher b/tests/data/cypher_queries/read/match/match-custom1.cypher similarity index 100% rename from src/cypher/query/read/match/match-custom1.cypher rename to tests/data/cypher_queries/read/match/match-custom1.cypher diff --git a/src/cypher/query/read/match/match-custom2.cypher b/tests/data/cypher_queries/read/match/match-custom2.cypher similarity index 100% rename from src/cypher/query/read/match/match-custom2.cypher rename to tests/data/cypher_queries/read/match/match-custom2.cypher diff --git a/src/cypher/query/read/match/match-n-m.cypher b/tests/data/cypher_queries/read/match/match-n-m.cypher similarity index 100% rename from src/cypher/query/read/match/match-n-m.cypher rename to tests/data/cypher_queries/read/match/match-n-m.cypher diff --git a/src/cypher/query/read/match/match-optional.cypher b/tests/data/cypher_queries/read/match/match-optional.cypher similarity index 100% rename from src/cypher/query/read/match/match-optional.cypher rename to tests/data/cypher_queries/read/match/match-optional.cypher diff --git a/src/cypher/query/read/match/match-path.cypher b/tests/data/cypher_queries/read/match/match-path.cypher similarity index 100% rename from src/cypher/query/read/match/match-path.cypher rename to tests/data/cypher_queries/read/match/match-path.cypher diff --git a/src/cypher/query/read/match/match-property.cypher b/tests/data/cypher_queries/read/match/match-property.cypher similarity index 100% rename from src/cypher/query/read/match/match-property.cypher rename to tests/data/cypher_queries/read/match/match-property.cypher diff --git a/src/cypher/query/read/match/match-where.cypher b/tests/data/cypher_queries/read/match/match-where.cypher similarity index 100% rename from src/cypher/query/read/match/match-where.cypher rename to tests/data/cypher_queries/read/match/match-where.cypher diff --git a/src/cypher/query/read/return/return-alias.cypher b/tests/data/cypher_queries/read/return/return-alias.cypher similarity index 100% rename from src/cypher/query/read/return/return-alias.cypher rename to tests/data/cypher_queries/read/return/return-alias.cypher diff --git a/src/cypher/query/read/return/return-all.cypher b/tests/data/cypher_queries/read/return/return-all.cypher similarity index 100% rename from src/cypher/query/read/return/return-all.cypher rename to tests/data/cypher_queries/read/return/return-all.cypher diff --git a/src/cypher/query/read/return/return-count.cypher b/tests/data/cypher_queries/read/return/return-count.cypher similarity index 100% rename from src/cypher/query/read/return/return-count.cypher rename to tests/data/cypher_queries/read/return/return-count.cypher diff --git a/src/cypher/query/read/return/return-distinct.cypher b/tests/data/cypher_queries/read/return/return-distinct.cypher similarity index 100% rename from src/cypher/query/read/return/return-distinct.cypher rename to tests/data/cypher_queries/read/return/return-distinct.cypher diff --git a/src/cypher/query/read/return/return-limit.cypher b/tests/data/cypher_queries/read/return/return-limit.cypher similarity index 100% rename from src/cypher/query/read/return/return-limit.cypher rename to tests/data/cypher_queries/read/return/return-limit.cypher diff --git a/src/cypher/query/read/return/return-order-asc.cypher b/tests/data/cypher_queries/read/return/return-order-asc.cypher similarity index 100% rename from src/cypher/query/read/return/return-order-asc.cypher rename to tests/data/cypher_queries/read/return/return-order-asc.cypher diff --git a/src/cypher/query/read/return/return-order-desc.cypher b/tests/data/cypher_queries/read/return/return-order-desc.cypher similarity index 100% rename from src/cypher/query/read/return/return-order-desc.cypher rename to tests/data/cypher_queries/read/return/return-order-desc.cypher diff --git a/src/cypher/query/read/return/return-skip-limit.cypher b/tests/data/cypher_queries/read/return/return-skip-limit.cypher similarity index 100% rename from src/cypher/query/read/return/return-skip-limit.cypher rename to tests/data/cypher_queries/read/return/return-skip-limit.cypher diff --git a/src/cypher/query/read/return/return-skip.cypher b/tests/data/cypher_queries/read/return/return-skip.cypher similarity index 100% rename from src/cypher/query/read/return/return-skip.cypher rename to tests/data/cypher_queries/read/return/return-skip.cypher diff --git a/src/cypher/query/read/union/union-all.cypher b/tests/data/cypher_queries/read/union/union-all.cypher similarity index 100% rename from src/cypher/query/read/union/union-all.cypher rename to tests/data/cypher_queries/read/union/union-all.cypher diff --git a/src/cypher/query/read/union/union.cypher b/tests/data/cypher_queries/read/union/union.cypher similarity index 100% rename from src/cypher/query/read/union/union.cypher rename to tests/data/cypher_queries/read/union/union.cypher diff --git a/src/cypher/query/read/where/where.cypher b/tests/data/cypher_queries/read/where/where.cypher similarity index 100% rename from src/cypher/query/read/where/where.cypher rename to tests/data/cypher_queries/read/where/where.cypher diff --git a/src/cypher/query/read/with/match-with-order-skip-limit.cypher b/tests/data/cypher_queries/read/with/match-with-order-skip-limit.cypher similarity index 100% rename from src/cypher/query/read/with/match-with-order-skip-limit.cypher rename to tests/data/cypher_queries/read/with/match-with-order-skip-limit.cypher diff --git a/src/cypher/query/read/with/match-with-where.cypher b/tests/data/cypher_queries/read/with/match-with-where.cypher similarity index 100% rename from src/cypher/query/read/with/match-with-where.cypher rename to tests/data/cypher_queries/read/with/match-with-where.cypher diff --git a/src/cypher/query/write/create-return.cypher b/tests/data/cypher_queries/write/create-return.cypher similarity index 100% rename from src/cypher/query/write/create-return.cypher rename to tests/data/cypher_queries/write/create-return.cypher diff --git a/src/cypher/query/write/create.cypher b/tests/data/cypher_queries/write/create.cypher similarity index 100% rename from src/cypher/query/write/create.cypher rename to tests/data/cypher_queries/write/create.cypher