enum_codegen_ut.cpp 889 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include "enum_codegen.h"
  3. #include <util/string/builder.h>
  4. #define COLOR_MAP(XX) \
  5. XX(RED) \
  6. XX(GREEN) \
  7. XX(BLUE)
  8. enum EColor {
  9. COLOR_MAP(ENUM_VALUE_GEN_NO_VALUE)
  10. };
  11. ENUM_TO_STRING(EColor, COLOR_MAP)
  12. #define MULTIPLIER_MAP(XX) \
  13. XX(GB, 9) \
  14. XX(MB, 6) \
  15. XX(KB, 3)
  16. enum EMultiplier {
  17. MULTIPLIER_MAP(ENUM_VALUE_GEN)
  18. };
  19. ENUM_TO_STRING(EMultiplier, MULTIPLIER_MAP)
  20. Y_UNIT_TEST_SUITE(EnumCodegen) {
  21. Y_UNIT_TEST(GenWithValue) {
  22. UNIT_ASSERT_VALUES_EQUAL(6, MB);
  23. }
  24. Y_UNIT_TEST(ToCString) {
  25. UNIT_ASSERT_VALUES_EQUAL("RED", ToCString(RED));
  26. UNIT_ASSERT_VALUES_EQUAL("BLUE", ToCString(BLUE));
  27. UNIT_ASSERT_VALUES_EQUAL("GREEN", (TStringBuilder() << GREEN));
  28. UNIT_ASSERT_VALUES_EQUAL("GB", ToCString(GB));
  29. }
  30. }