aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/parser/lexer_common/ut/parse_hints_ut.cpp
blob: f2f4ebca819dc3e5f6a7c0a9aa5de2c091012306 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <yql/essentials/parser/lexer_common/parse_hints_impl.h>

#include <library/cpp/testing/unittest/registar.h>

#include <util/string/join.h>

using namespace NSQLTranslation;
using namespace NSQLTranslation::NDetail;

void CheckParse(TStringBuf comment, TStringBuf expected) {
    TString parsed = JoinSeq(",", ParseSqlHints({}, comment, false));
    UNIT_ASSERT_NO_DIFF(parsed, expected);
}

Y_UNIT_TEST_SUITE(TParseTests) {
    Y_UNIT_TEST(NoPlusInComment) {
        CheckParse("/* foo(bar) */", "");
        CheckParse("-- foo(bar)\n", "");
    }

    Y_UNIT_TEST(Basic) {
        TStringBuf comment = "/*+Foo( Bar 0Baz*) test\nFoo1(Bar1    Bar2)\n Foo2()*/";
        TStringBuf expected = R"raw("Foo":{"Bar","0Baz*"},"Foo1":{"Bar1","Bar2"},"Foo2":{})raw";
        CheckParse(comment, expected);
    }

    Y_UNIT_TEST(Quoted) {
        TStringBuf comment = "/*+Foo('Bar' Baz 'Bar'' quote')*/";
        TStringBuf expected = R"raw("Foo":{"Bar","Baz","Bar' quote"})raw";
        CheckParse(comment, expected);
    }

    Y_UNIT_TEST(MissingSpace) {
        TStringBuf comment = "/*+Foo()Bar(x)*/";
        TStringBuf expected = R"raw("Foo":{})raw";
        CheckParse(comment, expected);
    }
}