printf_ut.cpp 917 B

123456789101112131415161718192021222324252627282930
  1. #include "printf.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. Y_UNIT_TEST_SUITE(TStringPrintf) {
  4. Y_UNIT_TEST(TestSprintf) {
  5. TString s;
  6. int len = sprintf(s, "Hello %s", "world");
  7. UNIT_ASSERT_EQUAL(s, TString("Hello world"));
  8. UNIT_ASSERT_EQUAL(len, 11);
  9. }
  10. Y_UNIT_TEST(TestFcat) {
  11. TString s;
  12. int len = sprintf(s, "Hello %s", "world");
  13. UNIT_ASSERT_EQUAL(s, TString("Hello world"));
  14. UNIT_ASSERT_EQUAL(len, 11);
  15. len = fcat(s, " qwqw%s", "as");
  16. UNIT_ASSERT_EQUAL(s, TString("Hello world qwqwas"));
  17. UNIT_ASSERT_EQUAL(len, 7);
  18. }
  19. Y_UNIT_TEST(TestSpecial) {
  20. UNIT_ASSERT_EQUAL("4294967295", Sprintf("%" PRIu32, (ui32)(-1)));
  21. }
  22. Y_UNIT_TEST(TestExplicitPositions) {
  23. UNIT_ASSERT_EQUAL("abc xyz abc", Sprintf("%1$s %2$s %1$s", "abc", "xyz"));
  24. }
  25. } // Y_UNIT_TEST_SUITE(TStringPrintf)