aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/syntax/cursor_token_context_ut.cpp
blob: 0e275cca3b8cef820eded221d6527cbce003be29 (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
39
40
41
42
43
44
45
46
47
48
49
50
#include "cursor_token_context.h"

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

#include <yql/essentials/sql/v1/lexer/antlr4_pure/lexer.h>
#include <yql/essentials/sql/v1/lexer/lexer.h>

using namespace NSQLComplete;

Y_UNIT_TEST_SUITE(CursorTokenContextTests) {

    NSQLTranslation::ILexer::TPtr MakeLexer() {
        NSQLTranslationV1::TLexers lexers;
        lexers.Antlr4Pure = NSQLTranslationV1::MakeAntlr4PureLexerFactory();
        return NSQLTranslationV1::MakeLexer(
            lexers, /* ansi = */ false, /* antlr4 = */ true,
            NSQLTranslationV1::ELexerFlavor::Pure);
    }

    TCursorTokenContext Context(TString input) {
        auto lexer = MakeLexer();
        TCursorTokenContext context;
        UNIT_ASSERT(GetCursorTokenContext(lexer, SharpedInput(input), context));
        return context;
    }

    Y_UNIT_TEST(Empty) {
        auto context = Context("");
        UNIT_ASSERT(context.Cursor.PrevTokenIndex.Empty());
        UNIT_ASSERT_VALUES_EQUAL(context.Cursor.NextTokenIndex, 0);
        UNIT_ASSERT_VALUES_EQUAL(context.Cursor.Position, 0);
        UNIT_ASSERT(context.Enclosing().Empty());
    }

    Y_UNIT_TEST(Blank) {
        UNIT_ASSERT(Context("# ").Enclosing().Empty());
        UNIT_ASSERT(Context(" #").Enclosing().Empty());
        UNIT_ASSERT(Context(" # ").Enclosing().Empty());
    }

    Y_UNIT_TEST(Enclosing) {
        UNIT_ASSERT(Context("se#").Enclosing().Defined());
        UNIT_ASSERT(Context("#se").Enclosing().Empty());
        UNIT_ASSERT(Context("`se`#").Enclosing().Empty());
        UNIT_ASSERT(Context("#`se`").Enclosing().Empty());
        UNIT_ASSERT(Context("`se`#`se`").Enclosing().Defined());
        UNIT_ASSERT(Context("\"se\"#\"se\"").Enclosing().Empty());
    }

} // Y_UNIT_TEST_SUITE(CursorTokenContextTests)