summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-03-24 13:22:42 +0000
committerEric Liu <ioeric@google.com>2016-03-24 13:22:42 +0000
commit547d87912a71728fcee4a46b3a803827c3acc847 (patch)
treec18b0fff74cbb29106b37238feb85f52ca093644 /clang/unittests/Format/FormatTest.cpp
parentd47583232a906564e1a6ec84bd14569380ef4e74 (diff)
downloadbcm5719-llvm-547d87912a71728fcee4a46b3a803827c3acc847.tar.gz
bcm5719-llvm-547d87912a71728fcee4a46b3a803827c3acc847.zip
Added support for different VFSs in format::getStyle. Disable platform-related test case for MS compilers to avoid breaking buildbot.
llvm-svn: 264277
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d2ec4e645c9..7aa17e7be62 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14,6 +14,7 @@
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "gtest/gtest.h"
#define DEBUG_TYPE "format-test"
@@ -11199,6 +11200,39 @@ TEST_F(FormatTest, FormatsTableGenCode) {
verifyFormat("include \"a.td\"\ninclude \"b.td\"", Style);
}
+// Since this test case uses UNIX-style file path. We disable it for MS
+// compiler.
+#if !defined(_MSC_VER)
+
+TEST(FormatStyle, GetStyleOfFile) {
+ vfs::InMemoryFileSystem FS;
+ // Test 1: format file in the same directory.
+ ASSERT_TRUE(
+ FS.addFile("/a/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: LLVM")));
+ ASSERT_TRUE(
+ FS.addFile("/a/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;")));
+ auto Style1 = getStyle("file", "/a/.clang-format", "Google", &FS);
+ ASSERT_EQ(Style1, getLLVMStyle());
+
+ // Test 2: fallback to default.
+ ASSERT_TRUE(
+ FS.addFile("/b/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;")));
+ auto Style2 = getStyle("file", "/b/test.cpp", "Mozilla", &FS);
+ ASSERT_EQ(Style2, getMozillaStyle());
+
+ // Test 3: format file in parent directory.
+ ASSERT_TRUE(
+ FS.addFile("/c/.clang-format", 0,
+ llvm::MemoryBuffer::getMemBuffer("BasedOnStyle: Google")));
+ ASSERT_TRUE(FS.addFile("/c/sub/sub/sub/test.cpp", 0,
+ llvm::MemoryBuffer::getMemBuffer("int i;")));
+ auto Style3 = getStyle("file", "/c/sub/sub/sub/test.cpp", "LLVM", &FS);
+ ASSERT_EQ(Style3, getGoogleStyle());
+}
+
+#endif // _MSC_VER
+
class ReplacementTest : public ::testing::Test {
protected:
tooling::Replacement createReplacement(SourceLocation Start, unsigned Length,
OpenPOWER on IntegriCloud