summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Common/StringUtilTest.cpp
blob: 0a45c3b26a5d48518e47fa8ac693dd26961f36e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <gtest/gtest.h>
#include <string>
#include <vector>

#include "Common/StringUtil.h"

TEST(StringUtil, JoinStrings)
{
  EXPECT_EQ("", JoinStrings({}, ", "));
  EXPECT_EQ("a", JoinStrings({"a"}, ","));
  EXPECT_EQ("ab", JoinStrings({"a", "b"}, ""));
  EXPECT_EQ("a, bb, c", JoinStrings({"a", "bb", "c"}, ", "));
  EXPECT_EQ("???", JoinStrings({"?", "?"}, "?"));
}

TEST(StringUtil, StringBeginsWith)
{
  EXPECT_EQ(true, StringBeginsWith("abc", "a"));
  EXPECT_EQ(false, StringBeginsWith("abc", "b"));
  EXPECT_EQ(true, StringBeginsWith("abc", "ab"));
  EXPECT_EQ(false, StringBeginsWith("a", "ab"));
  EXPECT_EQ(false, StringBeginsWith("", "a"));
  EXPECT_EQ(false, StringBeginsWith("", "ab"));
  EXPECT_EQ(true, StringBeginsWith("abc", ""));
  EXPECT_EQ(true, StringBeginsWith("", ""));
}

TEST(StringUtil, StringEndsWith)
{
  EXPECT_EQ(true, StringEndsWith("abc", "c"));
  EXPECT_EQ(false, StringEndsWith("abc", "b"));
  EXPECT_EQ(true, StringEndsWith("abc", "bc"));
  EXPECT_EQ(false, StringEndsWith("a", "ab"));
  EXPECT_EQ(false, StringEndsWith("", "a"));
  EXPECT_EQ(false, StringEndsWith("", "ab"));
  EXPECT_EQ(true, StringEndsWith("abc", ""));
  EXPECT_EQ(true, StringEndsWith("", ""));
}