From da378efaaa549116c9e4c80dc9bbd2b9b9e3a4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Wed, 2 Nov 2016 10:59:41 +0100 Subject: [PATCH] written some tests based on a non-working feature (operator[] = operator[]) --- manualtest.cpp | 5 +++++ test.cpp | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/manualtest.cpp b/manualtest.cpp index ab5537e..e26a762 100644 --- a/manualtest.cpp +++ b/manualtest.cpp @@ -86,6 +86,11 @@ int main() if (str[1] == 'i') std::cout << "String::operator[] works" << std::endl; + String sajtok = "sajtok"; + sajtok[5] = sajtok[0]; + if (!std::strcmp(sajtok.c_str(), "sajtos")) + std::cout << "String::operator[]'s operator= works with other String::operator[]s" << std::endl; + try { str[8]; } catch (std::out_of_range) { std::cout << "String::operator[] throws when index is out of range" << std::endl; } diff --git a/test.cpp b/test.cpp index bc79be5..24c9a7b 100644 --- a/test.cpp +++ b/test.cpp @@ -173,7 +173,15 @@ TEST(StringTest, indexOperatorWorks) EXPECT_EQ(i, str[1]); } -TEST(StringTest, indexoperatorBoundCheckWorks) +TEST(StringTest, indexOperatorWorksWhenUsedWithOtherIndexOperators) +{ + String sajtok = "sajtok"; + sajtok[5] = sajtok[0]; + + EXPECT_STREQ("sajtos", sajtok.c_str()); +} + +TEST(StringTest, indexOperatorBoundCheckWorks) { String str("sajt");