diff options
author | Utkarsh Saxena <usx@google.com> | 2019-10-07 14:20:46 +0000 |
---|---|---|
committer | Utkarsh Saxena <usx@google.com> | 2019-10-07 14:20:46 +0000 |
commit | edf5027689c5b63c94262c17a7b8a87de9c55fb1 (patch) | |
tree | 4e0b3b728b2b04166502340c5ea004f9af711cef /clang/unittests/Lex/LexerTest.cpp | |
parent | 9f4de84eb0e0f69de66e5fdf99b63678264f3726 (diff) | |
download | llvm-edf5027689c5b63c94262c17a7b8a87de9c55fb1.zip llvm-edf5027689c5b63c94262c17a7b8a87de9c55fb1.tar.gz llvm-edf5027689c5b63c94262c17a7b8a87de9c55fb1.tar.bz2 |
[clang] Add test for FindNextToken in Lexer.
Reviewers: ilya-biryukov
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68565
llvm-svn: 373910
Diffstat (limited to 'clang/unittests/Lex/LexerTest.cpp')
-rw-r--r-- | clang/unittests/Lex/LexerTest.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp index 2295a90..ad9010e 100644 --- a/clang/unittests/Lex/LexerTest.cpp +++ b/clang/unittests/Lex/LexerTest.cpp @@ -11,9 +11,11 @@ #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" @@ -21,11 +23,13 @@ #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 { @@ -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 |