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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include "global.h"
#include <library/cpp/testing/unittest/registar.h>
using namespace NSQLComplete;
Y_UNIT_TEST_SUITE(GlobalAnalysisTests) {
Y_UNIT_TEST(TopLevelNamesCollected) {
IGlobalAnalysis::TPtr global = MakeGlobalAnalysis();
TString query = R"(
DECLARE $cluster_name AS String;
IMPORT math SYMBOLS $sqrt, $pow;
$sqrt = 0;
DEFINE ACTION $hello_world($name, $suffix?) AS
$name = $name ?? ($suffix ?? "world");
SELECT "Hello, " || $name || "!";
END DEFINE;
$first, $second, $_ = AsTuple(1, 2, 3);
)";
TGlobalContext ctx = global->Analyze({query}, {});
Sort(ctx.Names);
TVector<TString> expected = {
"cluster_name",
"first",
"hello_world",
"pow",
"second",
"sqrt",
};
UNIT_ASSERT_VALUES_EQUAL(ctx.Names, expected);
}
Y_UNIT_TEST(LocalNamesCollected) {
IGlobalAnalysis::TPtr global = MakeGlobalAnalysis();
TString query = R"(
DEFINE ACTION $sum($x, $y) AS
$acc = 0;
EVALUATE FOR $i IN AsList($x, $y) DO BEGIN
$plus = ($a, $b) -> (#);
$acc = $plus($acc, $i);
END DO;
END DEFINE;
)";
TCompletionInput input = SharpedInput(query);
TGlobalContext ctx = global->Analyze(input, {});
Sort(ctx.Names);
TVector<TString> expected = {
"a",
"acc",
"b",
"i",
"plus",
"sum",
"x",
"y",
};
UNIT_ASSERT_VALUES_EQUAL(ctx.Names, expected);
}
} // Y_UNIT_TEST_SUITE(GlobalAnalysisTests)
|