format_std_ut.cpp 1.7 KB

1234567891011121314151617181920212223242526272829
  1. #include "format.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <sstream>
  4. Y_UNIT_TEST_SUITE(StdOstreamFormattingTest) {
  5. template <typename T>
  6. TString ToStringViaOstream(T baseNumber) {
  7. std::stringstream ss;
  8. ss << baseNumber;
  9. return ss.str();
  10. }
  11. Y_UNIT_TEST(TestBin) {
  12. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<ui32>(2), nullptr)), "10");
  13. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(SBin(static_cast<i32>(-2), nullptr)), "-10");
  14. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(SBin(static_cast<i32>(-2))), "-0b00000000000000000000000000000010");
  15. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(SBin(static_cast<i32>(-2), HF_FULL)), "-00000000000000000000000000000010");
  16. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<ui32>(15), nullptr)), "1111");
  17. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<ui32>(1))), "0b00000000000000000000000000000001");
  18. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<ui32>(-1))), "0b11111111111111111111111111111111");
  19. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<i32>(-1))), "0b11111111111111111111111111111111");
  20. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<i32>(-1), nullptr)), "11111111111111111111111111111111");
  21. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<ui32>(256))), "0b00000000000000000000000100000000");
  22. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<ui8>(16))), "0b00010000");
  23. UNIT_ASSERT_VALUES_EQUAL(ToStringViaOstream(Bin(static_cast<ui64>(1234587912357ull))), "0b0000000000000000000000010001111101110011001011001000100010100101");
  24. }
  25. } // Y_UNIT_TEST_SUITE(StdOstreamFormattingTest)