mkql_string_util_ut.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "mkql_alloc.h"
  2. #include "mkql_string_util.h"
  3. #include <library/cpp/testing/unittest/registar.h>
  4. using namespace NYql;
  5. using namespace NKikimr::NMiniKQL;
  6. Y_UNIT_TEST_SUITE(TMiniKQLStringUtils) {
  7. Y_UNIT_TEST(SubstringWithLargeOffset) {
  8. TScopedAlloc alloc(__LOCATION__);
  9. const auto big = MakeStringNotFilled(NUdf::TUnboxedValuePod::OffsetLimit << 1U);
  10. const auto sub0 = SubString(big, 1U, 42U);
  11. const auto sub1 = SubString(big, NUdf::TUnboxedValuePod::OffsetLimit - 1U, 42U);
  12. const auto sub2 = SubString(big, NUdf::TUnboxedValuePod::OffsetLimit, 42U);
  13. UNIT_ASSERT(sub0.AsStringValue().Data() == sub1.AsStringValue().Data());
  14. UNIT_ASSERT(sub1.AsStringValue().Data() != sub2.AsStringValue().Data());
  15. }
  16. Y_UNIT_TEST(MakeStringWithPad) {
  17. TScopedAlloc alloc(__LOCATION__);
  18. {
  19. const auto buf= MakeStringNotFilled(NUdf::TUnboxedValuePod::InternalBufferSize - 1U, 1U);
  20. UNIT_ASSERT(buf.IsEmbedded());
  21. UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), NUdf::TUnboxedValuePod::InternalBufferSize - 1U);
  22. }
  23. {
  24. const auto buf= MakeStringNotFilled(NUdf::TUnboxedValuePod::InternalBufferSize, 1U);
  25. UNIT_ASSERT(buf.IsString());
  26. UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), NUdf::TUnboxedValuePod::InternalBufferSize);
  27. UNIT_ASSERT_VALUES_EQUAL(buf.AsStringValue().Size(), NUdf::TUnboxedValuePod::InternalBufferSize + 1U);
  28. }
  29. }
  30. Y_UNIT_TEST(MakeLargeString) {
  31. TScopedAlloc alloc(__LOCATION__);
  32. {
  33. const auto buf= MakeStringNotFilled(0xFFFFFFFFU);
  34. UNIT_ASSERT(buf.IsString());
  35. UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFFFU);
  36. const auto& value = buf.AsStringValue();
  37. UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFFFU);
  38. UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0x100000000ULL);
  39. }
  40. {
  41. const auto buf= MakeStringNotFilled(0xFFFFFFF1U);
  42. UNIT_ASSERT(buf.IsString());
  43. UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFF1U);
  44. const auto& value = buf.AsStringValue();
  45. UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFF1U);
  46. UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0x100000000ULL);
  47. }
  48. {
  49. const auto buf= MakeStringNotFilled(0xFFFFFFF0U);
  50. UNIT_ASSERT(buf.IsString());
  51. UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFF0U);
  52. const auto& value = buf.AsStringValue();
  53. UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFF0U);
  54. UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0xFFFFFFF0ULL);
  55. }
  56. }
  57. Y_UNIT_TEST(ConcatLargeString) {
  58. TScopedAlloc alloc(__LOCATION__);
  59. const NUdf::TUnboxedValue buf = MakeStringNotFilled(0x80000000U);
  60. try {
  61. ConcatStrings(buf, buf);
  62. UNIT_FAIL("No exception!");
  63. } catch (const yexception&) {}
  64. try {
  65. PrependString(buf.AsStringRef(), buf);
  66. UNIT_FAIL("No exception!");
  67. } catch (const yexception&) {}
  68. try {
  69. AppendString(buf, buf.AsStringRef());
  70. UNIT_FAIL("No exception!");
  71. } catch (const yexception&) {}
  72. }
  73. }