summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-09-04 16:00:12 +0000
committerAlexander Kornienko <alexfh@google.com>2013-09-04 16:00:12 +0000
commit280e5eef43ecf2279ab78f132922920ed7ce7952 (patch)
tree1bb943229dfe4665f53171bc73b7a6898d24f338 /unittests
parent9127334dade7fa36cb5cb999fc116ceaa4f52ac9 (diff)
downloadllvm-280e5eef43ecf2279ab78f132922920ed7ce7952.tar.gz
llvm-280e5eef43ecf2279ab78f132922920ed7ce7952.tar.bz2
llvm-280e5eef43ecf2279ab78f132922920ed7ce7952.tar.xz
Move generic isPrint and columnWidth implementations to a separate header/source to allow using both generic and system-dependent versions on win32.
Summary: This is needed so we can use generic columnWidthUTF8 in clang-format on win32 simultaneously with a separate system-dependent implementations of isPrint/columnWidth in TextDiagnostic.cpp to avoid attempts to print Unicode characters using narrow-character interfaces (which is not supported on Windows, and we'll have to figure out how to handle this). Reviewers: jordan_rose Reviewed By: jordan_rose CC: llvm-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1559 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189952 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Support/CMakeLists.txt2
-rw-r--r--unittests/Support/LocaleTest.cpp104
-rw-r--r--unittests/Support/UnicodeTest.cpp93
3 files changed, 94 insertions, 105 deletions
diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt
index 197561ebaa..5f5d9f6ccf 100644
--- a/unittests/Support/CMakeLists.txt
+++ b/unittests/Support/CMakeLists.txt
@@ -19,7 +19,6 @@ add_llvm_unittest(SupportTests
FileOutputBufferTest.cpp
IntegersSubsetTest.cpp
LeakDetectorTest.cpp
- LocaleTest.cpp
LockFileManagerTest.cpp
ManagedStatic.cpp
MathExtrasTest.cpp
@@ -32,6 +31,7 @@ add_llvm_unittest(SupportTests
RegexTest.cpp
SwapByteOrderTest.cpp
TimeValueTest.cpp
+ UnicodeTest.cpp
ValueHandleTest.cpp
YAMLIOTest.cpp
YAMLParserTest.cpp
diff --git a/unittests/Support/LocaleTest.cpp b/unittests/Support/LocaleTest.cpp
deleted file mode 100644
index 81d31b9f61..0000000000
--- a/unittests/Support/LocaleTest.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-//===- unittests/Support/LocaleTest.cpp - Locale.h tests ------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/Locale.h"
-#include "gtest/gtest.h"
-
-namespace llvm {
-namespace sys {
-namespace locale {
-namespace {
-
-// FIXME: WIN32 implementation is incorrect. We should consider using the one
-// from LocaleGeneric.inc for WIN32.
-#ifndef _WIN32
-TEST(Locale, columnWidth) {
- // FIXME: This test fails with MacOSX implementation of columnWidth.
-#ifndef __APPLE__
- EXPECT_EQ(0, columnWidth(""));
- EXPECT_EQ(1, columnWidth(" "));
- EXPECT_EQ(1, columnWidth("a"));
- EXPECT_EQ(1, columnWidth("~"));
-
- EXPECT_EQ(6, columnWidth("abcdef"));
-
- EXPECT_EQ(-1, columnWidth("\x01"));
- EXPECT_EQ(-1, columnWidth("aaaaaaaaaa\x01"));
- EXPECT_EQ(-1, columnWidth("\342\200\213")); // 200B ZERO WIDTH SPACE
-
- // 00AD SOFT HYPHEN is displayed on most terminals as a space or a dash. Some
- // text editors display it only when a line is broken at it, some use it as a
- // line-break hint, but don't display. We choose terminal-oriented
- // interpretation.
- EXPECT_EQ(1, columnWidth("\302\255"));
-
- EXPECT_EQ(0, columnWidth("\314\200")); // 0300 COMBINING GRAVE ACCENT
- EXPECT_EQ(1, columnWidth("\340\270\201")); // 0E01 THAI CHARACTER KO KAI
- EXPECT_EQ(2, columnWidth("\344\270\200")); // CJK UNIFIED IDEOGRAPH-4E00
-
- EXPECT_EQ(4, columnWidth("\344\270\200\344\270\200"));
- EXPECT_EQ(3, columnWidth("q\344\270\200"));
- EXPECT_EQ(3, columnWidth("\314\200\340\270\201\344\270\200"));
-
- // Invalid UTF-8 strings, columnWidth should error out.
- EXPECT_EQ(-2, columnWidth("\344"));
- EXPECT_EQ(-2, columnWidth("\344\270"));
- EXPECT_EQ(-2, columnWidth("\344\270\033"));
- EXPECT_EQ(-2, columnWidth("\344\270\300"));
- EXPECT_EQ(-2, columnWidth("\377\366\355"));
-
- EXPECT_EQ(-2, columnWidth("qwer\344"));
- EXPECT_EQ(-2, columnWidth("qwer\344\270"));
- EXPECT_EQ(-2, columnWidth("qwer\344\270\033"));
- EXPECT_EQ(-2, columnWidth("qwer\344\270\300"));
- EXPECT_EQ(-2, columnWidth("qwer\377\366\355"));
-
- // UTF-8 sequences longer than 4 bytes correspond to unallocated Unicode
- // characters.
- EXPECT_EQ(-2, columnWidth("\370\200\200\200\200")); // U+200000
- EXPECT_EQ(-2, columnWidth("\374\200\200\200\200\200")); // U+4000000
-#endif // __APPLE__
-}
-
-TEST(Locale, isPrint) {
- EXPECT_FALSE(isPrint(0)); // <control-0000>-<control-001F>
- EXPECT_FALSE(isPrint(0x01));
- EXPECT_FALSE(isPrint(0x1F));
- EXPECT_TRUE(isPrint(' '));
- EXPECT_TRUE(isPrint('A'));
- EXPECT_TRUE(isPrint('~'));
- EXPECT_FALSE(isPrint(0x7F)); // <control-007F>..<control-009F>
- EXPECT_FALSE(isPrint(0x90));
- EXPECT_FALSE(isPrint(0x9F));
-
- EXPECT_TRUE(isPrint(0xAC));
- EXPECT_TRUE(isPrint(0xAD)); // SOFT HYPHEN is displayed on most terminals
- // as either a space or a dash.
- EXPECT_TRUE(isPrint(0xAE));
-
- // MacOS implementation doesn't think it's printable.
-#ifndef __APPLE__
- EXPECT_TRUE(isPrint(0x0377)); // GREEK SMALL LETTER PAMPHYLIAN DIGAMMA
-#endif // __APPLE__
- EXPECT_FALSE(isPrint(0x0378)); // <reserved-0378>..<reserved-0379>
-
- EXPECT_FALSE(isPrint(0x0600)); // ARABIC NUMBER SIGN
-
- EXPECT_FALSE(isPrint(0x1FFFF)); // <reserved-1F774>..<noncharacter-1FFFF>
- EXPECT_TRUE(isPrint(0x20000)); // CJK UNIFIED IDEOGRAPH-20000
-
- EXPECT_FALSE(isPrint(0x10FFFF)); // noncharacter
-}
-
-#endif // _WIN32
-
-} // namespace
-} // namespace locale
-} // namespace sys
-} // namespace llvm
diff --git a/unittests/Support/UnicodeTest.cpp b/unittests/Support/UnicodeTest.cpp
new file mode 100644
index 0000000000..0733397d45
--- /dev/null
+++ b/unittests/Support/UnicodeTest.cpp
@@ -0,0 +1,93 @@
+//===- unittests/Support/UnicodeTest.cpp - Unicode.h tests ----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Unicode.h"
+#include "gtest/gtest.h"
+
+namespace llvm {
+namespace sys {
+namespace unicode {
+namespace {
+
+TEST(Unicode, columnWidthUTF8) {
+ EXPECT_EQ(0, columnWidthUTF8(""));
+ EXPECT_EQ(1, columnWidthUTF8(" "));
+ EXPECT_EQ(1, columnWidthUTF8("a"));
+ EXPECT_EQ(1, columnWidthUTF8("~"));
+
+ EXPECT_EQ(6, columnWidthUTF8("abcdef"));
+
+ EXPECT_EQ(-1, columnWidthUTF8("\x01"));
+ EXPECT_EQ(-1, columnWidthUTF8("aaaaaaaaaa\x01"));
+ EXPECT_EQ(-1, columnWidthUTF8("\342\200\213")); // 200B ZERO WIDTH SPACE
+
+ // 00AD SOFT HYPHEN is displayed on most terminals as a space or a dash. Some
+ // text editors display it only when a line is broken at it, some use it as a
+ // line-break hint, but don't display. We choose terminal-oriented
+ // interpretation.
+ EXPECT_EQ(1, columnWidthUTF8("\302\255"));
+
+ EXPECT_EQ(0, columnWidthUTF8("\314\200")); // 0300 COMBINING GRAVE ACCENT
+ EXPECT_EQ(1, columnWidthUTF8("\340\270\201")); // 0E01 THAI CHARACTER KO KAI
+ EXPECT_EQ(2, columnWidthUTF8("\344\270\200")); // CJK UNIFIED IDEOGRAPH-4E00
+
+ EXPECT_EQ(4, columnWidthUTF8("\344\270\200\344\270\200"));
+ EXPECT_EQ(3, columnWidthUTF8("q\344\270\200"));
+ EXPECT_EQ(3, columnWidthUTF8("\314\200\340\270\201\344\270\200"));
+
+ // Invalid UTF-8 strings, columnWidthUTF8 should error out.
+ EXPECT_EQ(-2, columnWidthUTF8("\344"));
+ EXPECT_EQ(-2, columnWidthUTF8("\344\270"));
+ EXPECT_EQ(-2, columnWidthUTF8("\344\270\033"));
+ EXPECT_EQ(-2, columnWidthUTF8("\344\270\300"));
+ EXPECT_EQ(-2, columnWidthUTF8("\377\366\355"));
+
+ EXPECT_EQ(-2, columnWidthUTF8("qwer\344"));
+ EXPECT_EQ(-2, columnWidthUTF8("qwer\344\270"));
+ EXPECT_EQ(-2, columnWidthUTF8("qwer\344\270\033"));
+ EXPECT_EQ(-2, columnWidthUTF8("qwer\344\270\300"));
+ EXPECT_EQ(-2, columnWidthUTF8("qwer\377\366\355"));
+
+ // UTF-8 sequences longer than 4 bytes correspond to unallocated Unicode
+ // characters.
+ EXPECT_EQ(-2, columnWidthUTF8("\370\200\200\200\200")); // U+200000
+ EXPECT_EQ(-2, columnWidthUTF8("\374\200\200\200\200\200")); // U+4000000
+}
+
+TEST(Unicode, isPrintable) {
+ EXPECT_FALSE(isPrintable(0)); // <control-0000>-<control-001F>
+ EXPECT_FALSE(isPrintable(0x01));
+ EXPECT_FALSE(isPrintable(0x1F));
+ EXPECT_TRUE(isPrintable(' '));
+ EXPECT_TRUE(isPrintable('A'));
+ EXPECT_TRUE(isPrintable('~'));
+ EXPECT_FALSE(isPrintable(0x7F)); // <control-007F>..<control-009F>
+ EXPECT_FALSE(isPrintable(0x90));
+ EXPECT_FALSE(isPrintable(0x9F));
+
+ EXPECT_TRUE(isPrintable(0xAC));
+ EXPECT_TRUE(isPrintable(0xAD)); // SOFT HYPHEN is displayed on most terminals
+ // as either a space or a dash.
+ EXPECT_TRUE(isPrintable(0xAE));
+
+ EXPECT_TRUE(isPrintable(0x0377)); // GREEK SMALL LETTER PAMPHYLIAN DIGAMMA
+ EXPECT_FALSE(isPrintable(0x0378)); // <reserved-0378>..<reserved-0379>
+
+ EXPECT_FALSE(isPrintable(0x0600)); // ARABIC NUMBER SIGN
+
+ EXPECT_FALSE(isPrintable(0x1FFFF)); // <reserved-1F774>..<noncharacter-1FFFF>
+ EXPECT_TRUE(isPrintable(0x20000)); // CJK UNIFIED IDEOGRAPH-20000
+
+ EXPECT_FALSE(isPrintable(0x10FFFF)); // noncharacter
+}
+
+} // namespace
+} // namespace unicode
+} // namespace sys
+} // namespace llvm