test_base.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include <yql/essentials/core/issue/protos/issue_id.pb.h>
  3. #include <yql/essentials/minikql/jsonpath/jsonpath.h>
  4. #include <yql/essentials/minikql/dom/json.h>
  5. #include <yql/essentials/minikql/computation/mkql_value_builder.h>
  6. #include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>
  7. #include <yql/essentials/minikql/invoke_builtins/mkql_builtins.h>
  8. #include <yql/essentials/minikql/mkql_mem_info.h>
  9. #include <yql/essentials/minikql/mkql_function_registry.h>
  10. #include <yql/essentials/minikql/mkql_alloc.h>
  11. #include <yql/essentials/minikql/mkql_node.h>
  12. #include <library/cpp/json/json_reader.h>
  13. #include <library/cpp/testing/unittest/registar.h>
  14. #include <util/generic/yexception.h>
  15. using namespace NYql;
  16. using namespace NYql::NDom;
  17. using namespace NYql::NUdf;
  18. using namespace NYql::NJsonPath;
  19. using namespace NJson;
  20. using namespace NKikimr::NMiniKQL;
  21. class TJsonPathTestBase: public TTestBase {
  22. public:
  23. TJsonPathTestBase();
  24. protected:
  25. const TVector<TStringBuf> LAX_MODES = {"", "lax "};
  26. const TVector<TStringBuf> STRICT_MODES = {"strict "};
  27. const TVector<TStringBuf> ALL_MODES = {"", "lax ", "strict "};
  28. TIntrusivePtr<IFunctionRegistry> FunctionRegistry;
  29. TScopedAlloc Alloc;
  30. TTypeEnvironment Env;
  31. TMemoryUsageInfo MemInfo;
  32. THolderFactory HolderFactory;
  33. TDefaultValueBuilder ValueBuilder;
  34. const int MAX_PARSE_ERRORS = 100;
  35. TIssueCode C(TIssuesIds::EIssueCode code);
  36. TUnboxedValue ParseJson(TStringBuf raw);
  37. struct TMultiOutputTestCase {
  38. TString Json;
  39. TString JsonPath;
  40. TVector<TString> Result;
  41. };
  42. void RunTestCase(const TString& rawJson, const TString& rawJsonPath, const TVector<TString>& expectedResult);
  43. void RunParseErrorTestCase(const TString& rawJsonPath);
  44. struct TRuntimeErrorTestCase {
  45. TString Json;
  46. TString JsonPath;
  47. TIssueCode Error;
  48. };
  49. void RunRuntimeErrorTestCase(const TString& rawJson, const TString& rawJsonPath, TIssueCode error);
  50. struct TVariablesTestCase {
  51. TString Json;
  52. THashMap<TStringBuf, TStringBuf> Variables;
  53. TString JsonPath;
  54. TVector<TString> Result;
  55. };
  56. void RunVariablesTestCase(const TString& rawJson, const THashMap<TStringBuf, TStringBuf>& variables, const TString& rawJsonPath, const TVector<TString>& expectedResult);
  57. };