forked from TNG/JGiven
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mapping JGiven tags to AsciiDoc tags
Issue: TNG#54 Signed-off-by: Johannes Thorn <2544827+johthor@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
107 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 92 additions & 30 deletions
122
jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]"); | ||
} | ||
} |