Mercurial > hg > CbC > CbC_llvm
diff unittests/ADT/StringExtrasTest.cpp @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
line wrap: on
line diff
--- a/unittests/ADT/StringExtrasTest.cpp Sun Dec 23 19:23:36 2018 +0900 +++ b/unittests/ADT/StringExtrasTest.cpp Wed Aug 14 19:46:37 2019 +0900 @@ -1,9 +1,8 @@ //===- StringExtrasTest.cpp - Unit tests for String extras ----------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -13,6 +12,17 @@ using namespace llvm; +TEST(StringExtrasTest, isPrint) { + EXPECT_FALSE(isPrint('\0')); + EXPECT_FALSE(isPrint('\t')); + EXPECT_TRUE(isPrint('0')); + EXPECT_TRUE(isPrint('a')); + EXPECT_TRUE(isPrint('A')); + EXPECT_TRUE(isPrint(' ')); + EXPECT_TRUE(isPrint('~')); + EXPECT_TRUE(isPrint('?')); +} + TEST(StringExtrasTest, Join) { std::vector<std::string> Items; EXPECT_EQ("", join(Items.begin(), Items.end(), " <sep> ")); @@ -59,6 +69,7 @@ OddBytes.size()); EXPECT_EQ(OddStr, toHex(OddData)); EXPECT_EQ(OddData, fromHex(StringRef(OddStr).drop_front())); + EXPECT_EQ(StringRef(OddStr).lower(), toHex(OddData, true)); std::vector<uint8_t> EvenBytes = {0xA5, 0xBD, 0x0D, 0x3E, 0xCD}; std::string EvenStr = "A5BD0D3ECD"; @@ -66,6 +77,7 @@ EvenBytes.size()); EXPECT_EQ(EvenStr, toHex(EvenData)); EXPECT_EQ(EvenData, fromHex(EvenStr)); + EXPECT_EQ(StringRef(EvenStr).lower(), toHex(EvenData, true)); } TEST(StringExtrasTest, to_float) { @@ -92,3 +104,17 @@ printLowerCase("ABCdefg01234.,&!~`'}\"", OS); EXPECT_EQ("abcdefg01234.,&!~`'}\"", OS.str()); } + +TEST(StringExtrasTest, printEscapedString) { + std::string str; + raw_string_ostream OS(str); + printEscapedString("ABCdef123&<>\\\"'\t", OS); + EXPECT_EQ("ABCdef123&<>\\5C\\22'\\09", OS.str()); +} + +TEST(StringExtrasTest, printHTMLEscaped) { + std::string str; + raw_string_ostream OS(str); + printHTMLEscaped("ABCdef123&<>\"'", OS); + EXPECT_EQ("ABCdef123&<>"'", OS.str()); +}