aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/Support/LocaleTest.cpp
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2013-08-07 15:07:10 -0700
committerStephen Hines <srhines@google.com>2013-08-07 15:07:10 -0700
commitfab2daa4a1127ecb217abe2b07c1769122b6fee1 (patch)
tree268ebfd1963fd98ba412e76819afdf95a7d4267b /unittests/Support/LocaleTest.cpp
parent8197ac1c1a0a91baa70c4dea8cb488f254ef974c (diff)
parent10251753b6897adcd22cc981c0cc42f348c109de (diff)
downloadexternal_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.zip
external_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.tar.gz
external_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.tar.bz2
Merge commit '10251753b6897adcd22cc981c0cc42f348c109de' into merge-20130807
Conflicts: lib/Archive/ArchiveReader.cpp lib/Support/Unix/PathV2.inc Change-Id: I29d8c1e321a4a380b6013f00bac6a8e4b593cc4e
Diffstat (limited to 'unittests/Support/LocaleTest.cpp')
-rw-r--r--unittests/Support/LocaleTest.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/unittests/Support/LocaleTest.cpp b/unittests/Support/LocaleTest.cpp
new file mode 100644
index 0000000..3524b4b
--- /dev/null
+++ b/unittests/Support/LocaleTest.cpp
@@ -0,0 +1,100 @@
+//===- 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
+
+ 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_EQ(false, isPrint(0)); // <control-0000>-<control-001F>
+ EXPECT_EQ(false, isPrint(0x01));
+ EXPECT_EQ(false, isPrint(0x1F));
+ EXPECT_EQ(true, isPrint(' '));
+ EXPECT_EQ(true, isPrint('A'));
+ EXPECT_EQ(true, isPrint('~'));
+ EXPECT_EQ(false, isPrint(0x7F)); // <control-007F>..<control-009F>
+ EXPECT_EQ(false, isPrint(0x90));
+ EXPECT_EQ(false, isPrint(0x9F));
+
+ EXPECT_EQ(true, isPrint(0xAC));
+ // FIXME: Figure out if we want to treat SOFT HYPHEN as printable character.
+#ifndef __APPLE__
+ EXPECT_EQ(false, isPrint(0xAD)); // SOFT HYPHEN
+#endif // __APPLE__
+ EXPECT_EQ(true, isPrint(0xAE));
+
+ // MacOS implementation doesn't think it's printable.
+#ifndef __APPLE__
+ EXPECT_EQ(true, isPrint(0x0377)); // GREEK SMALL LETTER PAMPHYLIAN DIGAMMA
+#endif // __APPLE__
+ EXPECT_EQ(false, isPrint(0x0378)); // <reserved-0378>..<reserved-0379>
+
+ EXPECT_EQ(false, isPrint(0x0600)); // ARABIC NUMBER SIGN
+
+ EXPECT_EQ(false, isPrint(0x1FFFF)); // <reserved-1F774>..<noncharacter-1FFFF>
+ EXPECT_EQ(true, isPrint(0x20000)); // CJK UNIFIED IDEOGRAPH-20000
+
+ EXPECT_EQ(false, isPrint(0x10FFFF)); // noncharacter
+}
+
+#endif // _WIN32
+
+} // namespace
+} // namespace locale
+} // namespace sys
+} // namespace llvm