summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Basic/SourceManagerTest.cpp
diff options
context:
space:
mode:
authorpaulhoad <mydeveloperday@gmail.com>2019-10-24 20:24:03 +0100
committerpaulhoad <mydeveloperday@gmail.com>2019-10-24 20:24:44 +0100
commit8fa5e98fd191d02fc7e0e220d74af267b9140e6a (patch)
treea59a3d86aa396dc88e3655cdfb96529e988ec300 /clang/unittests/Basic/SourceManagerTest.cpp
parent78700ef8866db7f5cea113fa81d810a28b5b7438 (diff)
downloadbcm5719-llvm-8fa5e98fd191d02fc7e0e220d74af267b9140e6a.tar.gz
bcm5719-llvm-8fa5e98fd191d02fc7e0e220d74af267b9140e6a.zip
[clang-format] Remove duplciate code from Invalid BOM detection
Summary: Review comments on {D68767} asked that this duplicated code in clang-format was moved to one central location that being SourceManager (where it had originally be copied from I assume) Moved function into static function ContentCache::getInvalidBOM(...) - (closest class to where it was defined before) Updated clang-format to call this static function Added unit tests for said new function in BasicTests Sorry not my normal code area so may have the wrong reviewers. (but your names were on the recent history) Reviewers: bruno, arphaman, klimek, owenpan, mitchell-stellar, dexonsmith Reviewed By: owenpan Subscribers: cfe-commits Tags: #clang, #clang-format, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D68914
Diffstat (limited to 'clang/unittests/Basic/SourceManagerTest.cpp')
-rw-r--r--clang/unittests/Basic/SourceManagerTest.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp
index bc7031e1fd2..465f7a06f71 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -200,6 +200,47 @@ TEST_F(SourceManagerTest, locationPrintTest) {
"</mainFile.cpp:1:1, /test-header.h:1:1>");
}
+TEST_F(SourceManagerTest, getInvalidBOM) {
+ ASSERT_EQ(SrcMgr::ContentCache::getInvalidBOM(""), nullptr);
+ ASSERT_EQ(SrcMgr::ContentCache::getInvalidBOM("\x00\x00\x00"), nullptr);
+ ASSERT_EQ(SrcMgr::ContentCache::getInvalidBOM("\xFF\xFF\xFF"), nullptr);
+ ASSERT_EQ(SrcMgr::ContentCache::getInvalidBOM("#include <iostream>"),
+ nullptr);
+
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ "\xFE\xFF#include <iostream>")),
+ "UTF-16 (BE)");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ "\xFF\xFE#include <iostream>")),
+ "UTF-16 (LE)");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ "\x2B\x2F\x76#include <iostream>")),
+ "UTF-7");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ "\xF7\x64\x4C#include <iostream>")),
+ "UTF-1");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ "\xDD\x73\x66\x73#include <iostream>")),
+ "UTF-EBCDIC");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ "\x0E\xFE\xFF#include <iostream>")),
+ "SCSU");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ "\xFB\xEE\x28#include <iostream>")),
+ "BOCU-1");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ "\x84\x31\x95\x33#include <iostream>")),
+ "GB-18030");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ llvm::StringLiteral::withInnerNUL(
+ "\x00\x00\xFE\xFF#include <iostream>"))),
+ "UTF-32 (BE)");
+ ASSERT_EQ(StringRef(SrcMgr::ContentCache::getInvalidBOM(
+ llvm::StringLiteral::withInnerNUL(
+ "\xFF\xFE\x00\x00#include <iostream>"))),
+ "UTF-32 (LE)");
+}
+
#if defined(LLVM_ON_UNIX)
TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
OpenPOWER on IntegriCloud