chromium/base/strings/string_util_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/strings/string_util.h"

#include <math.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <string>
#include <string_view>
#include <type_traits>

#include "base/bits.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

ElementsAre;

namespace base {

namespace {

const struct trim_case {} trim_cases[] =;

const struct trim_case_ascii {} trim_cases_ascii[] =;

// Helper used to test TruncateUTF8ToByteSize.
bool Truncated(const std::string& input,
               const size_t byte_size,
               std::string* output) {}

TestFunction;

// Helper used to test IsStringUTF8[AllowingNoncharacters].
void TestStructurallyValidUtf8(TestFunction fn) {}

// Helper used to test IsStringUTF8[AllowingNoncharacters].
void TestStructurallyInvalidUtf8(TestFunction fn) {}

// Helper used to test IsStringUTF8[AllowingNoncharacters].
void TestNoncharacters(TestFunction fn, bool expected_result) {}

TEST(StringUtilTest, TruncateUTF8ToByteSize) {}

#if defined(WCHAR_T_IS_16_BIT)
TEST(StringUtilTest, as_wcstr) {
  char16_t rw_buffer[10] = {};
  static_assert(
      std::is_same_v<wchar_t*, decltype(as_writable_wcstr(rw_buffer))>, "");
  EXPECT_EQ(static_cast<void*>(rw_buffer), as_writable_wcstr(rw_buffer));

  std::u16string rw_str(10, '\0');
  static_assert(std::is_same_v<wchar_t*, decltype(as_writable_wcstr(rw_str))>,
                "");
  EXPECT_EQ(static_cast<const void*>(rw_str.data()), as_writable_wcstr(rw_str));

  const char16_t ro_buffer[10] = {};
  static_assert(std::is_same_v<const wchar_t*, decltype(as_wcstr(ro_buffer))>,
                "");
  EXPECT_EQ(static_cast<const void*>(ro_buffer), as_wcstr(ro_buffer));

  const std::u16string ro_str(10, '\0');
  static_assert(std::is_same_v<const wchar_t*, decltype(as_wcstr(ro_str))>, "");
  EXPECT_EQ(static_cast<const void*>(ro_str.data()), as_wcstr(ro_str));

  std::u16string_view piece = ro_buffer;
  static_assert(std::is_same_v<const wchar_t*, decltype(as_wcstr(piece))>, "");
  EXPECT_EQ(static_cast<const void*>(piece.data()), as_wcstr(piece));
}

TEST(StringUtilTest, as_u16cstr) {
  wchar_t rw_buffer[10] = {};
  static_assert(
      std::is_same_v<char16_t*, decltype(as_writable_u16cstr(rw_buffer))>, "");
  EXPECT_EQ(static_cast<void*>(rw_buffer), as_writable_u16cstr(rw_buffer));

  std::wstring rw_str(10, '\0');
  static_assert(
      std::is_same_v<char16_t*, decltype(as_writable_u16cstr(rw_str))>, "");
  EXPECT_EQ(static_cast<const void*>(rw_str.data()),
            as_writable_u16cstr(rw_str));

  const wchar_t ro_buffer[10] = {};
  static_assert(
      std::is_same_v<const char16_t*, decltype(as_u16cstr(ro_buffer))>, "");
  EXPECT_EQ(static_cast<const void*>(ro_buffer), as_u16cstr(ro_buffer));

  const std::wstring ro_str(10, '\0');
  static_assert(std::is_same_v<const char16_t*, decltype(as_u16cstr(ro_str))>,
                "");
  EXPECT_EQ(static_cast<const void*>(ro_str.data()), as_u16cstr(ro_str));

  std::wstring_view piece = ro_buffer;
  static_assert(std::is_same_v<const char16_t*, decltype(as_u16cstr(piece))>,
                "");
  EXPECT_EQ(static_cast<const void*>(piece.data()), as_u16cstr(piece));
}
#endif  // defined(WCHAR_T_IS_16_BIT)

TEST(StringUtilTest, TrimWhitespace) {}

static const struct collapse_case {} collapse_cases[] =;

TEST(StringUtilTest, CollapseWhitespace) {}

static const struct collapse_case_ascii {} collapse_cases_ascii[] =;

TEST(StringUtilTest, CollapseWhitespaceASCII) {}

TEST(StringUtilTest, IsStringUTF8) {}

TEST(StringUtilTest, IsStringASCII) {}

TEST(StringUtilTest, ConvertASCII) {}

TEST(StringUtilTest, ToLowerASCII) {}

TEST(StringUtilTest, ToUpperASCII) {}

TEST(StringUtilTest, FormatBytesUnlocalized) {}
TEST(StringUtilTest, ReplaceSubstringsAfterOffset) {}

TEST(StringUtilTest, ReplaceFirstSubstringAfterOffset) {}

TEST(StringUtilTest, HexDigitToInt) {}

TEST(StringUtilTest, JoinString) {}

TEST(StringUtilTest, JoinString16) {}

TEST(StringUtilTest, JoinStringPiece) {}

TEST(StringUtilTest, JoinStringPiece16) {}

TEST(StringUtilTest, JoinStringInitializerList) {}

TEST(StringUtilTest, JoinStringInitializerList16) {}

TEST(StringUtilTest, StartsWith) {}

TEST(StringUtilTest, EndsWith) {}

TEST(StringUtilTest, GetStringFWithOffsets) {}

TEST(StringUtilTest, ReplaceStringPlaceholdersTooFew) {}

TEST(StringUtilTest, ReplaceStringPlaceholders) {}

TEST(StringUtilTest, ReplaceStringPlaceholdersNetExpansionWithContraction) {}

TEST(StringUtilTest, ReplaceStringPlaceholdersNetContractionWithExpansion) {}

TEST(StringUtilTest, ReplaceStringPlaceholdersOneDigit) {}

TEST(StringUtilTest, ReplaceStringPlaceholdersInvalidPlaceholder) {}

TEST(StringUtilTest, StdStringReplaceStringPlaceholders) {}

TEST(StringUtilTest, StdStringReplaceStringPlaceholdersMultipleMatches) {}

TEST(StringUtilTest, ReplaceStringPlaceholdersConsecutiveDollarSigns) {}

TEST(StringUtilTest, LcpyTest) {}

TEST(StringUtilTest, WprintfFormatPortabilityTest) {}

TEST(StringUtilTest, MakeBasicStringPieceTest) {}

TEST(StringUtilTest, RemoveChars) {}

TEST(StringUtilTest, ReplaceChars) {}

TEST(StringUtilTest, ContainsOnlyChars) {}

TEST(StringUtilTest, CompareCaseInsensitiveASCII) {}

TEST(StringUtilTest, EqualsCaseInsensitiveASCII) {}

TEST(StringUtilTest, IsUnicodeWhitespace) {}

// Tests that MakeStringViewWithNulChars preserves internal NUL characters.
TEST(StringUtilTest, MakeStringViewWithNulChars) {}

class WriteIntoTest : public testing::Test {};

TEST_F(WriteIntoTest, WriteInto) {}

}  // namespace

}  // namespace base