mkql_node_cast_ut.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "mkql_node.h"
  2. #include "mkql_node_cast.h"
  3. #include "mkql_node_builder.h"
  4. #include <library/cpp/testing/unittest/registar.h>
  5. namespace NKikimr {
  6. namespace NMiniKQL {
  7. class TMiniKQLNodeCast: public TTestBase
  8. {
  9. UNIT_TEST_SUITE(TMiniKQLNodeCast);
  10. UNIT_TEST(AsTypeTest);
  11. UNIT_TEST_EXCEPTION(BadAsTypeTest, yexception);
  12. UNIT_TEST(AsValueTest);
  13. UNIT_TEST_EXCEPTION(BadAsValueTest, yexception);
  14. UNIT_TEST_SUITE_END();
  15. void AsTypeTest() {
  16. TRuntimeNode node = Uint32AsNode(123);
  17. TDataType* type = AS_TYPE(TDataType, node);
  18. UNIT_ASSERT_EQUAL(type, node.GetStaticType());
  19. UNIT_ASSERT_EQUAL(type, node.GetNode()->GetType());
  20. }
  21. void BadAsTypeTest() {
  22. TRuntimeNode node = Uint32AsNode(123);
  23. TCallableType* type = AS_TYPE(TCallableType, node);
  24. Y_UNUSED(type);
  25. }
  26. void AsValueTest() {
  27. TRuntimeNode dataNode = Uint32AsNode(123);
  28. TCallableType* ctype = TCallableType::Create(
  29. "callable", dataNode.GetStaticType(),
  30. 0, nullptr, nullptr, Env);
  31. TCallable* callable = TCallable::Create(dataNode, ctype, Env);
  32. TRuntimeNode node(callable, false);
  33. node.Freeze();
  34. TDataLiteral* value = AS_VALUE(TDataLiteral, node);
  35. UNIT_ASSERT_EQUAL(value, dataNode.GetNode());
  36. }
  37. void BadAsValueTest() {
  38. TRuntimeNode node = Uint32AsNode(123);
  39. TListLiteral* list = AS_VALUE(TListLiteral, node);
  40. Y_UNUSED(list);
  41. }
  42. TMiniKQLNodeCast()
  43. : Alloc(__LOCATION__)
  44. , Env(Alloc)
  45. {}
  46. private:
  47. TRuntimeNode Uint32AsNode(ui32 value) {
  48. return TRuntimeNode(BuildDataLiteral(NUdf::TUnboxedValuePod(value), NUdf::EDataSlot::Uint32, Env), true);
  49. }
  50. private:
  51. TScopedAlloc Alloc;
  52. TTypeEnvironment Env;
  53. };
  54. UNIT_TEST_SUITE_REGISTRATION(TMiniKQLNodeCast);
  55. } // namespace NMiniKQL
  56. } // namespace NKikimr