| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 #include <gtest/gtest.h> | 17 #include <gtest/gtest.h> |
| 18 #include "../src/shared/Utils.h" | 18 #include "../src/shared/Utils.h" |
| 19 | 19 |
| 20 namespace | 20 namespace |
| 21 { | 21 { |
| 22 void TrimTestBody(std::wstring input, std::wstring expected) | 22 void TrimTestBody(const std::wstring& input, const std::wstring& expected) |
|
sergei
2015/11/30 12:37:54
It's not introduces in this change set but the com
Eric
2015/11/30 15:54:07
Done.
| |
| 23 { | 23 { |
| 24 std::wstring trimmed = TrimString(input); | 24 std::wstring trimmed = TrimString(input); |
| 25 ASSERT_EQ(expected, trimmed); | 25 EXPECT_EQ(expected, trimmed); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void TrimLeftTestBody(std::wstring input, std::wstring expected) | 28 void TrimLeftTestBody(const std::wstring& input, const std::wstring& expected) |
|
sergei
2015/11/30 12:37:54
Why not to pass arguments as constant references?
sergei
2015/11/30 12:37:54
It would be better to call it like
ExpectEqualToLe
Eric
2015/11/30 15:54:07
I'm not going to bother with the renaming. I don't
Eric
2015/11/30 15:54:08
Done.
| |
| 29 { | 29 { |
| 30 std::wstring trimmed = TrimStringLeft(input); | 30 std::wstring trimmed = TrimStringLeft(input); |
| 31 ASSERT_EQ(expected, trimmed); | 31 EXPECT_EQ(expected, trimmed); |
|
sergei
2015/11/30 12:37:54
It should not stop the tests, could you please use
Eric
2015/11/30 15:54:07
Done.
| |
| 32 } | 32 } |
| 33 | 33 |
| 34 void TrimRightTestBody(std::wstring input, std::wstring expected) | 34 void TrimRightTestBody(const std::wstring& input, const std::wstring& expected ) |
|
sergei
2015/11/30 12:37:54
ExpectEqualToRightTrimmed(expected, input);
sergei
2015/11/30 12:37:54
Same here, constant references
Eric
2015/11/30 15:54:07
Done.
| |
| 35 { | 35 { |
| 36 std::wstring trimmed = TrimStringRight(input); | 36 std::wstring trimmed = TrimStringRight(input); |
| 37 ASSERT_EQ(expected, trimmed); | 37 EXPECT_EQ(expected, trimmed); |
|
sergei
2015/11/30 12:37:55
EXPECT_EQ
Eric
2015/11/30 15:54:07
Done.
| |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 TEST(TrimTest, Trim00) | 41 TEST(TrimTest, Trim00) |
| 42 { | 42 { |
| 43 const std::wstring x = L""; | 43 const std::wstring x = L""; |
| 44 TrimTestBody(x, L""); | 44 TrimTestBody(x, L""); |
| 45 TrimLeftTestBody(x, L""); | 45 TrimLeftTestBody(x, L""); |
| 46 TrimRightTestBody(x, L""); | 46 TrimRightTestBody(x, L""); |
| 47 } | 47 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST(TrimTest, Trim14) | 153 TEST(TrimTest, Trim14) |
| 154 { | 154 { |
| 155 const std::wstring x = L" foo bar \r\n"; | 155 const std::wstring x = L" foo bar \r\n"; |
| 156 TrimTestBody(x, L"foo bar"); | 156 TrimTestBody(x, L"foo bar"); |
| 157 TrimLeftTestBody(x, L"foo bar \r\n"); | 157 TrimLeftTestBody(x, L"foo bar \r\n"); |
| 158 TrimRightTestBody(x, L" foo bar"); | 158 TrimRightTestBody(x, L" foo bar"); |
| 159 } | 159 } |
| 160 | 160 |
| 161 /* | |
| 162 * First of two tests verifying that TrimString() does not alter its argument. | |
| 163 * This one tests an ordinary, non-const variable as an argument. | |
| 164 * It differs from its companion only in the one line that declares the variable used as an argument. | |
| 165 */ | |
| 161 TEST(TrimTest, TrimPassesByValue) | 166 TEST(TrimTest, TrimPassesByValue) |
| 162 { | 167 { |
| 163 std::wstring x = L"foo bar "; // not declared 'const', coould alter | 168 std::wstring x = L"foo bar "; // not declared 'const', could alter |
| 164 const std::wstring y = x; | 169 const std::wstring y = x; |
| 165 ASSERT_EQ(y, x); | 170 ASSERT_EQ(y, x); |
|
sergei
2015/11/30 12:37:54
EXPECT_EQ here and below
Eric
2015/11/30 15:54:08
This statement is largely documentation. It's here
| |
| 166 std::wstring trimmed = TrimString(x); // expect here pass by value | 171 std::wstring trimmed = TrimString(x); // expect here pass by value |
|
sergei
2015/11/30 12:37:54
What if one calls it as `TrimString<std::wstring&>
Eric
2015/11/30 15:54:08
If you do that, you get in-place modification. I s
sergei
2015/11/30 16:36:03
Acknowledged. It's another issue, let's leave it.
| |
| 167 ASSERT_EQ(L"foo bar", trimmed); | 172 EXPECT_EQ(L"foo bar", trimmed); |
| 168 ASSERT_EQ(y, x); // argument variable not altered | 173 ASSERT_EQ(y, x); // argument variable not altered |
| 169 } | 174 } |
| 170 | 175 |
| 176 /* | |
| 177 * Second of two tests verifying that TrimString() does not alter its argument. | |
| 178 * This one tests a const variable as an argument. | |
| 179 */ | |
| 171 TEST(TrimTest, TrimBindsOnConstArg) | 180 TEST(TrimTest, TrimBindsOnConstArg) |
|
sergei
2015/11/30 12:37:55
If it's an attempt to test whether there is some b
Eric
2015/11/30 15:54:07
It verifies the modification, yes. The real purpos
| |
| 172 { | 181 { |
| 173 const std::wstring x = L"foo bar "; // declared 'const' | 182 const std::wstring x = L"foo bar "; // declared 'const' |
| 174 const std::wstring y = x; | 183 const std::wstring y = x; |
| 175 ASSERT_EQ(y, x); | 184 ASSERT_EQ(y, x); |
| 176 std::wstring trimmed = TrimString(x); | 185 std::wstring trimmed = TrimString(x); |
| 177 ASSERT_EQ(L"foo bar", trimmed); | 186 EXPECT_EQ(L"foo bar", trimmed); |
| 178 ASSERT_EQ(y, x); | 187 ASSERT_EQ(y, x); |
| 179 } | 188 } |
| LEFT | RIGHT |