walk_ut.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "walk.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. class TStringListInput: public IWalkInput {
  4. public:
  5. TStringListInput(const TVector<TString>& data)
  6. : Data_(data)
  7. , Index_(0)
  8. {
  9. }
  10. protected:
  11. size_t DoUnboundedNext(const void** ptr) override {
  12. if (Index_ >= Data_.size()) {
  13. return 0;
  14. }
  15. const TString& string = Data_[Index_++];
  16. *ptr = string.data();
  17. return string.size();
  18. }
  19. private:
  20. const TVector<TString>& Data_;
  21. size_t Index_;
  22. };
  23. Y_UNIT_TEST_SUITE(TWalkTest) {
  24. Y_UNIT_TEST(ReadTo) {
  25. TVector<TString> data;
  26. data.push_back("111a");
  27. data.push_back("222b");
  28. data.push_back("333c");
  29. data.push_back("444d");
  30. data.push_back("555e");
  31. data.push_back("666f");
  32. TStringListInput input(data);
  33. TString tmp1 = input.ReadTo('c');
  34. UNIT_ASSERT_VALUES_EQUAL(tmp1, "111a222b333");
  35. char tmp2;
  36. input.Read(&tmp2, 1);
  37. UNIT_ASSERT_VALUES_EQUAL(tmp2, '4');
  38. TString tmp3 = input.ReadTo('6');
  39. UNIT_ASSERT_VALUES_EQUAL(tmp3, "44d555e");
  40. TString tmp4 = input.ReadAll();
  41. UNIT_ASSERT_VALUES_EQUAL(tmp4, "66f");
  42. }
  43. } // Y_UNIT_TEST_SUITE(TWalkTest)