You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/testutils.cpp
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -223,19 +223,43 @@ class TestUtils : public TestFixture {
223
223
224
224
voidstrToInt() {
225
225
ASSERT_EQUALS(1, ::strToInt<int>("1"));
226
+
ASSERT_EQUALS(1, ::strToInt<int>("+1"));
226
227
ASSERT_EQUALS(-1, ::strToInt<int>("-1"));
227
228
ASSERT_EQUALS(1, ::strToInt<std::size_t>("1"));
229
+
ASSERT_EQUALS(1, ::strToInt<std::size_t>("+1"));
230
+
ASSERT_EQUALS(0, ::strToInt<int>("0"));
231
+
ASSERT_EQUALS(0, ::strToInt<int>("+0"));
232
+
ASSERT_EQUALS(0, ::strToInt<int>("-0"));
233
+
ASSERT_EQUALS(0, ::strToInt<std::size_t>("0"));
234
+
ASSERT_EQUALS(0, ::strToInt<std::size_t>("+0"));
228
235
ASSERT_THROW_EQUALS(::strToInt<int>(""), std::runtime_error, "converting '' to integer failed - not an integer");
229
236
ASSERT_THROW_EQUALS(::strToInt<std::size_t>(""), std::runtime_error, "converting '' to integer failed - not an integer");
230
237
ASSERT_THROW_EQUALS(::strToInt<int>(""), std::runtime_error, "converting ' ' to integer failed - not an integer");
231
238
ASSERT_THROW_EQUALS(::strToInt<std::size_t>(""), std::runtime_error, "converting ' ' to integer failed - not an integer");
232
239
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("-1"), std::runtime_error, "converting '-1' to integer failed - needs to be positive");
240
+
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("-0"), std::runtime_error, "converting '-0' to integer failed - needs to be positive");
241
+
ASSERT_THROW_EQUALS(::strToInt<std::size_t>("-1"), std::runtime_error, "converting '-1' to integer failed - needs to be positive");
242
+
ASSERT_THROW_EQUALS(::strToInt<std::size_t>("-0"), std::runtime_error, "converting '-0' to integer failed - needs to be positive");
233
243
ASSERT_THROW_EQUALS(::strToInt<int>("1ms"), std::runtime_error, "converting '1ms' to integer failed - not an integer");
234
244
ASSERT_THROW_EQUALS(::strToInt<int>("1.0"), std::runtime_error, "converting '1.0' to integer failed - not an integer");
245
+
ASSERT_THROW_EQUALS(::strToInt<int>("+1.0"), std::runtime_error, "converting '+1.0' to integer failed - not an integer");
246
+
ASSERT_THROW_EQUALS(::strToInt<int>("-1.0"), std::runtime_error, "converting '-1.0' to integer failed - not an integer");
235
247
ASSERT_THROW_EQUALS(::strToInt<int>("one"), std::runtime_error, "converting 'one' to integer failed - not an integer");
248
+
//ASSERT_THROW_EQUALS(::strToInt<int>(" 1"), std::runtime_error, "converting ' 1' to integer failed - not an integer"); // TODO: should fail
249
+
//ASSERT_THROW_EQUALS(::strToInt<int>("\t1"), std::runtime_error, "converting '\t1' to integer failed - not an integer"); // TODO should fail
250
+
ASSERT_THROW_EQUALS(::strToInt<int>("1 "), std::runtime_error, "converting '1 ' to integer failed - not an integer");
251
+
ASSERT_THROW_EQUALS(::strToInt<int>("1\t"), std::runtime_error, "converting '1\t' to integer failed - not an integer");
252
+
ASSERT_THROW_EQUALS(::strToInt<int>("+ 1"), std::runtime_error, "converting '+ 1' to integer failed - not an integer");
236
253
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("1ms"), std::runtime_error, "converting '1ms' to integer failed - not an integer");
237
254
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("1.0"), std::runtime_error, "converting '1.0' to integer failed - not an integer");
255
+
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("+1.0"), std::runtime_error, "converting '+1.0' to integer failed - not an integer");
256
+
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("-1.0"), std::runtime_error, "converting '-1.0' to integer failed - not an integer");
238
257
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("one"), std::runtime_error, "converting 'one' to integer failed - not an integer");
258
+
//ASSERT_THROW_EQUALS(::strToInt<unsigned int>(" 1"), std::runtime_error, "converting ' 1' to integer failed - not an integer"); // TODO: should fail
259
+
//ASSERT_THROW_EQUALS(::strToInt<unsigned int>("\t1"), std::runtime_error, "converting '\t1' to integer failed - not an integer"); // TODO: should fail
260
+
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("1 "), std::runtime_error, "converting '1 ' to integer failed - not an integer");
261
+
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("1\t"), std::runtime_error, "converting '1\t' to integer failed - not an integer");
262
+
ASSERT_THROW_EQUALS(::strToInt<unsignedint>("- 1"), std::runtime_error, "converting '- 1' to integer failed - not an integer");
239
263
ASSERT_THROW_EQUALS(::strToInt<int>(std::to_string(static_cast<int64_t>(std::numeric_limits<int>::max()) + 1)), std::runtime_error, "converting '2147483648' to integer failed - out of range (limits)");
240
264
ASSERT_THROW_EQUALS(::strToInt<int>(std::to_string(static_cast<int64_t>(std::numeric_limits<int>::min()) - 1)), std::runtime_error, "converting '-2147483649' to integer failed - out of range (limits)");
241
265
ASSERT_THROW_EQUALS(::strToInt<int8_t>(std::to_string(static_cast<int64_t>(std::numeric_limits<int8_t>::max()) + 1)), std::runtime_error, "converting '128' to integer failed - out of range (limits)");
0 commit comments