Add basic test client (#156)

Co-authored-by: star9029 <hengxings783@gmail.com>
This commit is contained in:
ykiko
2025-07-21 17:55:10 +08:00
committed by GitHub
parent 583c560ba0
commit 836d9dc988
61 changed files with 439 additions and 640 deletions

View File

@@ -0,0 +1,68 @@
#include "Test/Test.h"
#include "AST/SourceCode.h"
namespace clice::testing {
TEST(SourceCode, tokenize) {
std::size_t count = 0;
/// Test breaking the loop.
tokenize("int x = 1;", [&](const clang::Token& token) {
count++;
return false;
});
EXPECT_EQ(count, 1);
/// Test all tokens.
count = 0;
std::vector<clang::tok::TokenKind> kinds = {
clang::tok::raw_identifier,
clang::tok::raw_identifier,
clang::tok::equal,
clang::tok::numeric_constant,
clang::tok::semi,
};
tokenize("int x = 1; // comment", [&](const clang::Token& token) {
if(token.is(clang::tok::eof)) [[unlikely]] {
return false;
}
EXPECT_EQ(token.getKind(), kinds[count]);
count++;
return true;
});
EXPECT_EQ(count, 5);
/// Test retain comments.
count = 0;
kinds = {
clang::tok::raw_identifier,
clang::tok::raw_identifier,
clang::tok::equal,
clang::tok::numeric_constant,
clang::tok::semi,
clang::tok::comment,
};
tokenize(
"int x = 1; /// comment",
[&](const clang::Token& token) {
if(token.is(clang::tok::eof)) [[unlikely]] {
return false;
}
EXPECT_EQ(token.getKind(), kinds[count]);
count++;
return true;
},
false);
EXPECT_EQ(count, 6);
}
} // namespace clice::testing