Skip to content

Commit

Permalink
Add mapping JGiven tags to AsciiDoc tags
Browse files Browse the repository at this point in the history
Issue: TNG#54
Signed-off-by: Johannes Thorn <2544827+johthor@users.noreply.github.com>
  • Loading branch information
johthor committed Jan 23, 2024
1 parent dcc2273 commit 240daf5
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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[]");
}
}

0 comments on commit 240daf5

Please sign in to comment.