diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/TagMapper.java b/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/TagMapper.java index 38e36cf411..09f0a51d98 100644 --- a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/TagMapper.java +++ b/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/TagMapper.java @@ -5,11 +5,23 @@ final class TagMapper { private TagMapper() { - // static helper class not intended to be instantiated + // static helper class isn't intended to be instantiated } - static String mapTag(final Tag tag) { + static String toHumanReadableLabel(final Tag tag) { final String cssClassOrType = tag.getCssClass() == null ? "jg-tag-" + tag.getType() : tag.getCssClass(); - return "[." + cssClassOrType + "]#" + tag.toString() + "#"; + return "[." + cssClassOrType + "]#" + tag + "#"; + } + + static String toAsciiDocStartTag(final Tag tag) { + return "// tag::" + toAsciiDocTagName(tag) + "[]"; + } + + static String toAsciiDocEndTag(final Tag tag) { + return "// end::" + toAsciiDocTagName(tag) + "[]"; + } + + private static String toAsciiDocTagName(final Tag tag) { + return tag.toIdString(); } } diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java b/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java index dc14e53cd7..11db56952e 100644 --- a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java +++ b/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java @@ -1,88 +1,150 @@ package com.tngtech.jgiven.report.asciidoc; +import static org.assertj.core.api.Assertions.assertThat; + import com.tngtech.jgiven.report.model.Tag; -import java.util.List; -import org.assertj.core.api.Assertions; import org.junit.Test; +import java.util.List; + public class TagMapperTest { @Test - public void map_simple_tag() { + public void simple_tag_to_label() { // given final Tag tag = new Tag("com.tngtech.jgiven.tags.Feature"); tag.setType("Feature"); // when - final String snippet = TagMapper.mapTag(tag); + final String snippet = TagMapper.toHumanReadableLabel(tag); // then - Assertions.assertThat(snippet).isEqualTo("[.jg-tag-Feature]#Feature#"); + assertThat(snippet).isEqualTo("[.jg-tag-Feature]#Feature#"); } @Test - public void map_simple_tag_with_name() { - // given - final Tag tag = new Tag("com.tngtech.jgiven.tags.Priority", "Core Features", null); - tag.setType("FeatureCore"); - - // when - final String snippet = TagMapper.mapTag(tag); - - // then - Assertions.assertThat(snippet).isEqualTo("[.jg-tag-FeatureCore]#Core Features#"); - } - - @Test - public void map_simple_tag_with_single_value() { + public void single_value_tag_to_label() { // given final Tag tag = new Tag("com.tngtech.jgiven.tags.Story", "ACME-1337"); tag.setType("Story"); // when - final String snippet = TagMapper.mapTag(tag); + final String snippet = TagMapper.toHumanReadableLabel(tag); // then - Assertions.assertThat(snippet).isEqualTo("[.jg-tag-Story]#ACME-1337#"); + assertThat(snippet).isEqualTo("[.jg-tag-Story]#ACME-1337#"); } @Test - public void map_combined_tag_with_single_value() { + public void single_value_tag_with_type_to_label() { // given final Tag tag = new Tag("com.tngtech.jgiven.tags.Issue", "#1337"); tag.setType("Issue"); tag.setPrependType(true); // when - final String snippet = TagMapper.mapTag(tag); + final String snippet = TagMapper.toHumanReadableLabel(tag); // then - Assertions.assertThat(snippet).isEqualTo("[.jg-tag-Issue]#Issue-#1337#"); + assertThat(snippet).isEqualTo("[.jg-tag-Issue]#Issue-#1337#"); } @Test - public void map_simple_tag_with_multiple_values() { + public void multiple_value_tag_to_label() { // given final Tag tag = new Tag("com.tngtech.jgiven.tags.Story", List.of("ACME-1337", "ACME-4221")); tag.setType("Story"); // when - final String snippet = TagMapper.mapTag(tag); + final String snippet = TagMapper.toHumanReadableLabel(tag); // then - Assertions.assertThat(snippet).isEqualTo("[.jg-tag-Story]#ACME-1337, ACME-4221#"); + assertThat(snippet).isEqualTo("[.jg-tag-Story]#ACME-1337, ACME-4221#"); } @Test - public void map_simple_tag_with_css_class() { + public void tag_with_css_class_to_label() { // given final Tag tag = new Tag("com.tngtech.jgiven.tags.Priority", "1"); tag.setType("Priority"); tag.setCssClass("hidden"); // when - final String snippet = TagMapper.mapTag(tag); + final String snippet = TagMapper.toHumanReadableLabel(tag); + + // then + assertThat(snippet).isEqualTo("[.hidden]#1#"); + } + + @Test + public void tag_with_name_to_label() { + // given + final Tag tag = new Tag("com.tngtech.jgiven.tags.FeatureCore", "Core Features", null); + tag.setType("FeatureCore"); + + // when + final String snippet = TagMapper.toHumanReadableLabel(tag); + + // then + assertThat(snippet).isEqualTo("[.jg-tag-FeatureCore]#Core Features#"); + } + + @Test + public void simple_tag_to_AsciiDoc_tag() { + // given + final Tag tag = new Tag("com.tngtech.jgiven.tags.Feature"); + tag.setType("Feature"); + + // when + final String startSnippet = TagMapper.toAsciiDocStartTag(tag); + final String endSnippet = TagMapper.toAsciiDocEndTag(tag); + + // then + assertThat(startSnippet).isEqualTo("// tag::com.tngtech.jgiven.tags.Feature[]"); + assertThat(endSnippet).isEqualTo("// end::com.tngtech.jgiven.tags.Feature[]"); + } + + @Test + public void single_value_tag_to_AsciiDoc_tag() { + // given + final Tag tag = new Tag("com.tngtech.jgiven.tags.Feature", "AsciiDoc"); + tag.setType("Feature"); + + // when + final String startSnippet = TagMapper.toAsciiDocStartTag(tag); + final String endSnippet = TagMapper.toAsciiDocEndTag(tag); + + // then + assertThat(startSnippet).isEqualTo("// tag::com.tngtech.jgiven.tags.Feature-AsciiDoc[]"); + assertThat(endSnippet).isEqualTo("// end::com.tngtech.jgiven.tags.Feature-AsciiDoc[]"); + } + + @Test + public void single_value_tag_with_type_to_AsciiDoc_tag() { + // given + final Tag tag = new Tag("com.tngtech.jgiven.tags.Issue", "#1337"); + tag.setType("Issue"); + tag.setPrependType(true); + + // when + final String startSnippet = TagMapper.toAsciiDocStartTag(tag); + final String endSnippet = TagMapper.toAsciiDocEndTag(tag); + + // then + assertThat(startSnippet).isEqualTo("// tag::com.tngtech.jgiven.tags.Issue-#1337[]"); + assertThat(endSnippet).isEqualTo("// end::com.tngtech.jgiven.tags.Issue-#1337[]"); + } + + @Test + public void multiple_value_tag_to_AsciiDoc_tag() { + // given + final Tag tag = new Tag("com.tngtech.jgiven.tags.Feature", List.of("AsciiDoc", "Markdown")); + + // when + final String startSnippet = TagMapper.toAsciiDocStartTag(tag); + final String endSnippet = TagMapper.toAsciiDocEndTag(tag); // then - Assertions.assertThat(snippet).isEqualTo("[.hidden]#1#"); + assertThat(startSnippet).isEqualTo("// tag::com.tngtech.jgiven.tags.Feature-AsciiDoc, Markdown[]"); + assertThat(endSnippet).isEqualTo("// end::com.tngtech.jgiven.tags.Feature-AsciiDoc, Markdown[]"); } }