Skip to content

Commit

Permalink
#65 add test for long tag with parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten Marx committed Nov 9, 2023
1 parent 84f0e44 commit d68e694
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
@RequiredArgsConstructor
public class ContentTags {

public static final Pattern TAG_PARAMS_PATTERN_SHORT = Pattern.compile("\\[{2}(?<tag>[a-z_A-Z]+)( (?<params>.*?))?\\p{Blank}*/\\]{2}");
public static final Pattern TAG_PARAMS_PATTERN_SHORT = Pattern.compile("\\[{2}(?<tag>[a-z_A-Z0-9]+)( (?<params>.*?))?\\p{Blank}*/\\]{2}");

public static final Pattern TAG_PARAMS_PATTERN_LONG = Pattern.compile("\\[{2}(?<tag>[a-z_A-Z]+)( (?<params>.*?))?\\]{2}(?<content>.*)\\[{2}/\\k<tag>\\]{2}");
public static final Pattern TAG_PARAMS_PATTERN_LONG = Pattern.compile("\\[{2}(?<tag>[a-z_A-Z0-9]+)( (?<params>.*?))?\\]{2}(?<content>.*)\\[{2}/\\k<tag>\\]{2}");

private final Tags tags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public static void init () {
params -> "<mark>%s</mark>".formatted(params.get("content"))
);

tags.add(
"mark2",
params -> "<mark class='%s'>%s</mark>".formatted(params.get("class"), params.get("content"))
);

contentTags = new ContentTags(tags);
}

Expand Down Expand Up @@ -113,6 +118,13 @@ void test_long () {
Assertions.assertThat(result).isEqualTo("<mark>Important</mark>");
}

@Test
void test_long_with_params () {
var result = contentTags.replace("[[mark2 class='test-class']]Important[[/mark2]]");

Assertions.assertThat(result).isEqualTo("<mark class='test-class'>Important</mark>");
}

@Test
void long_complex () {

Expand Down

0 comments on commit d68e694

Please sign in to comment.