summaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/docs/markdown_ut.cpp
blob: 45e45e645a52996999f4c1a7af15a5ba0268c888 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#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(NestedSections) {
        TString markdown = R"(
# Section 1 {#s1}
Section 1 Text.
## Subsection 1 {#s1s1}
Subsection 1.1 Text.
## Subsection 2 {#s1s2}
Subsection 1.2 Text.
# Section 2 {#s2}
Section 2 Text.
## Subsection 1 {#s2s1}
Subsection 2.1 Text.
## Subsection 2 {#s2s2}
Subsection 2.2 Text.
### Subsubsection 1 {#s2s2s1}
Subsection 2.2.1 Text.
# Section 3 {#s3}
Section 3 Text.
)";
        TMarkdownPage page = ParseMarkdownPage(markdown);
        {
            const TMarkdownSection& section = page.SectionsByAnchor["s1s2"];
            UNIT_ASSERT_STRING_CONTAINS(section.Body, "Subsection 1.2 Text.");
            UNIT_ASSERT_C(!section.Body.Contains("Section 1 Text."), section.Body);
            UNIT_ASSERT_C(!section.Body.Contains("Section 2 Text."), section.Body);
            UNIT_ASSERT_C(!section.Body.Contains("Section 3 Text."), section.Body);
        }
        {
            const TMarkdownSection& section = page.SectionsByAnchor["s2s2s1"];
            UNIT_ASSERT_STRING_CONTAINS(section.Body, "Subsection 2.2.1 Text.");
            UNIT_ASSERT_C(!section.Body.Contains("Section 3 Text."), section.Body);
        }
    }

} // Y_UNIT_TEST_SUITE(MarkdownParserTests)