Skip to content

Instantly share code, notes, and snippets.

@getjump
Created March 23, 2015 06:53
Show Gist options
  • Save getjump/0b958c2009c7eb0c6cee to your computer and use it in GitHub Desktop.
Save getjump/0b958c2009c7eb0c6cee to your computer and use it in GitHub Desktop.
#include "..\String.h"
#include <gtest\gtest.h>
TEST(StringTest, InsertTest)
{
String s("Far Eastern");
s.insert(4, "1337 ");
EXPECT_EQ(s, "Far 1337 Eastern");
}
TEST(StringTest, StringRemove)
{
String s("1122removeme1122");
s.remove(4, 8);
EXPECT_EQ(s, "11221122");
}
TEST(StringTest, StringArraySet)
{
String s("djamalungma");
s[0] = '2';
EXPECT_EQ(s[0], '2');
}
TEST(StringTest, StringCharConcatenation)
{
String s("kilimanjaro");
char* p = "1";
s += p;
EXPECT_EQ(s, "kilimanjaro1");
}
TEST(StringTest, EmptyString)
{
String empty;
EXPECT_TRUE(!empty);
}
TEST(StringTest, Comparision)
{
String s1("228");
String s2("228");
EXPECT_TRUE(s1 == s2);
EXPECT_TRUE(s1 >= s2);
EXPECT_FALSE(s1 < s2);
EXPECT_FALSE(s1 > s2);
}
TEST(StringTest, ReferenceCounter)
{
String s1("228");
String s2 = s1;
EXPECT_EQ(s2.rc(), s1.rc());
EXPECT_EQ(s1.rc(), 2);
String s3 = s2;
EXPECT_EQ(s3.rc(), 3);
s1 = "1337";
EXPECT_EQ(s1.rc(), 1);
EXPECT_EQ(s2.rc(), 2);
}
TEST(StringTest, Length)
{
String s("ololololololo");
EXPECT_EQ(s.length(), 13);
}
TEST(StringTest, Substr)
{
String s("oloshka");
EXPECT_EQ((String)s(0, 3), "olo");
}
TEST(StringTest, SubstrAssignMore)
{
String s("oloshka");
s(0, 3) = "228228";
EXPECT_EQ((String)s(0, 6), "228228");
EXPECT_EQ(s, "228228shka");
}
TEST(StringTest, SubstrAssignLess)
{
String s("oloshka");
s(0, 3) = "2";
EXPECT_EQ((String)s(0, 3), "2sh");
EXPECT_EQ(s, "2shka");
}
TEST(StringTest, SubstrAssign)
{
String s("oloshka");
s(0, 3) = "228";
EXPECT_EQ((String)s(0, 3), "228");
EXPECT_EQ(s, "228shka");
}
TEST(StringTest, ArrayAccess)
{
String s("dada");
EXPECT_EQ(s[0], 'd');
EXPECT_EQ(s[1], 'a');
}
TEST(StringTest, Concatenate)
{
String s("dada");
String s2("netnet");
EXPECT_EQ(s + s2, "dadanetnet");
s2 += s;
EXPECT_EQ(s2, "netnetdada");
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment