parse_hints_ut.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <yql/essentials/parser/lexer_common/parse_hints_impl.h>
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/string/join.h>
  4. using namespace NSQLTranslation;
  5. using namespace NSQLTranslation::NDetail;
  6. void CheckParse(TStringBuf comment, TStringBuf expected) {
  7. TString parsed = JoinSeq(",", ParseSqlHints({}, comment, false));
  8. UNIT_ASSERT_NO_DIFF(parsed, expected);
  9. }
  10. Y_UNIT_TEST_SUITE(TParseTests) {
  11. Y_UNIT_TEST(NoPlusInComment) {
  12. CheckParse("/* foo(bar) */", "");
  13. CheckParse("-- foo(bar)\n", "");
  14. }
  15. Y_UNIT_TEST(Basic) {
  16. TStringBuf comment = "/*+Foo( Bar 0Baz*) test\nFoo1(Bar1 Bar2)\n Foo2()*/";
  17. TStringBuf expected = R"raw("Foo":{"Bar","0Baz*"},"Foo1":{"Bar1","Bar2"},"Foo2":{})raw";
  18. CheckParse(comment, expected);
  19. }
  20. Y_UNIT_TEST(Quoted) {
  21. TStringBuf comment = "/*+Foo('Bar' Baz 'Bar'' quote')*/";
  22. TStringBuf expected = R"raw("Foo":{"Bar","Baz","Bar' quote"})raw";
  23. CheckParse(comment, expected);
  24. }
  25. Y_UNIT_TEST(MissingSpace) {
  26. TStringBuf comment = "/*+Foo()Bar(x)*/";
  27. TStringBuf expected = R"raw("Foo":{})raw";
  28. CheckParse(comment, expected);
  29. }
  30. }