forked from domaindrivendev/Swashbuckle.AspNetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlCommentsTextHelperTests.cs
More file actions
279 lines (235 loc) · 7.92 KB
/
XmlCommentsTextHelperTests.cs
File metadata and controls
279 lines (235 loc) · 7.92 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using Xunit;
namespace Swashbuckle.AspNetCore.SwaggerGen.Test
{
/// NOTE: Whitespace in these tests is significant and uses a combination of {tabs} and {spaces}
/// You should toggle "View White Space" to "on".
public class XmlCommentsTextHelperTests
{
[Fact]
public void Humanize_TrimsWhiteSpaceFromStartAndEnd()
{
var input = @"
A line of text
";
var output = XmlCommentsTextHelper.Humanize(input);
Assert.Equal("A line of text", output, false, true);
}
[Fact]
public void Humanize_TrimsCommonSpaceIndentations()
{
var input = @"
## Heading 1
* list item 1
## Heading 2
POST /api/test
{
""prop1"": {
""name"": ""value""
}
}
";
var output = XmlCommentsTextHelper.Humanize(input);
Assert.Equal(
@"## Heading 1
* list item 1
## Heading 2
POST /api/test
{
""prop1"": {
""name"": ""value""
}
}",
output,
false,
true
);
}
[Fact]
public void Humanize_TrimsCommonTabIndentations()
{
// Common indentation seen in visual studio: {tab}
var input = @"
## Heading 1
A line of text
";
var output = XmlCommentsTextHelper.Humanize(input);
Assert.Equal(
@"## Heading 1
A line of text",
output,
false,
true
);
}
[Fact]
public void Humanize_TrimsCommonSpaceTabIndentations()
{
// Common indentation seen in visual studio: {space}{tab}
var input = @"
## Heading 1
A line of text
";
var output = XmlCommentsTextHelper.Humanize(input);
Assert.Equal(
@"## Heading 1
A line of text",
output,
false,
true
);
}
[Fact]
public void Humanize_DoesNotTrimInconsistentIndentations()
{
var input = @"
Space Indentation Line 1
Space Indentation Line 2
Misplaced Tab Indentation
Space Indentation Line 4
";
var output = XmlCommentsTextHelper.Humanize(input);
Assert.Equal(
@" Space Indentation Line 1
Space Indentation Line 2
Misplaced Tab Indentation
Space Indentation Line 4",
output, false, true);
}
[Theory]
[InlineData(@"Returns a <see cref=""T:Product""/>", "Returns a Product")]
[InlineData(@"<paramref name=""param1"" /> does something", "param1 does something")]
[InlineData("<c>DoWork</c> is a method in <c>TestClass</c>.", "`DoWork` is a method in `TestClass`.")]
[InlineData("<code>DoWork</code> is a method in <code>\nTestClass\n</code>.", "```DoWork``` is a method in ```\nTestClass\n```.")]
[InlineData("<para>This is a paragraph</para>.", "\r\nThis is a paragraph.")]
[InlineData("<para> This is a paragraph </para>.", "\r\nThis is a paragraph.")]
[InlineData("GET /Todo?iscomplete=true&owner=mike", "GET /Todo?iscomplete=true&owner=mike")]
[InlineData(@"Returns a <see langword=""null""/> item.", "Returns a null item.")]
[InlineData(@"<see href=""https://www.iso.org/iso-4217-currency-codes.html"">ISO currency code</see>", "[ISO currency code](https://www.iso.org/iso-4217-currency-codes.html)")]
[InlineData("First line.<br />Second line.<br/>Third line.<br>Fourth line.", "First line.\r\nSecond line.\r\nThird line.\r\nFourth line.")]
[InlineData("<para> one </para><para> two </para>","\r\none\r\ntwo")]
public void Humanize_HumanizesInlineTags(
string input,
string expectedOutput)
{
var output = XmlCommentsTextHelper.Humanize(input);
Assert.Equal(expectedOutput, output, false, true);
}
[Theory]
[InlineData("\r\n")]
[InlineData("\n")]
[InlineData(null)]
public void Humanize_MultilineBrTag_SpecificEol(string xmlCommentEndOfLine)
{
const string input = @"
This is a paragraph.
<br>
A parameter after br tag.";
var output = XmlCommentsTextHelper.Humanize(input, xmlCommentEndOfLine);
var expected = string.Join(XmlCommentsTextHelper.EndOfLine(xmlCommentEndOfLine),
[
"This is a paragraph.",
"",
"",
"A parameter after br tag."
]);
Assert.Equal(expected, output, false, ignoreLineEndingDifferences: false);
}
[Fact]
public void Humanize_ParaMultiLineTags()
{
const string input = @"
<para>
This is a paragraph.
MultiLined.
</para>
<para> This is a paragraph </para>.";
var output = XmlCommentsTextHelper.Humanize(input);
Assert.Equal("\r\nThis is a paragraph.\r\n MultiLined.\r\n\r\nThis is a paragraph.", output, false, true);
}
[Fact]
public void Humanize_CodeMultiLineTag()
{
const string input = @"
<code>
{
""Prop1"":1,
""Prop2"":[]
}
</code>";
var output = XmlCommentsTextHelper.Humanize(input);
var expected = string.Join(XmlCommentsTextHelper.EndOfLine(null),
[
"```",
"{",
" \"Prop1\":1,",
" \"Prop2\":[]",
"}",
"```"
]);
Assert.Equal(expected, output);
}
[Fact]
public void Humanize_CodeMultiLineTag_OnSameLine()
{
const string input = @"
<code>{
""Prop1"":1,
""Prop2"":[]
}
</code>";
var output = XmlCommentsTextHelper.Humanize(input);
var expected = string.Join(XmlCommentsTextHelper.EndOfLine(null),
[
"```",
"{",
" \"Prop1\":1,",
" \"Prop2\":[]",
" }",
"```"
]);
Assert.Equal(expected, output);
}
[Fact]
public void Humanize_CodeInsideParaTag()
{
var input = string.Join(XmlCommentsTextHelper.EndOfLine(null),
[
"<para>Creates a new Answer</para>",
"<para><code><![CDATA[",
"POST /api/answers",
"{",
""" "name": "OnlyYes",""",
""" "label": "Yes",""",
""" "answers": [""",
" {",
""" "answer": "yes""",
" }",
" ]",
"}",
"]]></code></para>",
]);
var output = XmlCommentsTextHelper.Humanize(input);
var expected = string.Join(XmlCommentsTextHelper.EndOfLine(null),
[
"",
"Creates a new Answer",
"",
"```",
"<![CDATA[",
"POST /api/answers",
"{",
""" "name": "OnlyYes",""",
""" "label": "Yes",""",
""" "answers": [""",
" {",
""" "answer": "yes""",
" }",
" ]",
"}",
"]]>",
"```"
]);
Assert.Equal(expected, output);
}
}
}