Skip to content

Commit

Permalink
Update IT
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Feb 11, 2024
1 parent a575937 commit d21b130
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,16 @@ public class HelloWorld {
. Protons
. Electrons
. Neutrons

==== Description list

Operating Systems::
Linux:::
. Fedora
* Desktop
. Ubuntu
* Desktop
* Server
BSD:::
. FreeBSD
. NetBSD
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ new HtmlAsserter(htmlContent).with { asserter ->
asserter.containsSectionTitle("Ordered list", 4)
asserter.containsOrderedList("Protons", "Electrons", "Neutrons")

asserter.containsSectionTitle("Description list", 4)
asserter.descriptionListTerm("Operating Systems")
asserter.descriptionListTerm("Linux")
asserter.contains("<li>Fedora")
asserter.containsUnorderedList("Desktop")
asserter.contains("<li>Ubuntu")
asserter.containsUnorderedList("Desktop", "Server")
asserter.descriptionListTerm("BSD")
asserter.containsOrderedList("FreeBSD", "NetBSD")
}

String strong(String text) {
Expand Down Expand Up @@ -111,6 +120,11 @@ class HtmlAsserter {
return content.indexOf(value, lastAssertionCursor)
}

void contains(String text) {
def found = find(text)
assertFound("HTML text", text, found)
}

void containsDocumentTitle(String value) {
def found = find("<h1>$value</h1>")
assertFound("Document Title", value, found)
Expand Down Expand Up @@ -160,6 +174,11 @@ class HtmlAsserter {
assertFound("Ordered list", values.join(','), found)
}

void descriptionListTerm(String term) {
def found = find("<dt>${term}</dt>")
assertFound("Description list", term, found)
}

void containsTable(int columns, int rows, List<String> headers, String caption) {
def start = content.indexOf("<table", lastAssertionCursor)
def end = content.indexOf("</table>", lastAssertionCursor) + "</table>".length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.asciidoctor.maven.site.ast.processors.test.Html.LIST_STYLE_TYPE_DECIMAL;
import static org.asciidoctor.maven.site.ast.processors.test.Html.dd;
import static org.asciidoctor.maven.site.ast.processors.test.Html.dt;
import static org.asciidoctor.maven.site.ast.processors.test.Html.italics;
import static org.asciidoctor.maven.site.ast.processors.test.Html.li;
import static org.asciidoctor.maven.site.ast.processors.test.Html.monospace;
import static org.asciidoctor.maven.site.ast.processors.test.Html.ol;
import static org.asciidoctor.maven.site.ast.processors.test.Html.strong;
import static org.asciidoctor.maven.site.ast.processors.test.Html.ul;
import static org.asciidoctor.maven.site.ast.processors.test.StringTestUtils.clean;
import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -48,10 +57,8 @@ void should_convert_simple_list() {
// TODO: document We are not adding additional <div> / <p>, unlike Asciidoctor
assertThat(html)
.isEqualTo("<dl>" +
"<dt>CPU</dt>" +
"<dd>The brain of the computer.</dd>" +
"<dt>RAM</dt>" +
"<dd>Temporarily stores information the CPU uses during operation.</dd>" +
dt("CPU") + dd("The brain of the computer.") +
dt("RAM") + dd("Temporarily stores information the CPU uses during operation.") +
"</dl>");
}

Expand All @@ -63,10 +70,8 @@ void should_convert_simple_list_with_formatting() {

assertThat(html)
.isEqualTo("<dl>" +
"<dt><strong>CPU</strong></dt>" +
"<dd>The brain of <em>the computer</em>.</dd>" +
"<dt><code>RAM</code></dt>" +
"<dd><strong>Temporarily stores information</strong> the CPU uses during operation.</dd>" +
dt(strong("CPU")) + dd("The brain of " + italics("the computer") + ".") +
dt(monospace("RAM")) + dd(strong("Temporarily stores information") + " the CPU uses during operation.") +
"</dl>");
}

Expand All @@ -78,18 +83,13 @@ void should_convert_simple_list_with_nested_list() {

assertThat(html)
.isEqualTo("<dl>" +
"<dt>Dairy</dt>" +
dt("Dairy") +
"<dd>" +
"<ul>" +
"<li>Milk</li>" +
"<li>Eggs</li>" +
"</ul>" +
ul(li("Milk"), li("Eggs")) +
"</dd>" +
"<dt>Bakery</dt>" +
dt("Bakery") +
"<dd>" +
"<ol style=\"list-style-type: decimal\">" +
"<li>Bread</li>" +
"</ol>" +
ol(LIST_STYLE_TYPE_DECIMAL, li("Bread")) +
"</dd>" +
"</dl>"
);
Expand All @@ -103,18 +103,23 @@ void should_convert_nested_description_lists() {

assertThat(html)
.isEqualTo("<dl>" +
"<dt>Dairy</dt>" +
dt("Operating Systems") +
"<dd>" +
"<ul>" +
"<li>Milk</li>" +
"<li>Eggs</li>" +
"</ul>" +
"<dl>" +

dt("Linux") +
"<dd>" +
ol(LIST_STYLE_TYPE_DECIMAL,
li("Fedora" + ul(li("Desktop"))),
li("Ubuntu" + ul(li("Desktop"), li("Server")))
) +
"</dd>" +
"<dt>Bakery</dt>" +
dt("BSD") +
"<dd>" +
"<ol style=\"list-style-type: decimal\">" +
"<li>Bread</li>" +
"</ol>" +
ol(LIST_STYLE_TYPE_DECIMAL, li("FreeBSD"), li("NetBSD")) +
"</dd>" +
"</dl>" +

"</dd>" +
"</dl>"
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.asciidoctor.maven.site.ast.processors.test;

public class Html {

public static final String LIST_STYLE_TYPE_DECIMAL = "list-style-type: decimal";

public static String strong(String text) {
return htmlElement("strong", text);
}

public static String italics(String text) {
return htmlElement("em", text);
}

public static String monospace(String text) {
return htmlElement("code", text);
}

public static String ul(String... elements) {
return htmlElement("ul", String.join("", elements));
}

public static String ol(String style, String... elements) {
return htmlElement("ol", style, String.join("", elements));
}

public static String li(String text) {
return htmlElement("li", text);
}

public static String dt(String text) {
return htmlElement("dt", text);
}

public static String dd(String text) {
return htmlElement("dd", text);
}

static String htmlElement(String element, String text) {
return htmlElement(element, null, text);
}

static String htmlElement(String element, String style, String text) {
if (style == null) {
return String.format("<%1$s>%2$s</%1$s>", element, text).trim();
}
return String.format("<%1$s style=\"%3$s\">%2$s</%1$s>", element, text, style).trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ This module is still under development, here is a summary of supported features:
** Ordered, only arabic numerals
** Description lists, with nested ordered, unordered and description lists
** Formatted text in list items
+
NOTE: Unlike in Asciidoctor lists, descriptions are not surrounded by `<p>` and list themselves are not surrounded by `<div>` elements.

* Code blocks with source-highlighting using https://maven.apache.org/skins/maven-fluido-skin/#source-code-line-numbers[Fluido Skin Pretiffy].
** Support for numbered lines with `linenums`
Expand Down

0 comments on commit d21b130

Please sign in to comment.