diff options
author | swarmer <swarmer@yandex-team.com> | 2024-09-30 22:24:38 +0300 |
---|---|---|
committer | swarmer <swarmer@yandex-team.com> | 2024-09-30 22:35:54 +0300 |
commit | 803c95f77d7e098750be07c125e78f892ec7c169 (patch) | |
tree | d69fd2dbf013c998844350fc99b20929ab0ac9f2 /tools/enum_parser/parse_enum/parse_enum_ut.cpp | |
parent | a6718e3c426bdd6f17af1f4f68f5a6a9b13f47be (diff) | |
download | ydb-803c95f77d7e098750be07c125e78f892ec7c169.tar.gz |
enum_parser: support digit separators in numeric literals
commit_hash:9791d25e9ea02f73329f9755f7c70f335c612121
Diffstat (limited to 'tools/enum_parser/parse_enum/parse_enum_ut.cpp')
-rw-r--r-- | tools/enum_parser/parse_enum/parse_enum_ut.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/enum_parser/parse_enum/parse_enum_ut.cpp b/tools/enum_parser/parse_enum/parse_enum_ut.cpp index 21ed6a2fc4..e979f5119a 100644 --- a/tools/enum_parser/parse_enum/parse_enum_ut.cpp +++ b/tools/enum_parser/parse_enum/parse_enum_ut.cpp @@ -3,10 +3,30 @@ #include <tools/enum_parser/parse_enum/parse_enum.h> +#include <util/generic/array_ref.h> +#include <util/generic/maybe.h> + typedef TEnumParser::TEnum TEnum; typedef TEnumParser::TEnums TEnums; typedef TEnumParser::TItems TItems; +namespace { + using TNameValuePair = std::pair<TStringBuf, TMaybe<TStringBuf>>; + + void CompareNameValueItems(TConstArrayRef<TNameValuePair> ref, const TEnum& e) { + const TItems& it = e.Items; + for (size_t i = 0; i < Min(ref.size(), it.size()); ++i) { + const auto& [refCppName, refValue] = ref[i]; + UNIT_ASSERT_VALUES_EQUAL_C(it[i].CppName, refCppName, e.CppName); + UNIT_ASSERT_EQUAL_C(it[i].Value.Defined(), refValue.Defined(), e.CppName); + if (refValue.Defined() && it[i].Value.Defined()) { + UNIT_ASSERT_VALUES_EQUAL_C(*it[i].Value, *refValue, e.CppName); + } + } + UNIT_ASSERT_VALUES_EQUAL_C(it.size(), ref.size(), e.CppName); + } +} + Y_UNIT_TEST_SUITE(TEnumParserTest) { Y_UNIT_TEST(MainTest) { @@ -312,4 +332,41 @@ Y_UNIT_TEST_SUITE(TEnumParserTest) { UNIT_ASSERT(CurrentExceptionMessage().Contains("https://clubs.at.yandex-team.ru/stackoverflow/2603")); } } + + Y_UNIT_TEST(DigitSeparatorTest) { + TString text = NResource::Find("/digit_separator"); + TMemoryInput input(text.data(), text.size()); + TEnumParser parser(input); + const TEnums& enums = parser.Enums; + UNIT_ASSERT_VALUES_EQUAL(enums.size(), 2u); + { + const TEnum& e = enums[0]; + UNIT_ASSERT_VALUES_EQUAL(e.CppName, "ELiterals"); + static constexpr TNameValuePair ref[]{ + {"Char", "sizeof(u8'.')"}, + {"Int", "123'456'789"}, + {"Float1", "int(456'789.123'456)"}, + {"Float2", "int(1'2e0'1)"}, + {"Float3", "int(0x1'2p4)"}, + }; + CompareNameValueItems(ref, e); + UNIT_ASSERT_VALUES_EQUAL(e.Scope.size(), 0u); + } + { + const TEnum& e = enums[1]; + UNIT_ASSERT_VALUES_EQUAL(e.Scope.size(), 0u); + UNIT_ASSERT_VALUES_EQUAL(e.CppName, "ETimePrecision"); + static constexpr TNameValuePair ref[]{ + {"MicroSeconds", "1"}, + {"MilliSeconds", "1'000"}, + {"Seconds", "1'000'000"}, + {"Minutes", "60'000'000"}, + {"Hours", "3'600'000'000"}, + {"Days", "86'400'000'000"}, + {"Weeks", "604'800'000'000"}, + }; + CompareNameValueItems(ref, e); + UNIT_ASSERT_VALUES_EQUAL(e.Scope.size(), 0u); + } + } } |