/* * SonarQube * Copyright (C) 2009-2023 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("http://google.com"); } @Test public void shouldDecorateRelativeUrl() { assertThat(Markdown.convertToHtml("[Google](/google/com)")) .isEqualTo("Google"); } @Test public void shouldDecorateDocumentedLink() { assertThat(Markdown.convertToHtml("For more details, please [check online documentation](http://docs.sonarsource.com/sonarqube/display/SONAR).")) .isEqualTo("For more details, please check online documentation."); } @Test public void shouldDecorateEndOfLine() { assertThat(Markdown.convertToHtml("1\r2\r\n3\n")).isEqualTo("1
2
3
"); } @Test public void shouldDecorateUnorderedList() { assertThat(Markdown.convertToHtml(" * one\r* two\r\n* three\n * \n *five")) .isEqualTo(" *five"); assertThat(Markdown.convertToHtml(" * one\r* two")).isEqualTo(""); assertThat(Markdown.convertToHtml("* \r*")).isEqualTo("*"); } @Test public void shouldDecorateOrderedList() { assertThat(Markdown.convertToHtml(" 1. one\r1. two\r\n1. three\n 1. \n 1.five")) .isEqualTo("
  1. one
  2. \r
  3. two
  4. \r\n
  5. three
  6. \n
  7. \n
1.five"); assertThat(Markdown.convertToHtml(" 1. one\r1. two")).isEqualTo("
  1. one
  2. \r
  3. two
"); assertThat(Markdown.convertToHtml("1. \r1.")).isEqualTo("
  1. \r
1."); } @Test public void shouldDecorateHeadings() { assertThat(Markdown.convertToHtml(" = Top\r== Sub\r\n=== Sub sub\n ==== \n ===== five\n============ max")) .isEqualTo("

Top

Sub

Sub sub

five
max
"); } @Test public void shouldDecorateBlockquote() { assertThat(Markdown.convertToHtml("> Yesterday
it worked\n> Today it is not working\r\n> Software is like that\r")) .isEqualTo("
Yesterday <br/> it worked
\nToday it is not working
\r\nSoftware is like that
\r
"); assertThat(Markdown.convertToHtml("HTML elements should not 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("
  1. one
  2. \r
  1. three
  2. \n
1.five"); } @Test public void shouldDecorateCode() { assertThat(Markdown.convertToHtml("This is a ``line of code``")).isEqualTo("This is a line of 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
line of code\nOn multiple lines
"); assertThat(Markdown.convertToHtml("This is not a ``line of code\nOn multiple lines``")).isEqualTo("This is not a ``line of code
On multiple lines``"); assertThat(Markdown.convertToHtml("This is not a ``line of code\nOn multiple lines")).isEqualTo("This is not a ``line of code
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
line of code\nOn multiple lines
"); assertThat(Markdown.convertToHtml("This is not a ``java line of code\nOn multiple lines``")).isEqualTo("This is not a ``java line of code
On multiple lines``"); assertThat(Markdown.convertToHtml("This is not a ``java \nline of code\nOn multiple lines``")).isEqualTo("This is not a ``java
line of code
On multiple lines``"); } @Test public void shouldEmphasisText() { assertThat(Markdown.convertToHtml("This is *Sparta !!!*")).isEqualTo("This is Sparta !!!"); assertThat(Markdown.convertToHtml("This is *A*")).isEqualTo("This is A"); assertThat(Markdown.convertToHtml("This should not be * \n emphasized")).isEqualTo("This should not be *
emphasized"); assertThat(Markdown.convertToHtml("This is *very* very *important*")).isEqualTo("This is very very important"); 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("emphasizedinsideword"); assertThat(Markdown.convertToHtml("*Emphasize many words*")).isEqualTo("Emphasize many words"); } @Test public void shouldNotChangeAnythingInTheText() { assertThat(Markdown.convertToHtml("My text is $123 ''")).isEqualTo("My text is $123 ''"); } }