Skip to content

Commit 6faba8d

Browse files
committed
#158 - Test CppStringT::removesuffix() with char and wchar_t
Completed. Fixed a bug on size of substring.
1 parent e85bfc9 commit 6faba8d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

cpp-strings-tests/cpp-strings-tests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,5 +893,22 @@ namespace cppstringstests
893893
Assert::AreEqual(L"cdab", L"abcdab"cs.removeprefix(L"ab").c_str());
894894
}
895895

896+
897+
TEST_METHOD(removesuffix)
898+
{
899+
pcs::CppString s("abcd");
900+
Assert::AreEqual("ab", s.removesuffix("cd").c_str());
901+
Assert::AreEqual("abcd", s.removesuffix("dc").c_str());
902+
Assert::AreEqual("abcd", s.removesuffix("").c_str());
903+
Assert::AreEqual("abbaba", "abbabaabcd"cs.removesuffix("abcd").c_str());
904+
Assert::AreEqual("abcd", "abcdab"cs.removesuffix("ab").c_str());
905+
906+
pcs::CppWString ws(L"abcd");
907+
Assert::AreEqual(L"ab", ws.removesuffix(L"cd").c_str());
908+
Assert::AreEqual(L"abcd", ws.removesuffix(L"dc").c_str());
909+
Assert::AreEqual(L"abcd", ws.removesuffix(L"").c_str());
910+
Assert::AreEqual(L"abbaba", L"abbabaabcd"cs.removesuffix(L"abcd").c_str());
911+
Assert::AreEqual(L"abcd", L"abcdab"cs.removesuffix(L"ab").c_str());
912+
}
896913
};
897914
}

cpp-strings/cppstrings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ namespace pcs // i.e. "pythonic c++ strings"
11741174
{
11751175
if (this->endswith(suffix)) {
11761176
const size_type suffix_length = suffix.size();
1177-
return this->substr(0, this->size() - suffix_length + 1);
1177+
return this->substr(0, this->size() - suffix_length);
11781178
}
11791179
else
11801180
return *this;

0 commit comments

Comments
 (0)