Fix external macro use when fast_preprocessing=false
Forget to add standard library includes... Fixes #39.
This commit is contained in:
parent
d2dc8907e2
commit
cc5127979b
3 changed files with 226 additions and 191 deletions
|
|
@ -136,185 +136,3 @@ b
|
|||
});
|
||||
REQUIRE(count == 1u);
|
||||
}
|
||||
|
||||
TEST_CASE("preprocessor line numbers")
|
||||
{
|
||||
auto code = R"(/// 1
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/// 5
|
||||
|
||||
#include <string>
|
||||
|
||||
int var;
|
||||
|
||||
/// 11
|
||||
|
||||
#define foo \
|
||||
\
|
||||
\
|
||||
int \
|
||||
main()
|
||||
|
||||
/// 19
|
||||
|
||||
foo {}
|
||||
|
||||
/// 23
|
||||
|
||||
/* C comment
|
||||
spanning
|
||||
multiple
|
||||
lines
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
/// 37
|
||||
)";
|
||||
|
||||
auto file = parse({}, "preprocessor_line_numbers.cpp", code);
|
||||
for (auto& comment : file->unmatched_comments())
|
||||
{
|
||||
if (comment.content[0] != '\n')
|
||||
REQUIRE(comment.line == std::stoi(comment.content));
|
||||
}
|
||||
REQUIRE((file->unmatched_comments().size() == 6u + 1u));
|
||||
}
|
||||
|
||||
TEST_CASE("comment content")
|
||||
{
|
||||
auto code = R"(
|
||||
/// simple comment
|
||||
|
||||
///no space
|
||||
|
||||
/// multi
|
||||
/// line
|
||||
/// comment
|
||||
|
||||
/** C comment */
|
||||
/**C comment no space*/
|
||||
|
||||
/** Multiline
|
||||
C
|
||||
comment
|
||||
with indent */
|
||||
|
||||
/** Multiline
|
||||
C
|
||||
comment
|
||||
with
|
||||
indent */
|
||||
|
||||
/** Multiline
|
||||
* C
|
||||
* comment
|
||||
* with
|
||||
* indent
|
||||
* star */
|
||||
)";
|
||||
|
||||
auto file = parse({}, "comment-content.cpp", code);
|
||||
auto comments = file->unmatched_comments();
|
||||
REQUIRE((comments.size() == 8u));
|
||||
|
||||
REQUIRE(comments[0u].content == "simple comment");
|
||||
REQUIRE(comments[1u].content == "no space");
|
||||
REQUIRE(comments[2u].content == "multi\nline\ncomment");
|
||||
REQUIRE(comments[3u].content == "C comment");
|
||||
REQUIRE(comments[4u].content == "C comment no space");
|
||||
REQUIRE(comments[5u].content == "Multiline\nC\n comment\nwith indent");
|
||||
REQUIRE(comments[6u].content == "Multiline\nC\n comment\n with\n indent");
|
||||
REQUIRE(comments[7u].content == "Multiline\nC\ncomment\nwith\nindent\nstar");
|
||||
}
|
||||
|
||||
TEST_CASE("comment matching")
|
||||
{
|
||||
auto code = R"(
|
||||
/// u
|
||||
|
||||
/// a
|
||||
/// a
|
||||
struct a {};
|
||||
|
||||
/// u
|
||||
/** b
|
||||
* b */
|
||||
void b(int, float)
|
||||
{
|
||||
auto c = '#';
|
||||
}
|
||||
|
||||
/** u */
|
||||
//! c
|
||||
/// c
|
||||
enum class c
|
||||
{
|
||||
d, //< d
|
||||
/// d
|
||||
e, //< e
|
||||
/// e
|
||||
|
||||
/** f
|
||||
f **/
|
||||
f,
|
||||
};
|
||||
|
||||
/// g
|
||||
/// g
|
||||
#define g(name) \
|
||||
class name \
|
||||
{ \
|
||||
};
|
||||
|
||||
/// h
|
||||
/// h
|
||||
g(h)
|
||||
|
||||
/*! i
|
||||
i */
|
||||
using i = int;
|
||||
|
||||
/// cstddef
|
||||
/// cstddef
|
||||
#include <cstddef>
|
||||
|
||||
/// j
|
||||
/// j
|
||||
template <typename T/**/>
|
||||
void j();
|
||||
)";
|
||||
|
||||
auto file = parse({}, "comment-matching.cpp", code);
|
||||
visit(*file, [&](const cpp_entity& e, visitor_info) {
|
||||
if (e.kind() == cpp_entity_kind::file_t)
|
||||
return true;
|
||||
else if (e.name().empty())
|
||||
return true;
|
||||
else if (is_templated(e))
|
||||
return true;
|
||||
|
||||
INFO(e.name());
|
||||
REQUIRE(e.comment());
|
||||
REQUIRE(e.comment().value() == e.name() + "\n" + e.name());
|
||||
return true;
|
||||
});
|
||||
|
||||
auto add = 0u;
|
||||
for (auto& comment : file->unmatched_comments())
|
||||
{
|
||||
if (comment.content == "cstddef\ncstddef")
|
||||
// happens if include parsing is not supported
|
||||
// error is still going to be detected because if it is supported, the entity will be matched above
|
||||
add = 1u;
|
||||
else
|
||||
REQUIRE(comment.content == "u");
|
||||
}
|
||||
REQUIRE((file->unmatched_comments().size() == 3u + add));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue