Skip to content

Commit

Permalink
[clang] Add test for FindNextToken in Lexer.
Browse files Browse the repository at this point in the history
Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68565

llvm-svn: 373910
  • Loading branch information
usx95 committed Oct 7, 2019
1 parent 9f4de84 commit edf5027
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions clang/unittests/Lex/LexerTest.cpp
Expand Up @@ -11,21 +11,25 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/MacroArgs.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/ModuleLoader.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

using namespace clang;
#include <vector>

namespace {
using namespace clang;
using testing::ElementsAre;

// The test fixture.
class LexerTest : public ::testing::Test {
Expand Down Expand Up @@ -535,4 +539,21 @@ TEST_F(LexerTest, CharRangeOffByOne) {
EXPECT_EQ(Lexer::getSourceText(CR, SourceMgr, LangOpts), "MOO"); // Was "MO".
}

TEST_F(LexerTest, FindNextToken) {
Lex("int abcd = 0;\n"
"int xyz = abcd;\n");
std::vector<std::string> GeneratedByNextToken;
SourceLocation Loc =
SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
while (true) {
auto T = Lexer::findNextToken(Loc, SourceMgr, LangOpts);
ASSERT_TRUE(T.hasValue());
if (T->is(tok::eof))
break;
GeneratedByNextToken.push_back(getSourceText(*T, *T));
Loc = T->getLocation();
}
EXPECT_THAT(GeneratedByNextToken, ElementsAre("abcd", "=", "0", ";", "int",
"xyz", "=", "abcd", ";"));
}
} // anonymous namespace

0 comments on commit edf5027

Please sign in to comment.