serialize_ut.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <yt/cpp/mapreduce/interface/serialize.h>
  2. #include <yt/cpp/mapreduce/interface/common.h>
  3. #include <library/cpp/yson/node/node_builder.h>
  4. #include <library/cpp/testing/unittest/registar.h>
  5. #include <util/generic/serialized_enum.h>
  6. using namespace NYT;
  7. Y_UNIT_TEST_SUITE(Serialization)
  8. {
  9. Y_UNIT_TEST(TableSchema)
  10. {
  11. auto schema = TTableSchema()
  12. .AddColumn(TColumnSchema().Name("a").Type(EValueType::VT_STRING).SortOrder(SO_ASCENDING))
  13. .AddColumn(TColumnSchema().Name("b").Type(EValueType::VT_UINT64))
  14. .AddColumn(TColumnSchema().Name("c").Type(EValueType::VT_INT64, true));
  15. auto schemaNode = schema.ToNode();
  16. UNIT_ASSERT(schemaNode.IsList());
  17. UNIT_ASSERT_VALUES_EQUAL(schemaNode.Size(), 3);
  18. UNIT_ASSERT_VALUES_EQUAL(schemaNode[0]["name"], "a");
  19. UNIT_ASSERT_VALUES_EQUAL(schemaNode[0]["type"], "string");
  20. UNIT_ASSERT_VALUES_EQUAL(schemaNode[0]["required"], false);
  21. UNIT_ASSERT_VALUES_EQUAL(schemaNode[0]["sort_order"], "ascending");
  22. UNIT_ASSERT_VALUES_EQUAL(schemaNode[1]["name"], "b");
  23. UNIT_ASSERT_VALUES_EQUAL(schemaNode[1]["type"], "uint64");
  24. UNIT_ASSERT_VALUES_EQUAL(schemaNode[1]["required"], false);
  25. UNIT_ASSERT_VALUES_EQUAL(schemaNode[2]["name"], "c");
  26. UNIT_ASSERT_VALUES_EQUAL(schemaNode[2]["type"], "int64");
  27. UNIT_ASSERT_VALUES_EQUAL(schemaNode[2]["required"], true);
  28. }
  29. Y_UNIT_TEST(ValueTypeSerialization)
  30. {
  31. for (const auto value : GetEnumAllValues<EValueType>()) {
  32. TNode serialized = NYT::NDetail::ToString(value);
  33. EValueType deserialized;
  34. Deserialize(deserialized, serialized);
  35. UNIT_ASSERT_VALUES_EQUAL(value, deserialized);
  36. }
  37. }
  38. }