usaxena95 updated this revision to Diff 223503. usaxena95 added a comment. Revert unintended formatting.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D68565/new/ https://reviews.llvm.org/D68565 Files: clang/unittests/Lex/LexerTest.cpp Index: clang/unittests/Lex/LexerTest.cpp =================================================================== --- clang/unittests/Lex/LexerTest.cpp +++ 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" @@ -22,6 +24,9 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "gtest/gtest.h" +#include <vector> + +namespace { using namespace clang; @@ -535,4 +540,22 @@ 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> ExpectedTokens = {"abcd", "=", "0", ";", "int", + "xyz", "=", "abcd", ";"}; + 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_EQ(ExpectedTokens, GeneratedByNextToken); +} } // anonymous namespace
Index: clang/unittests/Lex/LexerTest.cpp =================================================================== --- clang/unittests/Lex/LexerTest.cpp +++ 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" @@ -22,6 +24,9 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "gtest/gtest.h" +#include <vector> + +namespace { using namespace clang; @@ -535,4 +540,22 @@ 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> ExpectedTokens = {"abcd", "=", "0", ";", "int", + "xyz", "=", "abcd", ";"}; + 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_EQ(ExpectedTokens, GeneratedByNextToken); +} } // anonymous namespace
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits