mirror of https://gitlab.com/cppit/libclangmm
18 changed files with 161 additions and 181 deletions
@ -1,36 +1,33 @@
|
||||
set(project_tests ${project_name}_tests) |
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") |
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_HOME_DIRECTORY}/cmake/Modules/") |
||||
|
||||
add_definitions(-DBOOST_TEST_STATIC_LINK) |
||||
|
||||
message("Searching for libclang") |
||||
#LIBCLANG_FOUND System has libclang. |
||||
#LIBCLANG_INCLUDE_DIRS The libclang include directories. |
||||
#LIBCLANG_LIBRARIES The libraries needed to use libclang. |
||||
#LIBCLANG_LIBRARY_DIR The path to the directory containing libclang. |
||||
#LIBCLANG_KNOWN_LLVM_VERSIONS Known LLVM release numbers. |
||||
find_package(LibClang REQUIRED) |
||||
find_package(Boost 1.55 COMPONENTS unit_test_framework system filesystem REQUIRED) |
||||
|
||||
add_executable(${project_tests} |
||||
Entry.cc |
||||
TranslationUnit_Test.cc |
||||
CompletionString_H_Test.cc |
||||
CodeCompleteResults_H_Test.cc |
||||
Cursor_H_Test.cc |
||||
Token_H_Test.cc |
||||
SourceLocation_H_Test.cc |
||||
Diagnostics_Test.cc |
||||
) |
||||
|
||||
include_directories(${LIBCLANG_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} "${CMAKE_SOURCE_DIR}/src") |
||||
target_link_libraries(${project_tests} ${LIBCLANG_LIBRARIES} ${Boost_LIBRARIES} clangmm) |
||||
|
||||
set(tests |
||||
${project_tests} |
||||
) |
||||
|
||||
add_test(${tests} ${tests}) |
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLIBCLANGMM_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") |
||||
|
||||
include_directories(${LIBCLANG_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/src") |
||||
|
||||
add_executable(code_complete_results_test code_complete_results_test.cc) |
||||
target_link_libraries(code_complete_results_test ${LIBCLANG_LIBRARIES} clangmm) |
||||
add_test(code_complete_results_test code_complete_results_test) |
||||
|
||||
add_executable(completion_string_test completion_string_test.cc) |
||||
target_link_libraries(completion_string_test ${LIBCLANG_LIBRARIES} clangmm) |
||||
add_test(completion_string_test completion_string_test) |
||||
|
||||
add_executable(cursor_test cursor_test.cc) |
||||
target_link_libraries(cursor_test ${LIBCLANG_LIBRARIES} clangmm) |
||||
add_test(cursor_test cursor_test) |
||||
|
||||
add_executable(diagnostics_test diagnostics_test.cc) |
||||
target_link_libraries(diagnostics_test ${LIBCLANG_LIBRARIES} clangmm) |
||||
add_test(diagnostics_test diagnostics_test) |
||||
|
||||
add_executable(source_location_test source_location_test.cc) |
||||
target_link_libraries(source_location_test ${LIBCLANG_LIBRARIES} clangmm) |
||||
add_test(source_location_test source_location_test) |
||||
|
||||
add_executable(token_test token_test.cc) |
||||
target_link_libraries(token_test ${LIBCLANG_LIBRARIES} clangmm) |
||||
add_test(token_test token_test) |
||||
|
||||
add_executable(translation_unit_test translation_unit_test.cc) |
||||
target_link_libraries(translation_unit_test ${LIBCLANG_LIBRARIES} clangmm) |
||||
add_test(translation_unit_test translation_unit_test) |
||||
|
||||
@ -1,36 +0,0 @@
|
||||
#include <boost/test/unit_test.hpp> |
||||
#include "clangmm.h" |
||||
#include <string> |
||||
|
||||
BOOST_AUTO_TEST_CASE(completion_chunk) { |
||||
clangmm::CompletionChunk str("(", clangmm::CompletionChunk_LeftBrace); |
||||
|
||||
BOOST_CHECK(str.chunk == "("); |
||||
BOOST_CHECK(str.kind == clangmm::CompletionChunk_LeftBrace); |
||||
} |
||||
|
||||
BOOST_AUTO_TEST_CASE(completion_string) { |
||||
|
||||
// [ Should be changed with mockery
|
||||
|
||||
std::string path("./case/main.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
|
||||
std::string buffer="#include <string>\n" |
||||
"int main(int argc, char *argv[]) {\n" |
||||
"std::string str;\n" |
||||
"str.\n" |
||||
"return 0\n" |
||||
"}"; |
||||
|
||||
tu.reparse(buffer); |
||||
auto results=tu.get_code_completions(buffer, 4, 5); |
||||
// ]
|
||||
|
||||
auto str = results.get(0); |
||||
|
||||
BOOST_CHECK(str.get_num_chunks()>0); |
||||
BOOST_CHECK(str.get_chunks().size()>0); |
||||
} |
||||
@ -1,18 +0,0 @@
|
||||
#include <boost/test/unit_test.hpp> |
||||
#include "clangmm.h" |
||||
#include <string> |
||||
|
||||
BOOST_AUTO_TEST_CASE(cursor) { |
||||
// [ Should be changed with mockery
|
||||
|
||||
std::string path("./case/main.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
|
||||
// ]
|
||||
|
||||
auto cursor=tu.get_cursor(path, 103); |
||||
|
||||
BOOST_CHECK(cursor.get_kind() == clangmm::Cursor::Kind::ReturnStmt); |
||||
} |
||||
@ -1,19 +0,0 @@
|
||||
#include <boost/test/unit_test.hpp> |
||||
#include "clangmm.h" |
||||
#include <iostream> |
||||
#include <fstream> |
||||
|
||||
using namespace std; |
||||
|
||||
BOOST_AUTO_TEST_CASE(diagnostics_test) { |
||||
std::string path("./case/main_error.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
|
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
|
||||
auto diagnostics=tu.get_diagnostics(); |
||||
BOOST_CHECK(diagnostics.size()>0); |
||||
BOOST_CHECK(!diagnostics[0].spelling.empty()); |
||||
BOOST_CHECK(diagnostics[0].severity==3); |
||||
} |
||||
@ -1,2 +0,0 @@
|
||||
#define BOOST_TEST_MODULE clangmm_tests |
||||
#include <boost/test/included/unit_test.hpp> |
||||
@ -1,17 +0,0 @@
|
||||
#include <boost/test/unit_test.hpp> |
||||
#include "clangmm.h" |
||||
#include <string> |
||||
|
||||
BOOST_AUTO_TEST_CASE(source_location) { |
||||
std::string path("./case/main.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
|
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
auto tokens=tu.get_tokens(0, 113); |
||||
|
||||
auto offsets=(*tokens)[28].offsets; |
||||
|
||||
BOOST_CHECK(offsets.first.line == 6 && offsets.first.index == 3); |
||||
BOOST_CHECK(offsets.second.line == 6 && offsets.second.index == 9); |
||||
} |
||||
@ -1,19 +0,0 @@
|
||||
#include <boost/test/unit_test.hpp> |
||||
#include "clangmm.h" |
||||
#include <string> |
||||
|
||||
BOOST_AUTO_TEST_CASE(token) { |
||||
std::string path("./case/main.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
|
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
|
||||
auto tokens=tu.get_tokens(0, 113); |
||||
|
||||
BOOST_CHECK(tokens->size() == 32); |
||||
BOOST_CHECK((*tokens)[1].get_kind() == clangmm::Token::Kind::Identifier); |
||||
|
||||
std::string str = (*tokens)[28].get_spelling(); |
||||
BOOST_CHECK(str == "return");
|
||||
} |
||||
@ -0,0 +1,35 @@
|
||||
#include "clangmm.h" |
||||
#include <string> |
||||
#include <cassert> |
||||
|
||||
int main() { |
||||
{ |
||||
clangmm::CompletionChunk str("(", clangmm::CompletionChunk_LeftBrace); |
||||
|
||||
assert(str.chunk == "("); |
||||
assert(str.kind == clangmm::CompletionChunk_LeftBrace); |
||||
} |
||||
|
||||
{ |
||||
std::string tests_path=LIBCLANGMM_TESTS_PATH; |
||||
std::string path(tests_path+"/case/main.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
|
||||
std::string buffer="#include <string>\n" |
||||
"int main(int argc, char *argv[]) {\n" |
||||
"std::string str;\n" |
||||
"str.\n" |
||||
"return 0\n" |
||||
"}"; |
||||
|
||||
tu.reparse(buffer); |
||||
auto results=tu.get_code_completions(buffer, 4, 5); |
||||
|
||||
auto str = results.get(0); |
||||
|
||||
assert(str.get_num_chunks()>0); |
||||
assert(str.get_chunks().size()>0); |
||||
} |
||||
} |
||||
@ -0,0 +1,15 @@
|
||||
#include "clangmm.h" |
||||
#include <string> |
||||
#include <cassert> |
||||
|
||||
int main() { |
||||
std::string tests_path=LIBCLANGMM_TESTS_PATH; |
||||
std::string path(tests_path+"/case/main.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
|
||||
auto cursor=tu.get_cursor(path, 103); |
||||
|
||||
assert(cursor.get_kind() == clangmm::Cursor::Kind::ReturnStmt); |
||||
} |
||||
@ -0,0 +1,20 @@
|
||||
#include "clangmm.h" |
||||
#include <iostream> |
||||
#include <fstream> |
||||
#include <cassert> |
||||
|
||||
using namespace std; |
||||
|
||||
int main() { |
||||
std::string tests_path=LIBCLANGMM_TESTS_PATH; |
||||
std::string path(tests_path+"/case/main_error.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
|
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
|
||||
auto diagnostics=tu.get_diagnostics(); |
||||
assert(diagnostics.size()>0); |
||||
assert(!diagnostics[0].spelling.empty()); |
||||
assert(diagnostics[0].severity==3); |
||||
} |
||||
@ -0,0 +1,18 @@
|
||||
#include "clangmm.h" |
||||
#include <string> |
||||
#include <cassert> |
||||
|
||||
int main() { |
||||
std::string tests_path=LIBCLANGMM_TESTS_PATH; |
||||
std::string path(tests_path+"/case/main.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
|
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
auto tokens=tu.get_tokens(0, 113); |
||||
|
||||
auto offsets=(*tokens)[28].get_source_range().get_offsets(); |
||||
|
||||
assert(offsets.first.line == 6 && offsets.first.index == 3); |
||||
assert(offsets.second.line == 6 && offsets.second.index == 9); |
||||
} |
||||
@ -0,0 +1,20 @@
|
||||
#include "clangmm.h" |
||||
#include <string> |
||||
#include <cassert> |
||||
|
||||
int main() { |
||||
std::string tests_path=LIBCLANGMM_TESTS_PATH; |
||||
std::string path(tests_path+"/case/main.cpp"); |
||||
|
||||
clangmm::Index index(0, 0); |
||||
|
||||
clangmm::TranslationUnit tu(index, path, {}); |
||||
|
||||
auto tokens=tu.get_tokens(0, 113); |
||||
|
||||
assert(tokens->size() == 32); |
||||
assert((*tokens)[1].get_kind() == clangmm::Token::Kind::Identifier); |
||||
|
||||
std::string str = (*tokens)[28].get_spelling(); |
||||
assert(str == "return");
|
||||
} |
||||
Loading…
Reference in new issue