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(project_tests ${project_name}_tests) |
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLIBCLANGMM_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") |
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_HOME_DIRECTORY}/cmake/Modules/") |
include_directories(${LIBCLANG_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/src") |
||||||
|
|
||||||
add_definitions(-DBOOST_TEST_STATIC_LINK) |
add_executable(code_complete_results_test code_complete_results_test.cc) |
||||||
|
target_link_libraries(code_complete_results_test ${LIBCLANG_LIBRARIES} clangmm) |
||||||
message("Searching for libclang") |
add_test(code_complete_results_test code_complete_results_test) |
||||||
#LIBCLANG_FOUND System has libclang. |
|
||||||
#LIBCLANG_INCLUDE_DIRS The libclang include directories. |
add_executable(completion_string_test completion_string_test.cc) |
||||||
#LIBCLANG_LIBRARIES The libraries needed to use libclang. |
target_link_libraries(completion_string_test ${LIBCLANG_LIBRARIES} clangmm) |
||||||
#LIBCLANG_LIBRARY_DIR The path to the directory containing libclang. |
add_test(completion_string_test completion_string_test) |
||||||
#LIBCLANG_KNOWN_LLVM_VERSIONS Known LLVM release numbers. |
|
||||||
find_package(LibClang REQUIRED) |
add_executable(cursor_test cursor_test.cc) |
||||||
find_package(Boost 1.55 COMPONENTS unit_test_framework system filesystem REQUIRED) |
target_link_libraries(cursor_test ${LIBCLANG_LIBRARIES} clangmm) |
||||||
|
add_test(cursor_test cursor_test) |
||||||
add_executable(${project_tests} |
|
||||||
Entry.cc |
add_executable(diagnostics_test diagnostics_test.cc) |
||||||
TranslationUnit_Test.cc |
target_link_libraries(diagnostics_test ${LIBCLANG_LIBRARIES} clangmm) |
||||||
CompletionString_H_Test.cc |
add_test(diagnostics_test diagnostics_test) |
||||||
CodeCompleteResults_H_Test.cc |
|
||||||
Cursor_H_Test.cc |
add_executable(source_location_test source_location_test.cc) |
||||||
Token_H_Test.cc |
target_link_libraries(source_location_test ${LIBCLANG_LIBRARIES} clangmm) |
||||||
SourceLocation_H_Test.cc |
add_test(source_location_test source_location_test) |
||||||
Diagnostics_Test.cc |
|
||||||
) |
add_executable(token_test token_test.cc) |
||||||
|
target_link_libraries(token_test ${LIBCLANG_LIBRARIES} clangmm) |
||||||
include_directories(${LIBCLANG_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} "${CMAKE_SOURCE_DIR}/src") |
add_test(token_test token_test) |
||||||
target_link_libraries(${project_tests} ${LIBCLANG_LIBRARIES} ${Boost_LIBRARIES} clangmm) |
|
||||||
|
add_executable(translation_unit_test translation_unit_test.cc) |
||||||
set(tests |
target_link_libraries(translation_unit_test ${LIBCLANG_LIBRARIES} clangmm) |
||||||
${project_tests} |
add_test(translation_unit_test translation_unit_test) |
||||||
) |
|
||||||
|
|
||||||
add_test(${tests} ${tests}) |
|
||||||
|
|||||||
@ -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