summaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/docs/markdown_ut.cpp
blob: 8cafa2f22f12cf3212d7c7b5761ff7983446bc96 (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
#include "markdown.h"

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

using namespace NYql::NDocs;

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;
```
)";
        TMarkdownPage page = ParseMarkdownPage(markdown);

        UNIT_ASSERT_VALUES_EQUAL(page.SectionsByAnchor.size(), 2);

        const auto& coelcese = page.SectionsByAnchor["coalesce"];
        UNIT_ASSERT_STRING_CONTAINS(coelcese.Header.Content, "COALESCE");
        UNIT_ASSERT_VALUES_EQUAL(coelcese.Header.Anchor, "coalesce");
        UNIT_ASSERT_STRING_CONTAINS(coelcese.Body, "Iterates");
        UNIT_ASSERT_STRING_CONTAINS(coelcese.Body, "COALESCE");
        UNIT_ASSERT_GE(Count(coelcese.Body, '\n'), 5);

        const auto& random = page.SectionsByAnchor["random"];
        UNIT_ASSERT_STRING_CONTAINS(random.Header.Content, "Random");
        UNIT_ASSERT_VALUES_EQUAL(random.Header.Anchor, "random");
        UNIT_ASSERT_STRING_CONTAINS(random.Body, "Generates");
        UNIT_ASSERT_STRING_CONTAINS(random.Body, "Random");
        UNIT_ASSERT_GE(Count(random.Body, '\n'), 5);
    }

} // Y_UNIT_TEST_SUITE(MarkdownParserTests)