diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-07-19 07:02:30 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-07-19 07:02:30 +0000 |
| commit | de51d671486b6ac9a2ad9ee5fcfdb1a23cc59238 (patch) | |
| tree | 17ff629bd1f00b82d8dbb66a022e2f59e218c3c2 /unittests | |
| parent | 8746d127c04f5bbaf6c6e88cef8606ca5a6a54e9 (diff) | |
Notes
Diffstat (limited to 'unittests')
| -rw-r--r-- | unittests/ASTMatchers/Dynamic/ParserTest.cpp | 4 | ||||
| -rw-r--r-- | unittests/Format/FormatTest.cpp | 11 | ||||
| -rw-r--r-- | unittests/Format/FormatTestJS.cpp | 11 | ||||
| -rw-r--r-- | unittests/Format/SortImportsTestJS.cpp | 17 | ||||
| -rw-r--r-- | unittests/Lex/LexerTest.cpp | 6 | ||||
| -rw-r--r-- | unittests/Tooling/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | unittests/Tooling/DiagnosticsYamlTest.cpp | 167 |
7 files changed, 212 insertions, 5 deletions
diff --git a/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/unittests/ASTMatchers/Dynamic/ParserTest.cpp index ed184a8c1497..0c4c7dfd7802 100644 --- a/unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ b/unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -80,8 +80,8 @@ TEST(ParserTest, ParseBoolean) { Sema.parse("true"); Sema.parse("false"); EXPECT_EQ(2U, Sema.Values.size()); - EXPECT_EQ(true, Sema.Values[0].getBoolean()); - EXPECT_EQ(false, Sema.Values[1].getBoolean()); + EXPECT_TRUE(Sema.Values[0].getBoolean()); + EXPECT_FALSE(Sema.Values[1].getBoolean()); } TEST(ParserTest, ParseDouble) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 937362f5c9d7..f533ebf2234b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -333,6 +333,16 @@ TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) { verifyFormat("x = (a) xor (b);"); } +TEST_F(FormatTest, RecognizesUnaryOperatorKeywords) { + verifyFormat("x = compl(a);"); + verifyFormat("x = not(a);"); + verifyFormat("x = bitand(a);"); + // Unary operator must not be merged with the next identifier + verifyFormat("x = compl a;"); + verifyFormat("x = not a;"); + verifyFormat("x = bitand a;"); +} + //===----------------------------------------------------------------------===// // Tests for control statements. //===----------------------------------------------------------------------===// @@ -5340,6 +5350,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("x = *a(x) = *a(y);", Left); verifyFormat("for (;; *a = b) {\n}", Left); verifyFormat("return *this += 1;", Left); + verifyFormat("throw *x;", Left); verifyIndependentOfContext("a = *(x + y);"); verifyIndependentOfContext("a = &(x + y);"); diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 11e386a1c7c7..c256ebe46263 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1464,6 +1464,17 @@ TEST_F(FormatTestJS, ImportWrapping) { " A,\n" "} from 'some/module.js';", Style); + Style.ColumnLimit = 40; + // Using this version of verifyFormat because test::messUp hides the issue. + verifyFormat("import {\n" + " A,\n" + "} from\n" + " 'some/path/longer/than/column/limit/module.js';", + " import { \n" + " A, \n" + " } from\n" + " 'some/path/longer/than/column/limit/module.js' ; ", + Style); } TEST_F(FormatTestJS, TemplateStrings) { diff --git a/unittests/Format/SortImportsTestJS.cpp b/unittests/Format/SortImportsTestJS.cpp index 7e766e1969e1..4208b29702dd 100644 --- a/unittests/Format/SortImportsTestJS.cpp +++ b/unittests/Format/SortImportsTestJS.cpp @@ -283,6 +283,23 @@ TEST_F(SortImportsTestJS, SortCaseInsensitive) { "1;"); } +TEST_F(SortImportsTestJS, SortMultiLine) { + // Reproduces issue where multi-line import was not parsed correctly. + verifySort("import {A} from 'a';\n" + "import {A} from 'b';\n" + "\n" + "1;", + "import\n" + "{\n" + "A\n" + "}\n" + "from\n" + "'b';\n" + "import {A} from 'a';\n" + "\n" + "1;"); +} + } // end namespace } // end namespace format } // end namespace clang diff --git a/unittests/Lex/LexerTest.cpp b/unittests/Lex/LexerTest.cpp index a887c22bd301..923aff18472b 100644 --- a/unittests/Lex/LexerTest.cpp +++ b/unittests/Lex/LexerTest.cpp @@ -379,11 +379,11 @@ TEST_F(LexerTest, DontOverallocateStringifyArgs) { auto PP = CreatePP("\"StrArg\", 5, 'C'", ModLoader); llvm::BumpPtrAllocator Allocator; - std::array<IdentifierInfo *, 3> ArgList; + std::array<IdentifierInfo *, 3> ParamList; MacroInfo *MI = PP->AllocateMacroInfo({}); MI->setIsFunctionLike(); - MI->setArgumentList(ArgList, Allocator); - EXPECT_EQ(3u, MI->getNumArgs()); + MI->setParameterList(ParamList, Allocator); + EXPECT_EQ(3u, MI->getNumParams()); EXPECT_TRUE(MI->isFunctionLike()); Token Eof; diff --git a/unittests/Tooling/CMakeLists.txt b/unittests/Tooling/CMakeLists.txt index 8ed35480cb88..1359c7cabd1e 100644 --- a/unittests/Tooling/CMakeLists.txt +++ b/unittests/Tooling/CMakeLists.txt @@ -14,6 +14,7 @@ add_clang_unittest(ToolingTests CastExprTest.cpp CommentHandlerTest.cpp CompilationDatabaseTest.cpp + DiagnosticsYamlTest.cpp FixItTest.cpp LookupTest.cpp QualTypeNamesTest.cpp diff --git a/unittests/Tooling/DiagnosticsYamlTest.cpp b/unittests/Tooling/DiagnosticsYamlTest.cpp new file mode 100644 index 000000000000..83e09eaeef2d --- /dev/null +++ b/unittests/Tooling/DiagnosticsYamlTest.cpp @@ -0,0 +1,167 @@ +//===- unittests/Tooling/DiagnosticsYamlTest.cpp - Serialization tests ---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Tests for serialization of Diagnostics. +// +//===----------------------------------------------------------------------===// + +#include "clang/Tooling/DiagnosticsYaml.h" +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Tooling/ReplacementsYaml.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace clang::tooling; +using clang::tooling::Diagnostic; + +static Diagnostic makeDiagnostic(StringRef DiagnosticName, + const std::string &Message, int FileOffset, + const std::string &FilePath, + const StringMap<Replacements> &Fix) { + DiagnosticMessage DiagMessage; + DiagMessage.Message = Message; + DiagMessage.FileOffset = FileOffset; + DiagMessage.FilePath = FilePath; + return Diagnostic(DiagnosticName, DiagMessage, Fix, {}, Diagnostic::Warning, + "path/to/build/directory"); +} + +TEST(DiagnosticsYamlTest, serializesDiagnostics) { + TranslationUnitDiagnostics TUD; + TUD.MainSourceFile = "path/to/source.cpp"; + + StringMap<Replacements> Fix1 = { + {"path/to/source.cpp", + Replacements({"path/to/source.cpp", 100, 12, "replacement #1"})}}; + TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#1", "message #1", 55, + "path/to/source.cpp", Fix1)); + + StringMap<Replacements> Fix2 = { + {"path/to/header.h", + Replacements({"path/to/header.h", 62, 2, "replacement #2"})}}; + TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#2", "message #2", 60, + "path/to/header.h", Fix2)); + + TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#3", "message #3", 72, + "path/to/source2.cpp", {})); + + std::string YamlContent; + raw_string_ostream YamlContentStream(YamlContent); + + yaml::Output YAML(YamlContentStream); + YAML << TUD; + + EXPECT_EQ("---\n" + "MainSourceFile: path/to/source.cpp\n" + "Diagnostics: \n" + " - DiagnosticName: 'diagnostic#1\'\n" + " Message: 'message #1'\n" + " FileOffset: 55\n" + " FilePath: path/to/source.cpp\n" + " Replacements: \n" + " - FilePath: path/to/source.cpp\n" + " Offset: 100\n" + " Length: 12\n" + " ReplacementText: 'replacement #1'\n" + " - DiagnosticName: 'diagnostic#2'\n" + " Message: 'message #2'\n" + " FileOffset: 60\n" + " FilePath: path/to/header.h\n" + " Replacements: \n" + " - FilePath: path/to/header.h\n" + " Offset: 62\n" + " Length: 2\n" + " ReplacementText: 'replacement #2'\n" + " - DiagnosticName: 'diagnostic#3'\n" + " Message: 'message #3'\n" + " FileOffset: 72\n" + " FilePath: path/to/source2.cpp\n" + " Replacements: \n" + "...\n", + YamlContentStream.str()); +} + +TEST(DiagnosticsYamlTest, deserializesDiagnostics) { + std::string YamlContent = "---\n" + "MainSourceFile: path/to/source.cpp\n" + "Diagnostics: \n" + " - DiagnosticName: 'diagnostic#1'\n" + " Message: 'message #1'\n" + " FileOffset: 55\n" + " FilePath: path/to/source.cpp\n" + " Replacements: \n" + " - FilePath: path/to/source.cpp\n" + " Offset: 100\n" + " Length: 12\n" + " ReplacementText: 'replacement #1'\n" + " - DiagnosticName: 'diagnostic#2'\n" + " Message: 'message #2'\n" + " FileOffset: 60\n" + " FilePath: path/to/header.h\n" + " Replacements: \n" + " - FilePath: path/to/header.h\n" + " Offset: 62\n" + " Length: 2\n" + " ReplacementText: 'replacement #2'\n" + " - DiagnosticName: 'diagnostic#3'\n" + " Message: 'message #3'\n" + " FileOffset: 98\n" + " FilePath: path/to/source.cpp\n" + " Replacements: \n" + "...\n"; + TranslationUnitDiagnostics TUDActual; + yaml::Input YAML(YamlContent); + YAML >> TUDActual; + + ASSERT_FALSE(YAML.error()); + ASSERT_EQ(3u, TUDActual.Diagnostics.size()); + EXPECT_EQ("path/to/source.cpp", TUDActual.MainSourceFile); + + auto getFixes = [](const StringMap<Replacements> &Fix) { + std::vector<Replacement> Fixes; + for (auto &Replacements : Fix) { + for (auto &Replacement : Replacements.second) { + Fixes.push_back(Replacement); + } + } + return Fixes; + }; + + Diagnostic D1 = TUDActual.Diagnostics[0]; + EXPECT_EQ("diagnostic#1", D1.DiagnosticName); + EXPECT_EQ("message #1", D1.Message.Message); + EXPECT_EQ(55u, D1.Message.FileOffset); + EXPECT_EQ("path/to/source.cpp", D1.Message.FilePath); + std::vector<Replacement> Fixes1 = getFixes(D1.Fix); + ASSERT_EQ(1u, Fixes1.size()); + EXPECT_EQ("path/to/source.cpp", Fixes1[0].getFilePath()); + EXPECT_EQ(100u, Fixes1[0].getOffset()); + EXPECT_EQ(12u, Fixes1[0].getLength()); + EXPECT_EQ("replacement #1", Fixes1[0].getReplacementText()); + + Diagnostic D2 = TUDActual.Diagnostics[1]; + EXPECT_EQ("diagnostic#2", D2.DiagnosticName); + EXPECT_EQ("message #2", D2.Message.Message); + EXPECT_EQ(60u, D2.Message.FileOffset); + EXPECT_EQ("path/to/header.h", D2.Message.FilePath); + std::vector<Replacement> Fixes2 = getFixes(D2.Fix); + ASSERT_EQ(1u, Fixes2.size()); + EXPECT_EQ("path/to/header.h", Fixes2[0].getFilePath()); + EXPECT_EQ(62u, Fixes2[0].getOffset()); + EXPECT_EQ(2u, Fixes2[0].getLength()); + EXPECT_EQ("replacement #2", Fixes2[0].getReplacementText()); + + Diagnostic D3 = TUDActual.Diagnostics[2]; + EXPECT_EQ("diagnostic#3", D3.DiagnosticName); + EXPECT_EQ("message #3", D3.Message.Message); + EXPECT_EQ(98u, D3.Message.FileOffset); + EXPECT_EQ("path/to/source.cpp", D3.Message.FilePath); + std::vector<Replacement> Fixes3 = getFixes(D3.Fix); + EXPECT_TRUE(Fixes3.empty()); +} |
