about summary refs log tree commit diff
path: root/tests/rustdoc-gui/docblock-code-block-line-number.goml
blob: fed916ac246758468222c9d3d27691666729fb36 (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Checks that the setting "line numbers" is working as expected.
include: "utils.goml"
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"

// We check that without this setting, there is no line number displayed.
assert-false: "pre.example-line-numbers"

// All corners should be rounded.
assert-css: (
    ".example-wrap .rust",
    {
        "border-top-left-radius": "6px",
        "border-bottom-left-radius": "6px",
        "border-top-right-radius": "6px",
        "border-bottom-right-radius": "6px",
    },
    ALL,
)

// We set the setting to show the line numbers on code examples.
set-local-storage: {"rustdoc-line-numbers": "true"}
reload:
// We wait for the line numbers to be added into the DOM by the JS...
wait-for: "pre.example-line-numbers"

// Otherwise, we can't check text color
show-text: true

// Let's now check some CSS properties...
define-function: (
    "check-colors",
    [theme, color],
    block {
        // Page will be reloaded in "switch-theme".
        call-function: ("switch-theme", {"theme": |theme|})
        // If the test didn't fail, it means that it was found!
        assert-css: (
            "pre.example-line-numbers",
            {
                "color": |color|,
                "margin": "0px",
                "padding-top": "14px",
                "padding-bottom": "14px",
                "padding-left": "8px",
                "padding-right": "2px",
                "text-align": "right",
                // There should not be a radius on the right of the line numbers.
                "border-top-left-radius": "6px",
                "border-bottom-left-radius": "6px",
                "border-top-right-radius": "0px",
                "border-bottom-right-radius": "0px",
            },
            ALL,
        )
        // There should not be a radius on the left of the line numbers.
        assert-css: ("pre.example-line-numbers + .rust", {
            "border-top-left-radius": "0px",
            "border-bottom-left-radius": "0px",
            "border-top-right-radius": "6px",
            "border-bottom-right-radius": "6px",
        })
    },
)
call-function: ("check-colors", {
    "theme": "ayu",
    "color": "#5c6773",
})
call-function: ("check-colors", {
    "theme": "dark",
    "color": "#3b91e2",
})
call-function: ("check-colors", {
    "theme": "light",
    "color": "#c67e2d",
})

// The first code block has two lines so let's check its `<pre>` elements lists both of them.
assert-text: ("pre.example-line-numbers", "1\n2")

// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
// and make sure it goes away.

// First, open the settings menu.
click: "#settings-menu"
wait-for: "#settings"
assert-css: ("#settings", {"display": "block"})

// Then, click the toggle button.
click: "input#line-numbers"
wait-for: 100 // wait-for-false does not exist
assert-false: "pre.example-line-numbers"
assert-local-storage: {"rustdoc-line-numbers": "false" }

// Check that the rounded corners are back.
assert-css: (
    ".example-wrap .rust",
    {
        "border-top-left-radius": "6px",
        "border-bottom-left-radius": "6px",
        "border-top-right-radius": "6px",
        "border-bottom-right-radius": "6px",
    },
    ALL,
)

// Finally, turn it on again.
click: "input#line-numbers"
wait-for: "pre.example-line-numbers"
assert-local-storage: {"rustdoc-line-numbers": "true" }

// Same check with scraped examples line numbers.
go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"

assert-css: (
    ".scraped-example .src-line-numbers > pre",
    {
        // There should not be a radius on the right of the line numbers.
        "border-top-left-radius": "6px",
        "border-bottom-left-radius": "6px",
        "border-top-right-radius": "0px",
        "border-bottom-right-radius": "0px",
    },
    ALL,
)
assert-css: (
    ".scraped-example .src-line-numbers",
    {
        // There should not be a radius on the right of the line numbers.
        "border-top-left-radius": "6px",
        "border-bottom-left-radius": "6px",
        "border-top-right-radius": "0px",
        "border-bottom-right-radius": "0px",
    },
    ALL,
)
assert-css: (
    ".scraped-example .rust",
    {
        // There should not be a radius on the left of the code.
        "border-top-left-radius": "0px",
        "border-bottom-left-radius": "0px",
        "border-top-right-radius": "6px",
        "border-bottom-right-radius": "6px",
    },
    ALL,
)

// Checking line numbers on scraped code examples.
go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"

define-function: (
    "check-padding",
    [path, padding_bottom],
    block {
        assert-css: (|path| + " .src-line-numbers", {
            "padding-top": "0px",
            "padding-bottom": "0px",
            "padding-left": "0px",
            "padding-right": "0px",
        })
        assert-css: (|path| + " .src-line-numbers > pre", {
            "padding-top": "14px",
            "padding-bottom": |padding_bottom|,
            "padding-left": "0px",
            "padding-right": "0px",
        })
        assert-css: (|path| + " .src-line-numbers > pre > span", {
            "padding-top": "0px",
            "padding-bottom": "0px",
            "padding-left": "8px",
            "padding-right": "8px",
        })
    },
)

call-function: ("check-padding", {
    "path": ".scraped-example .example-wrap",
    "padding_bottom": "0px",
})

move-cursor-to: ".scraped-example .example-wrap .rust"
wait-for: ".scraped-example .example-wrap .button-holder .expand"
click: ".scraped-example .example-wrap .button-holder .expand"
wait-for: ".scraped-example.expanded"

call-function: ("check-padding", {
    "path": ".scraped-example.expanded .example-wrap",
    "padding_bottom": "14px",
})

// Now checking the line numbers in the source code page.
click: ".src"
assert-css: (".src-line-numbers", {
    "padding-top": "20px",
    "padding-bottom": "20px",
    "padding-left": "4px",
    "padding-right": "0px",
})
assert-css: (".src-line-numbers > a", {
    "padding-top": "0px",
    "padding-bottom": "0px",
    "padding-left": "8px",
    "padding-right": "8px",
})