aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/docs/markdown_ut.cpp
blob: 15d69ed9e5dfceb5ec204be35fe5fca431a94e0c (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "markdown.h"

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

using namespace NSQLComplete;

Y_UNIT_TEST_SUITE(MarkdownParserTests) {

    Y_UNIT_TEST(ParseMarkdown) {
        TString markdown = R"(
# Basic built-in functions

Below are the general-purpose functions.

## COALESCE {#coalesce}

Iterates through the arguments from left to right.

#### Examples

```yql
SELECT COALESCE(
  maybe_empty_column,
  "it's empty!"
) FROM my_table;
```

## Random... {#random}

Generates a pseudorandom number:

* `Random()`: A floating point number (Double) from 0 to 1.
* `RandomNumber()`: An integer from the complete Uint64 range.
* `RandomUuid()`: [Uuid version 4](https://tools.ietf.org/html/rfc4122#section-4.4).

#### Signatures

```yql
Random(T1[, T2, ...])->Double
RandomNumber(T1[, T2, ...])->Uint64
RandomUuid(T1[, T2, ...])->Uuid
```

No arguments are used for random number generation.

#### Examples

```yql
SELECT
    Random(key) -- [0, 1)
FROM my_table;
```
)";
        TVector<TMarkdownSection> sections;

        TStringStream input(markdown);
        ParseMarkdown(input, [&](TMarkdownSection&& section) {
            sections.emplace_back(std::move(section));
        });

        UNIT_ASSERT_VALUES_EQUAL(sections.size(), 2);

        UNIT_ASSERT_STRING_CONTAINS(sections[0].Header.Content, "COALESCE");
        UNIT_ASSERT_VALUES_EQUAL(sections[0].Header.Anchor, "#coalesce");
        UNIT_ASSERT_STRING_CONTAINS(sections[0].Body, "Iterates");
        UNIT_ASSERT_STRING_CONTAINS(sections[0].Body, "COALESCE");
        UNIT_ASSERT_GE(Count(sections[0].Body, '\n'), 5);

        UNIT_ASSERT_STRING_CONTAINS(sections[1].Header.Content, "Random");
        UNIT_ASSERT_VALUES_EQUAL(sections[1].Header.Anchor, "#random");
        UNIT_ASSERT_STRING_CONTAINS(sections[1].Body, "Generates");
        UNIT_ASSERT_STRING_CONTAINS(sections[1].Body, "Random");
        UNIT_ASSERT_GE(Count(sections[1].Body, '\n'), 5);
    }

} // Y_UNIT_TEST_SUITE(MarkdownParserTests)