case_insensitive_string_ut.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "case_insensitive_string.h"
  2. #include <util/generic/string_ut.h>
  3. class TCaseInsensitiveStringTest : public TTestBase, private TStringTestImpl<TCaseInsensitiveString, TTestData<char>> {
  4. public:
  5. UNIT_TEST_SUITE(TCaseInsensitiveStringTest);
  6. UNIT_TEST(TestOperators);
  7. UNIT_TEST(TestOperatorsCI);
  8. UNIT_TEST_SUITE_END();
  9. };
  10. UNIT_TEST_SUITE_REGISTRATION(TCaseInsensitiveStringTest);
  11. Y_UNIT_TEST_SUITE(TCaseInsensitiveStringTestEx) {
  12. Y_UNIT_TEST(BasicTString) {
  13. TCaseInsensitiveString foo("foo");
  14. TCaseInsensitiveString FOO("FOO");
  15. TCaseInsensitiveString Bar("Bar");
  16. TCaseInsensitiveString bAR("bAR");
  17. UNIT_ASSERT_EQUAL(foo, FOO);
  18. UNIT_ASSERT_EQUAL(Bar, bAR);
  19. constexpr TCaseInsensitiveStringBuf foobar("foobar");
  20. UNIT_ASSERT(foobar.StartsWith(foo));
  21. UNIT_ASSERT(foobar.StartsWith(FOO));
  22. UNIT_ASSERT(foobar.EndsWith(Bar));
  23. UNIT_ASSERT(foobar.EndsWith(bAR));
  24. UNIT_ASSERT(foobar.Contains(FOO));
  25. UNIT_ASSERT(foobar.Contains(Bar));
  26. }
  27. Y_UNIT_TEST(BasicStdString) {
  28. using TCaseInsensitiveStdString = std::basic_string<char, TCaseInsensitiveCharTraits>;
  29. using TCaseInsensitiveStringView = std::basic_string_view<char, TCaseInsensitiveCharTraits>;
  30. TCaseInsensitiveStdString foo("foo");
  31. TCaseInsensitiveStdString FOO("FOO");
  32. TCaseInsensitiveStdString Bar("Bar");
  33. TCaseInsensitiveStdString bAR("bAR");
  34. UNIT_ASSERT_EQUAL(foo, FOO);
  35. UNIT_ASSERT_EQUAL(Bar, bAR);
  36. constexpr TCaseInsensitiveStringView foobar("foobar");
  37. UNIT_ASSERT(foobar.starts_with(foo));
  38. UNIT_ASSERT(foobar.starts_with(FOO));
  39. UNIT_ASSERT(foobar.ends_with(Bar));
  40. UNIT_ASSERT(foobar.ends_with(bAR));
  41. //TODO: test contains after C++23
  42. }
  43. /*
  44. Y_UNIT_TEST(TestSplit) {
  45. TCaseInsensitiveStringBuf input("splitAmeAbro");
  46. TVector<TCaseInsensitiveStringBuf> expected{"split", "me", "bro"};
  47. TVector<TCaseInsensitiveStringBuf> split = StringSplitter(input).Split('a');
  48. UNIT_ASSERT_VALUES_EQUAL(split, expected);
  49. }
  50. */
  51. }