diff options
author | gleb-kov <gleb-kov@yandex-team.ru> | 2022-02-16 20:08:53 +0300 |
---|---|---|
committer | gleb-kov <gleb-kov@yandex-team.ru> | 2022-02-16 20:08:53 +0300 |
commit | 76cbe125b7d39dca64a0de7b86eee37fd575e4df (patch) | |
tree | 07e37c2710f2e28d0703b034d5055410a8cef162 /util/string | |
parent | ba7bb8654688e77fb83af2e6f9e82ef5ea10dfc5 (diff) | |
download | ydb-76cbe125b7d39dca64a0de7b86eee37fd575e4df.tar.gz |
util unittests: replace try-catch-UNIT_ASSERT via UNIT_ASSERT_EXCEPTION
ref:f59ddae7dbb42f5fa999e6071769f709e8b80b85
Diffstat (limited to 'util/string')
-rw-r--r-- | util/string/cast_ut.cpp | 48 |
1 files changed, 5 insertions, 43 deletions
diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 033450c38c..ca235c1436 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -464,50 +464,12 @@ Y_UNIT_TEST_SUITE(TCastTest) { UNIT_ASSERT_VALUES_EQUAL(integer, wideCharacterCode); } - static void CheckMessage(TFromStringException& exc, const TString& phrase) { - TString message = exc.what(); - if (!message.Contains(phrase)) { - Cerr << message << Endl; - UNIT_ASSERT(false); - } - } - Y_UNIT_TEST(ErrorMessages) { - try { - FromString<ui32>(""); - UNIT_ASSERT(false); - } catch (TFromStringException& e) { - CheckMessage(e, "empty string as number"); - } - - try { - FromString<ui32>("-"); - UNIT_ASSERT(false); - } catch (TFromStringException& e) { - // Unsigned should have no sign at all, so - is not expected - CheckMessage(e, "Unexpected symbol \"-\" at pos 0 in string \"-\""); - } - - try { - FromString<i32>("-"); - UNIT_ASSERT(false); - } catch (TFromStringException& e) { - CheckMessage(e, "Cannot parse string \"-\" as number"); - } - - try { - FromString<i32>("+"); - UNIT_ASSERT(false); - } catch (TFromStringException& e) { - CheckMessage(e, "Cannot parse string \"+\" as number"); - } - - try { - FromString<ui32>("0.328413745072"); - UNIT_ASSERT(false); - } catch (TFromStringException& e) { - CheckMessage(e, "Unexpected symbol \".\" at pos 1 in string \"0.328413745072\""); - } + UNIT_ASSERT_EXCEPTION_CONTAINS(FromString<ui32>(""), TFromStringException, "empty string as number"); + UNIT_ASSERT_EXCEPTION_CONTAINS(FromString<ui32>("-"), TFromStringException, "Unexpected symbol \"-\" at pos 0 in string \"-\""); + UNIT_ASSERT_EXCEPTION_CONTAINS(FromString<i32>("-"), TFromStringException, "Cannot parse string \"-\" as number"); + UNIT_ASSERT_EXCEPTION_CONTAINS(FromString<i32>("+"), TFromStringException, "Cannot parse string \"+\" as number"); + UNIT_ASSERT_EXCEPTION_CONTAINS(FromString<i32>("0.328413745072"), TFromStringException, "Unexpected symbol \".\" at pos 1 in string \"0.328413745072\""); } Y_UNIT_TEST(TryStringBuf) { |