blob: 07bb33c708ff971bf18b9e186fd827ff5f460b6a (
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
|
/*
* SonarQube
* Copyright (C) 2009-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.markdown;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class MarkdownTest {
@Test
public void shouldDecorateAbsoluteUrl() {
assertThat(Markdown.convertToHtml("http://google.com"))
.isEqualTo("<a href=\"http://google.com\" target=\"_blank\" rel=\"noopener noreferrer\">http://google.com</a>");
}
@Test
public void shouldDecorateRelativeUrl() {
assertThat(Markdown.convertToHtml("[Google](/google/com)"))
.isEqualTo("<a href=\"/google/com\">Google</a>");
}
@Test
public void shouldDecorateDocumentedLink() {
assertThat(Markdown.convertToHtml("For more details, please [check online documentation](http://docs.sonarqube.org/display/SONAR)."))
.isEqualTo("For more details, please <a href=\"http://docs.sonarqube.org/display/SONAR\" target=\"_blank\" rel=\"noopener noreferrer\">check online documentation</a>.");
}
@Test
public void shouldDecorateEndOfLine() {
assertThat(Markdown.convertToHtml("1\r2\r\n3\n")).isEqualTo("1<br/>2<br/>3<br/>");
}
@Test
public void shouldDecorateUnorderedList() {
assertThat(Markdown.convertToHtml(" * one\r* two\r\n* three\n * \n *five"))
.isEqualTo("<ul><li>one</li>\r<li>two</li>\r\n<li>three</li>\n<li> </li>\n</ul> *five");
assertThat(Markdown.convertToHtml(" * one\r* two")).isEqualTo("<ul><li>one</li>\r<li>two</li></ul>");
assertThat(Markdown.convertToHtml("* \r*")).isEqualTo("<ul><li> </li>\r</ul>*");
}
@Test
public void shouldDecorateOrderedList() {
assertThat(Markdown.convertToHtml(" 1. one\r1. two\r\n1. three\n 1. \n 1.five"))
.isEqualTo("<ol><li>one</li>\r<li>two</li>\r\n<li>three</li>\n<li> </li>\n</ol> 1.five");
assertThat(Markdown.convertToHtml(" 1. one\r1. two")).isEqualTo("<ol><li>one</li>\r<li>two</li></ol>");
assertThat(Markdown.convertToHtml("1. \r1.")).isEqualTo("<ol><li> </li>\r</ol>1.");
}
@Test
public void shouldDecorateHeadings() {
assertThat(Markdown.convertToHtml(" = Top\r== Sub\r\n=== Sub sub\n ==== \n 1.five"))
.isEqualTo("<h1>Top</h1><h2>Sub</h2><h3>Sub sub</h3><h4></h4> 1.five");
}
@Test
public void shouldDecorateBlockquote() {
assertThat(Markdown.convertToHtml("> Yesterday <br/> it worked\n> Today it is not working\r\n> Software is like that\r"))
.isEqualTo("<blockquote>Yesterday <br/> it worked<br/>\nToday it is not working<br/>\r\nSoftware is like that<br/>\r</blockquote>");
assertThat(Markdown.convertToHtml("HTML elements should <em>not</em> be quoted!"))
.isEqualTo("HTML elements should <em>not</em> be quoted!");
}
@Test
public void shouldDecorateMixedOrderedAndUnorderedList() {
assertThat(Markdown.convertToHtml(" 1. one\r* two\r\n1. three\n * \n 1.five"))
.isEqualTo("<ol><li>one</li>\r</ol><ul><li>two</li>\r\n</ul><ol><li>three</li>\n</ol><ul><li> </li>\n</ul> 1.five");
}
@Test
public void shouldDecorateCode() {
assertThat(Markdown.convertToHtml("This is a ``line of code``")).isEqualTo("This is a <code>line of code</code>");
assertThat(Markdown.convertToHtml("This is not a ``line of code")).isEqualTo("This is not a ``line of code");
}
@Test
public void shouldDecorateMultipleLineCode() {
assertThat(Markdown.convertToHtml("This is a ``\nline of code\nOn multiple lines\n``")).isEqualTo("This is a <pre><code>line of code\nOn multiple lines</code></pre>");
assertThat(Markdown.convertToHtml("This is not a ``line of code\nOn multiple lines``")).isEqualTo("This is not a ``line of code<br/>On multiple lines``");
assertThat(Markdown.convertToHtml("This is not a ``line of code\nOn multiple lines")).isEqualTo("This is not a ``line of code<br/>On multiple lines");
}
@Test
public void shouldDecorateMultipleLineCodeWithLanguageSpecified() {
assertThat(Markdown.convertToHtml("This is a ``java\nline of code\nOn multiple lines\n``")).isEqualTo("This is a <pre lang=\"java\"><code>line of code\nOn multiple lines</code></pre>");
assertThat(Markdown.convertToHtml("This is not a ``java line of code\nOn multiple lines``")).isEqualTo("This is not a ``java line of code<br/>On multiple lines``");
assertThat(Markdown.convertToHtml("This is not a ``java \nline of code\nOn multiple lines``")).isEqualTo("This is not a ``java <br/>line of code<br/>On multiple lines``");
}
@Test
public void shouldEmphasisText() {
assertThat(Markdown.convertToHtml("This is *Sparta !!!*")).isEqualTo("This is <strong>Sparta !!!</strong>");
assertThat(Markdown.convertToHtml("This is *A*")).isEqualTo("This is <strong>A</strong>");
assertThat(Markdown.convertToHtml("This should not be * \n emphasized")).isEqualTo("This should not be * <br/> emphasized");
assertThat(Markdown.convertToHtml("This is *very* very *important*")).isEqualTo("This is <strong>very</strong> very <strong>important</strong>");
assertThat(Markdown.convertToHtml("Not * emphasized * because of whitespaces")).isEqualTo("Not * emphasized * because of whitespaces");
assertThat(Markdown.convertToHtml("Not *emphasized * because of whitespace")).isEqualTo("Not *emphasized * because of whitespace");
assertThat(Markdown.convertToHtml("Not * emphasized* because of whitespace")).isEqualTo("Not * emphasized* because of whitespace");
assertThat(Markdown.convertToHtml("emphasized*inside*word")).isEqualTo("emphasized<strong>inside</strong>word");
assertThat(Markdown.convertToHtml("*Emphasize many words*")).isEqualTo("<strong>Emphasize many words</strong>");
}
@Test
public void shouldNotChangeAnythingInTheText() {
assertThat(Markdown.convertToHtml("My text is $123 ''")).isEqualTo("My text is $123 ''");
}
}
|