fastcheck_ut.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "fastcheck.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. using namespace NYql;
  4. using namespace NYql::NFastCheck;
  5. Y_UNIT_TEST_SUITE(TFastCheckTests) {
  6. Y_UNIT_TEST(ParsePureYqlGood) {
  7. TOptions options;
  8. options.IsSql = false;
  9. options.ParseOnly = true;
  10. TIssues errors;
  11. UNIT_ASSERT(CheckProgram("(return world)", options, errors));
  12. UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
  13. }
  14. Y_UNIT_TEST(ParsePureYqlBad) {
  15. TOptions options;
  16. options.IsSql = false;
  17. options.ParseOnly = true;
  18. TIssues errors;
  19. UNIT_ASSERT(CheckProgram("(return world1)", options, errors));
  20. UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
  21. }
  22. Y_UNIT_TEST(ParsePureSqlGood) {
  23. TOptions options;
  24. options.IsSql = true;
  25. options.ParseOnly = true;
  26. TIssues errors;
  27. UNIT_ASSERT(CheckProgram("select 1", options, errors));
  28. UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
  29. }
  30. Y_UNIT_TEST(ParsePureSqlBad) {
  31. TOptions options;
  32. options.IsSql = true;
  33. options.ParseOnly = true;
  34. TIssues errors;
  35. UNIT_ASSERT(!CheckProgram("select1", options, errors));
  36. UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
  37. }
  38. Y_UNIT_TEST(CompilePureYqlBad) {
  39. TOptions options;
  40. options.IsSql = false;
  41. options.ParseOnly = false;
  42. TIssues errors;
  43. UNIT_ASSERT(!CheckProgram("(return world1)", options, errors));
  44. UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
  45. }
  46. Y_UNIT_TEST(CompileTableSqlGood) {
  47. TOptions options;
  48. options.IsSql = true;
  49. options.ParseOnly = false;
  50. options.ClusterMapping["plato"] = YtProviderName;
  51. TIssues errors;
  52. UNIT_ASSERT(CheckProgram("select key,count(*) from plato.Input group by key", options, errors));
  53. UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
  54. }
  55. Y_UNIT_TEST(CompileTableSqlBad) {
  56. TOptions options;
  57. options.IsSql = true;
  58. options.ParseOnly = false;
  59. TIssues errors;
  60. UNIT_ASSERT(!CheckProgram("select key,count(*) from plato.Input", options, errors));
  61. UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
  62. }
  63. Y_UNIT_TEST(CompileLibrary) {
  64. TOptions options;
  65. options.IsSql = true;
  66. options.IsLibrary = true;
  67. TIssues errors;
  68. UNIT_ASSERT(CheckProgram("$x = 1; export $x", options, errors));
  69. UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
  70. }
  71. Y_UNIT_TEST(CompileSqlWithLibsGood) {
  72. TOptions options;
  73. options.IsSql = true;
  74. options.ParseOnly = false;
  75. options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
  76. TIssues errors;
  77. UNIT_ASSERT(CheckProgram("pragma library('foo.sql');import foo symbols $x; select $x", options, errors));
  78. UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
  79. }
  80. Y_UNIT_TEST(ParseSqlWithBadLib) {
  81. TOptions options;
  82. options.IsSql = true;
  83. options.ParseOnly = true;
  84. options.SqlLibs["foo.sql"] = "$x = 1; zexport $x;";
  85. TIssues errors;
  86. UNIT_ASSERT(!CheckProgram("pragma library('foo.sql');import foo symbols $x; select $x", options, errors));
  87. UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
  88. }
  89. Y_UNIT_TEST(CompileSqlWithUnresolvedLib) {
  90. TOptions options;
  91. options.IsSql = true;
  92. options.ParseOnly = false;
  93. options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
  94. TIssues errors;
  95. UNIT_ASSERT(!CheckProgram("pragma library('foo.sql');import foo symbols $y; select $y", options, errors));
  96. UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
  97. }
  98. Y_UNIT_TEST(ParseSqlWithUnresolvedLib) {
  99. TOptions options;
  100. options.IsSql = true;
  101. options.ParseOnly = true;
  102. options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
  103. TIssues errors;
  104. UNIT_ASSERT(CheckProgram("pragma library('foo.sql');import foo symbols $y; select $y", options, errors));
  105. UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
  106. }
  107. }