Repository navigation
bugfix/423_uniform-tag-parsing #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
redcatbear
wants to merge
4
commits into
main
Choose a base branch
from
bugfix/423_uniform-tag-parsing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
91060a1
#423: Fixed tag parsing inconsistency
redcatbear 830681b
#423: Updated user guide with tag syntax and formats.
redcatbear f17c8c9
#423: Added test with inline and bulleted tags at the same time.
redcatbear 9baa09d
#423: Extracted common regex patterns to `ligthweightmarkup` package …
redcatbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
30 changes: 30 additions & 0 deletions
30
...c/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.itsallcode.openfasttrace.importer.lightweightmarkup; | ||
|
|
||
| import org.itsallcode.openfasttrace.api.core.SpecificationItemId; | ||
|
|
||
| /** | ||
| * Common regular expression constants used across lightweight markup formats. | ||
| */ | ||
| public final class PatternConstants | ||
| { | ||
| /** Matches valid artifact types (e.g., "req", "test"). */ | ||
| public static final String ARTIFACT_TYPE = "\\p{Alpha}+"; | ||
| /** Matches valid bullet points ("+", "*", "-"). */ | ||
| public static final String BULLETS = "[+*-]"; | ||
| // [impl->dsn~md.tags-format~1] | ||
| /** Matches valid tag names. */ | ||
| public static final String TAG_PATTERN = "\\p{Aplha}\\w*"; | ||
| /** Matches zero to three whitespace characters. */ | ||
| public static final String UP_TO_3_WHITESPACES = "\\s{0,3}"; | ||
| // [impl->dsn~md.requirement-references~1] | ||
| /** Matches a requirement reference after a bullet. Capture group 1 holds the ID. */ | ||
| public static final String REFERENCE_AFTER_BULLET = UP_TO_3_WHITESPACES | ||
| + PatternConstants.BULLETS + "(?:.*\\W)?" // | ||
| + "(" + SpecificationItemId.ID_PATTERN + ")" // | ||
| + "(?:\\W.*)?"; | ||
|
|
||
| private PatternConstants() | ||
| { | ||
| // not instantiable | ||
| } | ||
| } |
92 changes: 92 additions & 0 deletions
92
...st/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package org.itsallcode.openfasttrace.importer.lightweightmarkup; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.is; | ||
| import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
|
||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| class PatternConstantsTest | ||
| { | ||
| @ParameterizedTest | ||
| @ValueSource(strings = { "req", "feat", "DSN", "Artifact" }) | ||
| void testArtifactTypeMatchesValid(final String input) | ||
| { | ||
| assertThat(input.matches(PatternConstants.ARTIFACT_TYPE), is(true)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { "123", "req_1", "feat-item", "" }) | ||
| void testArtifactTypeRejectsInvalid(final String input) | ||
| { | ||
| assertThat(input.matches(PatternConstants.ARTIFACT_TYPE), is(false)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { "+", "*", "-" }) | ||
| void testBulletsMatchesValid(final String input) | ||
| { | ||
| assertThat(input.matches(PatternConstants.BULLETS), is(true)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { "/", "#", "=", "++", "" }) | ||
| void testBulletsRejectsInvalid(final String input) | ||
| { | ||
| assertThat(input.matches(PatternConstants.BULLETS), is(false)); | ||
| } | ||
|
|
||
| // [utest->dsn~md.tags-format~1] | ||
| @ParameterizedTest | ||
| @ValueSource(strings = { "tag", "TAG_1", "0_valid", "a" }) | ||
| void testTagPatternMatchesValid(final String input) | ||
| { | ||
| assertThat(input.matches(PatternConstants.TAG_PATTERN), is(true)); | ||
| } | ||
|
|
||
| // [utest->dsn~md.tags-format~1] | ||
| @ParameterizedTest | ||
| @ValueSource(strings = { "_invalid", "-invalid", "tag with spaces", "" }) | ||
| void testTagPatternRejectsInvalid(final String input) | ||
| { | ||
| assertThat(input.matches(PatternConstants.TAG_PATTERN), is(false)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { "", " ", " ", " " }) | ||
| void testUpTo3WhitespacesMatchesValid(final String input) | ||
| { | ||
| assertThat(input.matches(PatternConstants.UP_TO_3_WHITESPACES), is(true)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { " ", "\t\t\t\t" }) | ||
| void testUpTo3WhitespacesRejectsMoreThan3(final String input) | ||
| { | ||
| assertThat(input.matches(PatternConstants.UP_TO_3_WHITESPACES), is(false)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { "* req~name~1", " * req~name~1", " * req~name~1", "+ req~name~1", "- req~name~1", | ||
| "* covers: req~name~1", "* req~name~1 extra" }) | ||
| void testReferenceAfterBulletMatchesValid(final String input) | ||
| { | ||
| // Given/When/Then: input matches the pattern and captures the ID | ||
| final Matcher matcher = Pattern.compile(PatternConstants.REFERENCE_AFTER_BULLET).matcher(input); | ||
| assertAll(() -> assertThat(matcher.matches(), is(true)), | ||
| () -> assertThat(matcher.group(1), equalTo("req~name~1"))); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { " * req~name~1", "req~name~1", "*", " * " }) | ||
| void testReferenceAfterBulletRejectsInvalid(final String input) | ||
| { | ||
| // Given/When/Then: input does not match | ||
| assertThat(Pattern.compile(PatternConstants.REFERENCE_AFTER_BULLET).matcher(input).matches(), is(false)); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This silently ignores invalid tags. Should we at least log a warning to avoid surprises?