diff options
Diffstat (limited to 'src/strings/strings_test.cpp')
-rw-r--r-- | src/strings/strings_test.cpp | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/src/strings/strings_test.cpp b/src/strings/strings_test.cpp index dca463d..a95499d 100644 --- a/src/strings/strings_test.cpp +++ b/src/strings/strings_test.cpp @@ -1,4 +1,3 @@ -#include "all.hpp" // strings_test.cpp - Testsuite part 1 for strings. // // Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com> @@ -22,8 +21,13 @@ #include <gtest/gtest.h> +#include "all.hpp" + #include "../poison.hpp" + +namespace tmwa +{ template<typename T> class StringTest : public ::testing::Test { @@ -32,10 +36,10 @@ TYPED_TEST_CASE_P(StringTest); TYPED_TEST_P(StringTest, basic) { - TypeParam hi("Hello"); + TypeParam hi("Hello"_s); EXPECT_EQ(5, hi.size()); EXPECT_EQ(hi, hi); - const char hi2[] = "Hello\0random garbage"; + LString hi2 = "Hello\0random garbage"_s; EXPECT_EQ(hi, hi2); TypeParam hi0; EXPECT_EQ(0, hi0.size()); @@ -47,9 +51,9 @@ TYPED_TEST_P(StringTest, basic) TYPED_TEST_P(StringTest, order) { TypeParam a; - TypeParam b("Hello"); - TypeParam c("Hello,"); - TypeParam d("World!"); + TypeParam b("Hello"_s); + TypeParam c("Hello,"_s); + TypeParam d("World!"_s); // not using EXPECT_LT, etc. for better visibility @@ -158,7 +162,7 @@ TYPED_TEST_P(StringTest, order) TYPED_TEST_P(StringTest, iterators) { - TypeParam hi("Hello"); + TypeParam hi("Hello"_s); EXPECT_EQ(hi.begin(), hi.begin()); EXPECT_NE(hi.begin(), hi.end()); EXPECT_EQ(5, std::distance(hi.begin(), hi.end())); @@ -168,19 +172,19 @@ TYPED_TEST_P(StringTest, iterators) TYPED_TEST_P(StringTest, xslice) { - TypeParam hi("Hello, World!"); - EXPECT_EQ(" World!", hi.xslice_t(6)); - EXPECT_EQ("Hello,", hi.xslice_h(6)); - EXPECT_EQ("World!", hi.xrslice_t(6)); - EXPECT_EQ("Hello, ", hi.xrslice_h(6)); + TypeParam hi("Hello, World!"_s); + EXPECT_EQ(" World!"_s, hi.xslice_t(6)); + EXPECT_EQ("Hello,"_s, hi.xslice_h(6)); + EXPECT_EQ("World!"_s, hi.xrslice_t(6)); + EXPECT_EQ("Hello, "_s, hi.xrslice_h(6)); typename TypeParam::iterator it = std::find(hi.begin(), hi.end(), ' '); - EXPECT_EQ(" World!", hi.xislice_t(it)); - EXPECT_EQ("Hello,", hi.xislice_h(it)); - EXPECT_EQ("World", hi.xlslice(7, 5)); - EXPECT_EQ("World", hi.xpslice(7, 12)); - EXPECT_EQ("World", hi.xislice(hi.begin() + 7, hi.begin() + 12)); - EXPECT_TRUE(hi.startswith("Hello")); - EXPECT_TRUE(hi.endswith("World!")); + EXPECT_EQ(" World!"_s, hi.xislice_t(it)); + EXPECT_EQ("Hello,"_s, hi.xislice_h(it)); + EXPECT_EQ("World"_s, hi.xlslice(7, 5)); + EXPECT_EQ("World"_s, hi.xpslice(7, 12)); + EXPECT_EQ("World"_s, hi.xislice(hi.begin() + 7, hi.begin() + 12)); + EXPECT_TRUE(hi.startswith("Hello"_s)); + EXPECT_TRUE(hi.endswith("World!"_s)); } TYPED_TEST_P(StringTest, convert) @@ -188,15 +192,15 @@ TYPED_TEST_P(StringTest, convert) constexpr bool is_zstring = std::is_same<TypeParam, ZString>::value; typedef typename std::conditional<is_zstring, TString, SString>::type Sstring; typedef typename std::conditional<is_zstring, ZString, XString>::type Xstring; - RString r = "r"; - AString a = "a"; - TString t = "t"; - Sstring s = "s"; - ZString z = "z"; - Xstring x = "x"; - VString<255> v = "v"; - const char l[] = "l"; - VString<5> hi = "hello"; + RString r = "r"_s; + AString a = "a"_s; + TString t = "t"_s; + Sstring s = "s"_s; + ZString z = "z"_s; + Xstring x = "x"_s; + VString<255> v = "v"_s; + LString l = "l"_s; + VString<5> hi = "hello"_s; TypeParam r2 = r; TypeParam a2 = a; @@ -270,7 +274,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(StringStuff, StringTest, MostStringTypes); TEST(VStringTest, basic) { - VString<5> hi = "Hello"; + VString<5> hi = "Hello"_s; EXPECT_EQ(5, hi.size()); EXPECT_EQ(hi, hi); // truncation @@ -278,7 +282,7 @@ TEST(VStringTest, basic) EXPECT_EQ(5, hi2.size()); EXPECT_EQ(hi, hi2); // short - hi = "hi"; + hi = "hi"_s; EXPECT_EQ(2, hi.size()); VString<5> hi0; EXPECT_EQ(0, hi0.size()); @@ -292,7 +296,7 @@ TYPED_TEST_CASE_P(NulStringTest); TYPED_TEST_P(NulStringTest, basic) { - TypeParam hi("hello"); + TypeParam hi("hello"_s); EXPECT_EQ(hi.size(), strlen(hi.c_str())); EXPECT_STREQ("hello", hi.c_str()); } @@ -304,3 +308,4 @@ typedef ::testing::Types< RString, AString, TString, ZString, VString<255> > NulStringTypes; INSTANTIATE_TYPED_TEST_CASE_P(NulStringStuff, NulStringTest, NulStringTypes); +} // namespace tmwa |