From 8eb11841fcf8044d3f4540129a698f8035012b85 Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Sun, 18 Oct 2026 17:10:39 +0200 Subject: [PATCH 01/11] Support specifying covered specification items inline after Covers: Allow specification items in Markdown and reStructuredText to declare coverage inline on the same line as the 'Covers:' keyword (e.g. `Covers: req~etc~1`). Add design item `dsn~md.covers-single-line~1`, update user guide, and add unit/parser tests. --- doc/spec/design.md | 17 +++ .../use_cases/writing_a_specification.md | 14 ++- .../AbstractLightWeightMarkupImporter.java | 28 ++++- .../lightweightmarkup/PatternConstants.java | 5 + .../PatternConstantsTest.java | 19 ++++ .../importer/markdown/MarkdownImporter.java | 9 ++ .../importer/markdown/MdPattern.java | 2 + .../markdown/TestMarkdownImporter.java | 19 ++++ .../markdown/TestMarkdownMarkupImporter.java | 17 +++ .../RestructuredTextImporter.java | 9 ++ .../importer/restructuredtext/RstPattern.java | 2 + ...AbstractLightWeightMarkupImporterTest.java | 105 ++++++++++++++++++ 12 files changed, 244 insertions(+), 2 deletions(-) diff --git a/doc/spec/design.md b/doc/spec/design.md index 3a3c819a..10c25835 100644 --- a/doc/spec/design.md +++ b/doc/spec/design.md @@ -1047,6 +1047,23 @@ Covers: Needs: impl, utest +#### Markdown "Covers" Single Line +`dsn~md.covers-single-line~1` + +The Markdown and reStructuredText Importers support defining covered specification items inline on the same line as the "Covers:" keyword. + + covers-single-line = "Covers:" *WSP reference *("," *WSP reference) + +Rationale: + +When a specification item covers only one requirement, writing an unordered bullet list requires multiple lines and markdownlint requires blank lines around lists. Allowing an inline notation is more compact and convenient. + +Covers: + +* `req~markdown-standard-syntax~1` + +Needs: impl, utest + #### Markdown "Depends" List `dsn~md.depends-list~1` diff --git a/doc/user_guide/use_cases/writing_a_specification.md b/doc/user_guide/use_cases/writing_a_specification.md index da5a3614..dcbe10f8 100644 --- a/doc/user_guide/use_cases/writing_a_specification.md +++ b/doc/user_guide/use_cases/writing_a_specification.md @@ -112,7 +112,19 @@ The `Status` keyword takes a single value from `draft`, `proposed`, `approved`, ##### `Covers` -The `Covers` keyword states which items are covered by the current specification item. It is followed by a list of items that are covered, each one written on a new line starting with a bullet character (`+`, `*`, or `-`) followed by the referenced specification item id. +The `Covers` keyword states which items are covered by the current specification item. It comes in two flavors: as one-liner or as list. + +**Variant a) one-line `covers`** + + Covers: feat~rubber-ducky~1 + +Or with multiple comma-separated items: + + Covers: feat~rubber-ducky~1, feat~bathtub~1 + +**Variant b) as List** + +It is followed by a list of items that are covered, each one written on a new line starting with a bullet character (`+`, `*`, or `-`) followed by the referenced specification item id. Given the Feature `feat~rubber-ducky~1` exists and needs a `req`. A requirement that covers that feature could be written as diff --git a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/AbstractLightWeightMarkupImporter.java b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/AbstractLightWeightMarkupImporter.java index f1825d91..06bd482b 100644 --- a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/AbstractLightWeightMarkupImporter.java +++ b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/AbstractLightWeightMarkupImporter.java @@ -1,6 +1,7 @@ package org.itsallcode.openfasttrace.importer.lightweightmarkup; import java.util.logging.Logger; +import java.util.regex.Matcher; import java.util.regex.Pattern; import org.itsallcode.openfasttrace.api.core.*; @@ -274,10 +275,35 @@ protected void addCoverage() this.listener.addCoveredId(locatedId(idText, SpecificationItemId.parseId(idText))); } + /** + * Add covered specification item IDs found on an inline "Covers:" line. + */ + // [impl->dsn~md.covers-single-line~1] + protected void addInlineCoverage() + { + final String line = this.currentContext.currentLine(); + final Matcher matcher = SpecificationItemId.ID_PATTERN.matcher(line); + final int colonIndex = line.indexOf(':'); + if (colonIndex >= 0) + { + matcher.region(colonIndex + 1, line.length()); + } + while (matcher.find()) + { + final String idText = matcher.group(); + final SpecificationItemId id = SpecificationItemId.parseId(idText); + this.listener.addCoveredId(locatedId(idText, id, matcher.start())); + } + } + private LocatedSpecificationItemId locatedId(final String idText, final SpecificationItemId id) + { + return locatedId(idText, id, this.currentContext.currentLine().indexOf(idText)); + } + + private LocatedSpecificationItemId locatedId(final String idText, final SpecificationItemId id, final int column) { // [impl->dsn~located-specification-item-id-text-ranges~1] - final int column = this.currentContext.currentLine().indexOf(idText); final SourceRange range = new SourceRange(new SourcePosition(this.currentContext.lineNumber() - 1, column), new SourcePosition(this.currentContext.lineNumber() - 1, column + idText.length())); final int artifactTypeEnd = idText.indexOf(SpecificationItemId.ARTIFACT_TYPE_SEPARATOR); diff --git a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java index d0720d6e..acf7efb9 100644 --- a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java +++ b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java @@ -27,6 +27,11 @@ public final class PatternConstants + "(" + SpecificationItemId.ID_PATTERN + ")" + "(?:\\W.*)?"; + // [impl->dsn~md.covers-single-line~1] + /** Matches an inline requirement reference. Capture group 1 holds the first ID. */ + public static final String REFERENCE_INLINE = "\\s*.*?(" + + SpecificationItemId.ID_PATTERN + ").*"; + private PatternConstants() { // not instantiable diff --git a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java index 9816bb79..84abfc61 100644 --- a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java +++ b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java @@ -87,4 +87,23 @@ void testReferenceAfterBulletRejectsInvalid(final String input) { assertThat(PatternConstants.REFERENCE_AFTER_BULLET, not(PatternMatcher.patternMatches(input))); } + + // [utest->dsn~md.covers-single-line~1] + @ParameterizedTest + @ValueSource(strings = { " req~name~1", " `req~name~1`", "`req~name~1` extra", "[link](#req~name~1)", + " req~name~1, req~name~2", " `req~name~1`, `req~name~2`" }) + void testReferenceInlineMatchesValid(final String input) + { + final Matcher matcher = Pattern.compile(PatternConstants.REFERENCE_INLINE).matcher(input); + assertAll(() -> assertThat(matcher.matches(), is(true)), + () -> assertThat(matcher.group(1), equalTo("req~name~1"))); + } + + // [utest->dsn~md.covers-single-line~1] + @ParameterizedTest + @ValueSource(strings = { "", " ", "invalid", "not~an~id" }) + void testReferenceInlineRejectsInvalid(final String input) + { + assertThat(PatternConstants.REFERENCE_INLINE, not(PatternMatcher.patternMatches(input))); + } } diff --git a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MarkdownImporter.java b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MarkdownImporter.java index b1087b55..61a6d0e2 100644 --- a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MarkdownImporter.java +++ b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MarkdownImporter.java @@ -71,6 +71,7 @@ protected Transition[] configureTransitions() transition(SPEC_ITEM , TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), transition(SPEC_ITEM , RATIONALE , MdPattern.RATIONALE , this::beginRationale ), transition(SPEC_ITEM , COMMENT , MdPattern.COMMENT , this::beginComment ), + transition(SPEC_ITEM , COVERS , MdPattern.COVERS_INT , this::addInlineCoverage ), transition(SPEC_ITEM , COVERS , MdPattern.COVERS , () -> {} ), transition(SPEC_ITEM , DEPENDS , MdPattern.DEPENDS , () -> {} ), transition(SPEC_ITEM , SPEC_ITEM , MdPattern.NEEDS_INT , this::addNeeds ), @@ -85,6 +86,7 @@ protected Transition[] configureTransitions() transition(DESCRIPTION, TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), transition(DESCRIPTION, RATIONALE , MdPattern.RATIONALE , this::beginRationale ), transition(DESCRIPTION, COMMENT , MdPattern.COMMENT , this::beginComment ), + transition(DESCRIPTION, COVERS , MdPattern.COVERS_INT , this::addInlineCoverage ), transition(DESCRIPTION, COVERS , MdPattern.COVERS , () -> {} ), transition(DESCRIPTION, DEPENDS , MdPattern.DEPENDS , () -> {} ), transition(DESCRIPTION, SPEC_ITEM , MdPattern.NEEDS_INT , this::addNeeds ), @@ -97,6 +99,7 @@ protected Transition[] configureTransitions() transition(RATIONALE , SPEC_ITEM , MdPattern.ID , this::beginItem ), transition(RATIONALE , TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), transition(RATIONALE , COMMENT , MdPattern.COMMENT , this::beginComment ), + transition(RATIONALE , COVERS , MdPattern.COVERS_INT , this::addInlineCoverage ), transition(RATIONALE , COVERS , MdPattern.COVERS , () -> {} ), transition(RATIONALE , DEPENDS , MdPattern.DEPENDS , () -> {} ), transition(RATIONALE , SPEC_ITEM , MdPattern.NEEDS_INT , this::addNeeds ), @@ -107,6 +110,7 @@ protected Transition[] configureTransitions() transition(COMMENT , SPEC_ITEM , MdPattern.ID , this::beginItem ), transition(COMMENT , TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), + transition(COMMENT , COVERS , MdPattern.COVERS_INT , this::addInlineCoverage ), transition(COMMENT , COVERS , MdPattern.COVERS , () -> {} ), transition(COMMENT , DEPENDS , MdPattern.DEPENDS , () -> {} ), transition(COMMENT , SPEC_ITEM , MdPattern.NEEDS_INT , this::addNeeds ), @@ -116,9 +120,11 @@ protected Transition[] configureTransitions() transition(COMMENT , TAGS , MdPattern.TAGS , () -> {} ), transition(COMMENT , COMMENT , MdPattern.EVERYTHING , this::appendComment ), + // [impl->dsn~md.covers-single-line~1] // [impl->dsn~md.covers-list~1] transition(COVERS , SPEC_ITEM , MdPattern.ID , this::beginItem ), transition(COVERS , TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), + transition(COVERS , COVERS , MdPattern.COVERS_INT , this::addInlineCoverage ), transition(COVERS , COVERS , MdPattern.COVERS_REF , this::addCoverage ), transition(COVERS , RATIONALE , MdPattern.RATIONALE , this::beginRationale ), transition(COVERS , COMMENT , MdPattern.COMMENT , this::beginComment ), @@ -140,6 +146,7 @@ protected Transition[] configureTransitions() transition(DEPENDS , SPEC_ITEM , MdPattern.NEEDS_INT , this::addNeeds ), transition(DEPENDS , NEEDS_LIST , MdPattern.NEEDS , () -> {} ), transition(DEPENDS , DEPENDS , MdPattern.EMPTY , () -> {} ), + transition(DEPENDS , COVERS , MdPattern.COVERS_INT , this::addInlineCoverage ), transition(DEPENDS , COVERS , MdPattern.COVERS , () -> {} ), transition(DEPENDS , TAGS , MdPattern.TAGS_INT , this::addTag ), transition(DEPENDS , TAGS , MdPattern.TAGS , () -> {} ), @@ -154,6 +161,7 @@ protected Transition[] configureTransitions() transition(NEEDS_LIST , DEPENDS , MdPattern.DEPENDS , () -> {} ), transition(NEEDS_LIST , NEEDS_LIST , MdPattern.NEEDS_REF , this::addNeeds ), transition(NEEDS_LIST , DESCRIPTION, MdPattern.EMPTY , () -> {} ), + transition(NEEDS_LIST , COVERS , MdPattern.COVERS_INT , this::addInlineCoverage ), transition(NEEDS_LIST , COVERS , MdPattern.COVERS , () -> {} ), transition(NEEDS_LIST , TAGS , MdPattern.TAGS_INT , this::addTag ), transition(NEEDS_LIST , TAGS , MdPattern.TAGS , () -> {} ), @@ -169,6 +177,7 @@ protected Transition[] configureTransitions() transition(TAGS , SPEC_ITEM , MdPattern.NEEDS_INT , this::addNeeds ), transition(TAGS , NEEDS_LIST , MdPattern.NEEDS , () -> {} ), transition(TAGS , SPEC_ITEM , MdPattern.EMPTY , () -> {} ), + transition(TAGS , COVERS , MdPattern.COVERS_INT , this::addInlineCoverage ), transition(TAGS , COVERS , MdPattern.COVERS , () -> {} ), transition(TAGS , TAGS , MdPattern.TAGS , () -> {} ), transition(TAGS , TAGS , MdPattern.TAGS_INT , this::addTag ), diff --git a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java index 391507d1..4986e29e 100644 --- a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java +++ b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java @@ -15,11 +15,13 @@ enum MdPattern // [impl->dsn~md.specification-item-title~1] // [impl->dsn~md.artifact-forwarding-notation~1] // [impl->dsn~md.tags-format~1] + // [impl->dsn~md.covers-single-line~1] // @formatter:off CODE_BEGIN(" *[`~]{3,30}\\w*\\s*"), CODE_END(" *[`~]{3,30}\\s*"), COMMENT("Comment:\\s*"), + COVERS_INT("Covers:" + PatternConstants.REFERENCE_INLINE), COVERS("Covers:\\s*"), COVERS_REF(PatternConstants.REFERENCE_AFTER_BULLET), DEPENDS("Depends:\\s*"), diff --git a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java index 7793879e..7d19d30b 100644 --- a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java +++ b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java @@ -95,6 +95,25 @@ void testIdentifyNonTags(final String text) MarkdownAsserts.assertMismatch(MdPattern.TAGS_INT, text); } + // [utest->dsn~md.covers-single-line~1] + @ParameterizedTest + @CsvSource( + { "Covers: req~foo~1", "Covers: `req~foo~1`", "Covers:req~foo~1", "'Covers: \treq~foo~1 '", + "Covers: req~foo~1, req~bar~2" }) + void testIdentifyCoversInline(final String text) + { + MarkdownAsserts.assertMatch(MdPattern.COVERS_INT, text); + } + + // [utest->dsn~md.covers-single-line~1] + @ParameterizedTest + @CsvSource( + { "Covers:", "#Covers: req~foo~1", "' Covers: req~foo~1'", "Covers: abc" }) + void testIdentifyNonCoversInline(final String text) + { + MarkdownAsserts.assertMismatch(MdPattern.COVERS_INT, text); + } + @Test void testRunImportHandlesIOException(@Mock final InputFile fileMock, @Mock final ImportEventListener listenerMock, @Mock final BufferedReader readerMock) throws IOException diff --git a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownMarkupImporter.java b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownMarkupImporter.java index 5b3fcefa..43ed36a3 100644 --- a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownMarkupImporter.java +++ b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownMarkupImporter.java @@ -89,6 +89,23 @@ void testImportsLocatedDeclarationCoverageAndDependencyIds() () -> assertThat(item.getLocatedDependOnIds().get(0).getRange(), is(range(4, 2, 18)))); } + // [utest->dsn~located-specification-item-id-text-ranges~1] + @Test + void testImportsLocatedDeclarationCoverageAndDependencyIdsInline() + { + final SpecificationItem item = importText(""" + req~subject~1 + Covers: req~covered~2 + Depends: + * req~dependency~3 + """).get(0); + + assertAll( + () -> assertThat(item.getLocatedId().getRange(), is(range(0, 0, 13))), + () -> assertThat(item.getLocatedCoveredIds().get(0).getRange(), is(range(1, 8, 21))), + () -> assertThat(item.getLocatedDependOnIds().get(0).getRange(), is(range(3, 2, 18)))); + } + private static List importText(final String source) { return ImportAssertions.runImporterOnText(Path.of("located.md"), source, importerFactory); diff --git a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RestructuredTextImporter.java b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RestructuredTextImporter.java index c7c7416c..8b87a999 100644 --- a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RestructuredTextImporter.java +++ b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RestructuredTextImporter.java @@ -81,6 +81,7 @@ protected Transition[] configureTransitions() transition(SPEC_ITEM , RATIONALE , RstPattern.RATIONALE , this::beginRationale ), transition(SPEC_ITEM , COMMENT , RstPattern.COMMENT , this::beginComment ), transition(SPEC_ITEM , TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), + transition(SPEC_ITEM , COVERS , RstPattern.COVERS_INT , this::addInlineCoverage ), transition(SPEC_ITEM , COVERS , RstPattern.COVERS , () -> {} ), transition(SPEC_ITEM , DEPENDS , RstPattern.DEPENDS , () -> {} ), transition(SPEC_ITEM , SPEC_ITEM , RstPattern.NEEDS_INT , this::addNeeds ), @@ -95,6 +96,7 @@ protected Transition[] configureTransitions() transition(DESCRIPTION, TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), transition(DESCRIPTION, RATIONALE , RstPattern.RATIONALE , this::beginRationale ), transition(DESCRIPTION, COMMENT , RstPattern.COMMENT , this::beginComment ), + transition(DESCRIPTION, COVERS , RstPattern.COVERS_INT , this::addInlineCoverage ), transition(DESCRIPTION, COVERS , RstPattern.COVERS , () -> {} ), transition(DESCRIPTION, DEPENDS , RstPattern.DEPENDS , () -> {} ), transition(DESCRIPTION, SPEC_ITEM , RstPattern.NEEDS_INT , this::addNeeds ), @@ -108,6 +110,7 @@ protected Transition[] configureTransitions() transition(RATIONALE , SPEC_ITEM , RstPattern.ID , this::beginItem ), transition(RATIONALE , TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), transition(RATIONALE , COMMENT , RstPattern.COMMENT , this::beginComment ), + transition(RATIONALE , COVERS , RstPattern.COVERS_INT , this::addInlineCoverage ), transition(RATIONALE , COVERS , RstPattern.COVERS , () -> {} ), transition(RATIONALE , DEPENDS , RstPattern.DEPENDS , () -> {} ), transition(RATIONALE , SPEC_ITEM , RstPattern.NEEDS_INT , this::addNeeds ), @@ -118,6 +121,7 @@ protected Transition[] configureTransitions() transition(COMMENT , SPEC_ITEM , RstPattern.ID , this::beginItem ), transition(COMMENT , TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), + transition(COMMENT , COVERS , RstPattern.COVERS_INT , this::addInlineCoverage ), transition(COMMENT , COVERS , RstPattern.COVERS , () -> {} ), transition(COMMENT , DEPENDS , RstPattern.DEPENDS , () -> {} ), transition(COMMENT , SPEC_ITEM , RstPattern.NEEDS_INT , this::addNeeds ), @@ -127,9 +131,11 @@ protected Transition[] configureTransitions() transition(COMMENT , TAGS , RstPattern.TAGS , () -> {} ), transition(COMMENT , COMMENT , RstPattern.EVERYTHING , this::appendComment ), + // [impl->dsn~md.covers-single-line~1] // [impl->dsn~md.covers-list~1] transition(COVERS , SPEC_ITEM , RstPattern.ID , this::beginItem ), transition(COVERS , TITLE , SECTION_TITLE , () -> {endItem(); rememberTitle();}), + transition(COVERS , COVERS , RstPattern.COVERS_INT , this::addInlineCoverage ), transition(COVERS , COVERS , RstPattern.COVERS_REF , this::addCoverage ), transition(COVERS , RATIONALE , RstPattern.RATIONALE , this::beginRationale ), transition(COVERS , COMMENT , RstPattern.COMMENT , this::beginComment ), @@ -151,6 +157,7 @@ protected Transition[] configureTransitions() transition(DEPENDS , SPEC_ITEM , RstPattern.NEEDS_INT , this::addNeeds ), transition(DEPENDS , NEEDS_LINE , RstPattern.NEEDS , () -> {} ), transition(DEPENDS , DEPENDS , RstPattern.EMPTY , () -> {} ), + transition(DEPENDS , COVERS , RstPattern.COVERS_INT , this::addInlineCoverage ), transition(DEPENDS , COVERS , RstPattern.COVERS , () -> {} ), transition(DEPENDS , TAGS , RstPattern.TAGS_INT , this::addTag ), transition(DEPENDS , TAGS , RstPattern.TAGS , () -> {} ), @@ -165,6 +172,7 @@ protected Transition[] configureTransitions() transition(NEEDS_LINE , DEPENDS , RstPattern.DEPENDS , () -> {} ), transition(NEEDS_LINE , NEEDS_LINE , RstPattern.NEEDS_REF , this::addNeeds ), transition(NEEDS_LINE , NEEDS_LINE , RstPattern.EMPTY , () -> {} ), + transition(NEEDS_LINE , COVERS , RstPattern.COVERS_INT , this::addInlineCoverage ), transition(NEEDS_LINE , COVERS , RstPattern.COVERS , () -> {} ), transition(NEEDS_LINE , TAGS , RstPattern.TAGS_INT , this::addTag ), transition(NEEDS_LINE , TAGS , RstPattern.TAGS , () -> {} ), @@ -180,6 +188,7 @@ protected Transition[] configureTransitions() transition(TAGS , SPEC_ITEM , RstPattern.NEEDS_INT , this::addNeeds ), transition(TAGS , NEEDS_LINE , RstPattern.NEEDS , () -> {} ), transition(TAGS , SPEC_ITEM , RstPattern.EMPTY , () -> {} ), + transition(TAGS , COVERS , RstPattern.COVERS_INT , this::addInlineCoverage ), transition(TAGS , COVERS , RstPattern.COVERS , () -> {} ), transition(TAGS , TAGS , RstPattern.TAGS , () -> {} ), transition(TAGS , TAGS , RstPattern.TAGS_INT , this::addTag ), diff --git a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java index cbc84e34..cb31ba5d 100644 --- a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java +++ b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java @@ -15,9 +15,11 @@ enum RstPattern // [impl->dsn~md.specification-item-title~1] // [impl->dsn~md.artifact-forwarding-notation~1] // [impl->dsn~md.tags-format~1] + // [impl->dsn~md.covers-single-line~1] // @formatter:off COMMENT("Comment:\\s*"), + COVERS_INT("Covers:" + PatternConstants.REFERENCE_INLINE), COVERS("Covers:\\s*"), COVERS_REF(PatternConstants.REFERENCE_AFTER_BULLET), DEPENDS("Depends:\\s*"), diff --git a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java index 2aa6da41..12611f34 100644 --- a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java +++ b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java @@ -170,6 +170,111 @@ void testSpecificationItemCoversList() .build())); } + // [utest -> dsn~md.covers-single-line~1] + @Test + void testSpecificationItemCoversInline() + { + assertImport(PATH, """ + `req~item-a~2` + + Covers: feat~item-b~1 + """, + contains(item() + .id("req", "item-a", 2) + .addCoveredId("feat", "item-b", 1) + .location(PATH.toString(), 1) + .build())); + } + + // [utest -> dsn~md.covers-single-line~1] + @Test + void testSpecificationItemCoversInlineWithBackticks() + { + assertImport(PATH, """ + `req~item-a~2` + + Covers: `feat~item-b~1` + """, + contains(item() + .id("req", "item-a", 2) + .addCoveredId("feat", "item-b", 1) + .location(PATH.toString(), 1) + .build())); + } + + // [utest -> dsn~md.covers-single-line~1] + @Test + void testSpecificationItemCoversInlineMultipleOnSingleLine() + { + assertImport(PATH, """ + `req~item-a~2` + + Covers: `feat~item-b~1`, `feat~item-c~2` + """, + contains(item() + .id("req", "item-a", 2) + .addCoveredId("feat", "item-b", 1) + .addCoveredId("feat", "item-c", 2) + .location(PATH.toString(), 1) + .build())); + } + + // [utest -> dsn~md.covers-single-line~1] + @Test + void testSpecificationItemCoversInlineMultipleLines() + { + assertImport(PATH, """ + `req~item-a~2` + + Covers: feat~item-b~1 + Covers: feat~item-c~2 + """, + contains(item() + .id("req", "item-a", 2) + .addCoveredId("feat", "item-b", 1) + .addCoveredId("feat", "item-c", 2) + .location(PATH.toString(), 1) + .build())); + } + + // [utest -> dsn~md.covers-single-line~1] + @Test + void testSpecificationItemCoversInlineFollowedByBulletList() + { + assertImport(PATH, """ + `req~item-a~2` + + Covers: feat~item-b~1 + * `feat~item-c~2` + """, + contains(item() + .id("req", "item-a", 2) + .addCoveredId("feat", "item-b", 1) + .addCoveredId("feat", "item-c", 2) + .location(PATH.toString(), 1) + .build())); + } + + // [utest -> dsn~md.covers-single-line~1] + @Test + void testSpecificationItemCoversInlineFollowedByNeeds() + { + assertImport(PATH, """ + `req~item-a~2` + + Covers: feat~item-b~1 + + Needs: impl, utest + """, + contains(item() + .id("req", "item-a", 2) + .addCoveredId("feat", "item-b", 1) + .addNeedsArtifactType("impl") + .addNeedsArtifactType("utest") + .location(PATH.toString(), 1) + .build())); + } + // [utest -> dsn~md.depends-list~1] @Test void testSpecificationItemDependsList() From 25d05a9903363e800dd441dd3a7844fa5ab2a9c7 Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Sun, 18 Oct 2026 18:42:26 +0200 Subject: [PATCH 02/11] doc: mention backticked IDs support for inline Covers --- doc/user_guide/use_cases/writing_a_specification.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/user_guide/use_cases/writing_a_specification.md b/doc/user_guide/use_cases/writing_a_specification.md index dcbe10f8..d390db4c 100644 --- a/doc/user_guide/use_cases/writing_a_specification.md +++ b/doc/user_guide/use_cases/writing_a_specification.md @@ -118,9 +118,13 @@ The `Covers` keyword states which items are covered by the current specification Covers: feat~rubber-ducky~1 -Or with multiple comma-separated items: +The referenced IDs can optionally be enclosed in backticks: - Covers: feat~rubber-ducky~1, feat~bathtub~1 + Covers: `feat~rubber-ducky~1` + +Or with multiple comma-separated items (with or without backticks): + + Covers: `feat~rubber-ducky~1`, `feat~bathtub~1` **Variant b) as List** From 85107c1e9e08ae2cf9ca46804909e4420fe350fc Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Sun, 18 Oct 2026 18:46:40 +0200 Subject: [PATCH 03/11] test: remove unrealistic multiple consecutive Covers lines test --- .../AbstractLightWeightMarkupImporterTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java index 12611f34..4e1c60e7 100644 --- a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java +++ b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java @@ -219,24 +219,6 @@ void testSpecificationItemCoversInlineMultipleOnSingleLine() .build())); } - // [utest -> dsn~md.covers-single-line~1] - @Test - void testSpecificationItemCoversInlineMultipleLines() - { - assertImport(PATH, """ - `req~item-a~2` - - Covers: feat~item-b~1 - Covers: feat~item-c~2 - """, - contains(item() - .id("req", "item-a", 2) - .addCoveredId("feat", "item-b", 1) - .addCoveredId("feat", "item-c", 2) - .location(PATH.toString(), 1) - .build())); - } - // [utest -> dsn~md.covers-single-line~1] @Test void testSpecificationItemCoversInlineFollowedByBulletList() From e3d67d523461404563a3369af61f6d0e48c1aefc Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Sun, 18 Oct 2026 19:00:19 +0200 Subject: [PATCH 04/11] test: remove invalid hybrid inline-and-bullet Covers test --- .../AbstractLightWeightMarkupImporterTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java index 4e1c60e7..2773f068 100644 --- a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java +++ b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java @@ -219,24 +219,6 @@ void testSpecificationItemCoversInlineMultipleOnSingleLine() .build())); } - // [utest -> dsn~md.covers-single-line~1] - @Test - void testSpecificationItemCoversInlineFollowedByBulletList() - { - assertImport(PATH, """ - `req~item-a~2` - - Covers: feat~item-b~1 - * `feat~item-c~2` - """, - contains(item() - .id("req", "item-a", 2) - .addCoveredId("feat", "item-b", 1) - .addCoveredId("feat", "item-c", 2) - .location(PATH.toString(), 1) - .build())); - } - // [utest -> dsn~md.covers-single-line~1] @Test void testSpecificationItemCoversInlineFollowedByNeeds() From cb89dc0024c9f52f69206cd94f53087e2fd681df Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Sun, 18 Oct 2026 19:03:01 +0200 Subject: [PATCH 05/11] test: remove redundant testSpecificationItemCoversInlineFollowedByNeeds --- ...AbstractLightWeightMarkupImporterTest.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java index 2773f068..5118f8f1 100644 --- a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java +++ b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java @@ -219,26 +219,6 @@ void testSpecificationItemCoversInlineMultipleOnSingleLine() .build())); } - // [utest -> dsn~md.covers-single-line~1] - @Test - void testSpecificationItemCoversInlineFollowedByNeeds() - { - assertImport(PATH, """ - `req~item-a~2` - - Covers: feat~item-b~1 - - Needs: impl, utest - """, - contains(item() - .id("req", "item-a", 2) - .addCoveredId("feat", "item-b", 1) - .addNeedsArtifactType("impl") - .addNeedsArtifactType("utest") - .location(PATH.toString(), 1) - .build())); - } - // [utest -> dsn~md.depends-list~1] @Test void testSpecificationItemDependsList() From 75532627decd46905c04528be9f767d834bf3eb6 Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Sun, 18 Oct 2026 19:05:40 +0200 Subject: [PATCH 06/11] test: remove invalid extra string from testReferenceInlineMatchesValid --- .../importer/lightweightmarkup/PatternConstantsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java index 84abfc61..63df6067 100644 --- a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java +++ b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java @@ -90,7 +90,7 @@ void testReferenceAfterBulletRejectsInvalid(final String input) // [utest->dsn~md.covers-single-line~1] @ParameterizedTest - @ValueSource(strings = { " req~name~1", " `req~name~1`", "`req~name~1` extra", "[link](#req~name~1)", + @ValueSource(strings = { " req~name~1", " `req~name~1`", "[link](#req~name~1)", " req~name~1, req~name~2", " `req~name~1`, `req~name~2`" }) void testReferenceInlineMatchesValid(final String input) { From cb3a29b450d8ff657a3743f093d2a1ad74623c17 Mon Sep 17 00:00:00 2001 From: InAnYan Date: Thu, 19 Nov 2026 07:59:05 +0100 Subject: [PATCH 07/11] Update importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastian Bär --- .../importer/lightweightmarkup/PatternConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java index acf7efb9..cc2071c1 100644 --- a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java +++ b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java @@ -28,7 +28,7 @@ public final class PatternConstants + "(?:\\W.*)?"; // [impl->dsn~md.covers-single-line~1] - /** Matches an inline requirement reference. Capture group 1 holds the first ID. */ + /** Matches inline specification item ID reference. Capture group 1 holds the first ID. */ public static final String REFERENCE_INLINE = "\\s*.*?(" + SpecificationItemId.ID_PATTERN + ").*"; From 30ca5574657cfa8f533c4eb6fed2c864c2175fbe Mon Sep 17 00:00:00 2001 From: InAnYan Date: Thu, 19 Nov 2026 07:59:27 +0100 Subject: [PATCH 08/11] Update importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastian Bär --- .../importer/lightweightmarkup/PatternConstantsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java index 63df6067..15004a73 100644 --- a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java +++ b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java @@ -101,7 +101,7 @@ void testReferenceInlineMatchesValid(final String input) // [utest->dsn~md.covers-single-line~1] @ParameterizedTest - @ValueSource(strings = { "", " ", "invalid", "not~an~id" }) + @ValueSource(strings = { "", " ", "invalid", "not~an~id", "also~not-an-id~3b", "someone~forgot~1a~comma-1 }) void testReferenceInlineRejectsInvalid(final String input) { assertThat(PatternConstants.REFERENCE_INLINE, not(PatternMatcher.patternMatches(input))); From 5eb73eec20d02ad8b69c01a2cb9f9fe5afc78181 Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Thu, 19 Nov 2026 08:12:17 +0100 Subject: [PATCH 09/11] refactor: tighten inline Covers regex and address review comments --- .../importer/lightweightmarkup/PatternConstants.java | 5 +++-- .../lightweightmarkup/PatternConstantsTest.java | 8 +++++--- .../openfasttrace/importer/markdown/MdPattern.java | 2 +- .../importer/markdown/TestMarkdownImporter.java | 12 +++++++----- .../markdown/TestMarkdownMarkupImporter.java | 5 ++++- .../importer/restructuredtext/RstPattern.java | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java index cc2071c1..024ce74b 100644 --- a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java +++ b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java @@ -29,8 +29,9 @@ public final class PatternConstants // [impl->dsn~md.covers-single-line~1] /** Matches inline specification item ID reference. Capture group 1 holds the first ID. */ - public static final String REFERENCE_INLINE = "\\s*.*?(" - + SpecificationItemId.ID_PATTERN + ").*"; + public static final String REFERENCE_INLINE = "`?\\b(" + + SpecificationItemId.ID_PATTERN + ")\\b`?" + + "(?:\\s*,\\s*`?\\b" + SpecificationItemId.ID_PATTERN + "\\b`?)*"; private PatternConstants() { diff --git a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java index 15004a73..fc401ef8 100644 --- a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java +++ b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java @@ -90,8 +90,8 @@ void testReferenceAfterBulletRejectsInvalid(final String input) // [utest->dsn~md.covers-single-line~1] @ParameterizedTest - @ValueSource(strings = { " req~name~1", " `req~name~1`", "[link](#req~name~1)", - " req~name~1, req~name~2", " `req~name~1`, `req~name~2`" }) + @ValueSource(strings = { "req~name~1", "`req~name~1`", + "req~name~1, req~name~2", "`req~name~1`, `req~name~2`" }) void testReferenceInlineMatchesValid(final String input) { final Matcher matcher = Pattern.compile(PatternConstants.REFERENCE_INLINE).matcher(input); @@ -101,7 +101,9 @@ void testReferenceInlineMatchesValid(final String input) // [utest->dsn~md.covers-single-line~1] @ParameterizedTest - @ValueSource(strings = { "", " ", "invalid", "not~an~id", "also~not-an-id~3b", "someone~forgot~1a~comma-1 }) + @ValueSource(strings = { "", " ", "invalid", "not~an~id", "also~not-an-id~3b", + "someone~forgot~1a~comma-1", "[link](#req~name~1)", "req~name~1 req~name~2", + "req~name~1; req~name~2" }) void testReferenceInlineRejectsInvalid(final String input) { assertThat(PatternConstants.REFERENCE_INLINE, not(PatternMatcher.patternMatches(input))); diff --git a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java index 4986e29e..1f5c2305 100644 --- a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java +++ b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java @@ -21,7 +21,7 @@ enum MdPattern CODE_BEGIN(" *[`~]{3,30}\\w*\\s*"), CODE_END(" *[`~]{3,30}\\s*"), COMMENT("Comment:\\s*"), - COVERS_INT("Covers:" + PatternConstants.REFERENCE_INLINE), + COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE + "\\s*"), COVERS("Covers:\\s*"), COVERS_REF(PatternConstants.REFERENCE_AFTER_BULLET), DEPENDS("Depends:\\s*"), diff --git a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java index 7d19d30b..c0167cb0 100644 --- a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java +++ b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -97,9 +98,8 @@ void testIdentifyNonTags(final String text) // [utest->dsn~md.covers-single-line~1] @ParameterizedTest - @CsvSource( - { "Covers: req~foo~1", "Covers: `req~foo~1`", "Covers:req~foo~1", "'Covers: \treq~foo~1 '", - "Covers: req~foo~1, req~bar~2" }) + @ValueSource(strings = { "Covers: req~foo~1", "Covers: `req~foo~1`", "Covers:req~foo~1", + "Covers: \treq~foo~1 ", "Covers: req~foo~1, req~bar~2", "Covers: `req~foo~1`, `req~bar~2`" }) void testIdentifyCoversInline(final String text) { MarkdownAsserts.assertMatch(MdPattern.COVERS_INT, text); @@ -107,8 +107,10 @@ void testIdentifyCoversInline(final String text) // [utest->dsn~md.covers-single-line~1] @ParameterizedTest - @CsvSource( - { "Covers:", "#Covers: req~foo~1", "' Covers: req~foo~1'", "Covers: abc" }) + @ValueSource(strings = { "Covers:", "#Covers: req~foo~1", " Covers: req~foo~1", "Covers: abc", + "Covers; req~foo~1", "Covers req~foo~1", "Covers: req~foo~1 req~bar~2", + "Covers: req~foo~1; req~bar~2", "Covers: someone~forgot~1a~comma-1", + "Covers: [link](#req~foo~1)" }) void testIdentifyNonCoversInline(final String text) { MarkdownAsserts.assertMismatch(MdPattern.COVERS_INT, text); diff --git a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownMarkupImporter.java b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownMarkupImporter.java index 43ed36a3..68126480 100644 --- a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownMarkupImporter.java +++ b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownMarkupImporter.java @@ -2,6 +2,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.emptyIterable; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.itsallcode.matcher.auto.AutoMatcher.contains; import static org.itsallcode.openfasttrace.api.core.SpecificationItemId.createId; @@ -95,14 +96,16 @@ void testImportsLocatedDeclarationCoverageAndDependencyIdsInline() { final SpecificationItem item = importText(""" req~subject~1 - Covers: req~covered~2 + Covers: req~covered~2, req~covered~3 Depends: * req~dependency~3 """).get(0); assertAll( () -> assertThat(item.getLocatedId().getRange(), is(range(0, 0, 13))), + () -> assertThat(item.getLocatedCoveredIds(), hasSize(2)), () -> assertThat(item.getLocatedCoveredIds().get(0).getRange(), is(range(1, 8, 21))), + () -> assertThat(item.getLocatedCoveredIds().get(1).getRange(), is(range(1, 23, 36))), () -> assertThat(item.getLocatedDependOnIds().get(0).getRange(), is(range(3, 2, 18)))); } diff --git a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java index cb31ba5d..3a5d3863 100644 --- a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java +++ b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java @@ -19,7 +19,7 @@ enum RstPattern // @formatter:off COMMENT("Comment:\\s*"), - COVERS_INT("Covers:" + PatternConstants.REFERENCE_INLINE), + COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE + "\\s*"), COVERS("Covers:\\s*"), COVERS_REF(PatternConstants.REFERENCE_AFTER_BULLET), DEPENDS("Depends:\\s*"), From 6c1635763ff47a3a102e9fb3698691ff61e0b74c Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Thu, 19 Nov 2026 08:23:19 +0100 Subject: [PATCH 10/11] refactor: simplify REFERENCE_INLINE and clean up test cases --- .../importer/lightweightmarkup/PatternConstants.java | 5 ++--- .../importer/lightweightmarkup/PatternConstantsTest.java | 6 ++---- .../openfasttrace/importer/markdown/MdPattern.java | 3 ++- .../importer/markdown/TestMarkdownImporter.java | 3 +-- .../openfasttrace/importer/restructuredtext/RstPattern.java | 3 ++- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java index 024ce74b..3657b305 100644 --- a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java +++ b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java @@ -28,10 +28,9 @@ public final class PatternConstants + "(?:\\W.*)?"; // [impl->dsn~md.covers-single-line~1] - /** Matches inline specification item ID reference. Capture group 1 holds the first ID. */ + /** Matches inline specification item ID reference. Capture group 1 holds the ID. */ public static final String REFERENCE_INLINE = "`?\\b(" - + SpecificationItemId.ID_PATTERN + ")\\b`?" - + "(?:\\s*,\\s*`?\\b" + SpecificationItemId.ID_PATTERN + "\\b`?)*"; + + SpecificationItemId.ID_PATTERN + ")\\b`?"; private PatternConstants() { diff --git a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java index fc401ef8..228fb705 100644 --- a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java +++ b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java @@ -90,8 +90,7 @@ void testReferenceAfterBulletRejectsInvalid(final String input) // [utest->dsn~md.covers-single-line~1] @ParameterizedTest - @ValueSource(strings = { "req~name~1", "`req~name~1`", - "req~name~1, req~name~2", "`req~name~1`, `req~name~2`" }) + @ValueSource(strings = { "req~name~1", "`req~name~1`" }) void testReferenceInlineMatchesValid(final String input) { final Matcher matcher = Pattern.compile(PatternConstants.REFERENCE_INLINE).matcher(input); @@ -102,8 +101,7 @@ void testReferenceInlineMatchesValid(final String input) // [utest->dsn~md.covers-single-line~1] @ParameterizedTest @ValueSource(strings = { "", " ", "invalid", "not~an~id", "also~not-an-id~3b", - "someone~forgot~1a~comma-1", "[link](#req~name~1)", "req~name~1 req~name~2", - "req~name~1; req~name~2" }) + "someone~forgot~1a~comma-1" }) void testReferenceInlineRejectsInvalid(final String input) { assertThat(PatternConstants.REFERENCE_INLINE, not(PatternMatcher.patternMatches(input))); diff --git a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java index 1f5c2305..0bc82b69 100644 --- a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java +++ b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java @@ -21,7 +21,8 @@ enum MdPattern CODE_BEGIN(" *[`~]{3,30}\\w*\\s*"), CODE_END(" *[`~]{3,30}\\s*"), COMMENT("Comment:\\s*"), - COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE + "\\s*"), + COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE + + "(?:\\s*,\\s*" + PatternConstants.REFERENCE_INLINE + ")*\\s*"), COVERS("Covers:\\s*"), COVERS_REF(PatternConstants.REFERENCE_AFTER_BULLET), DEPENDS("Depends:\\s*"), diff --git a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java index c0167cb0..84d5b8dc 100644 --- a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java +++ b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java @@ -109,8 +109,7 @@ void testIdentifyCoversInline(final String text) @ParameterizedTest @ValueSource(strings = { "Covers:", "#Covers: req~foo~1", " Covers: req~foo~1", "Covers: abc", "Covers; req~foo~1", "Covers req~foo~1", "Covers: req~foo~1 req~bar~2", - "Covers: req~foo~1; req~bar~2", "Covers: someone~forgot~1a~comma-1", - "Covers: [link](#req~foo~1)" }) + "Covers: req~foo~1; req~bar~2", "Covers: someone~forgot~1a~comma-1" }) void testIdentifyNonCoversInline(final String text) { MarkdownAsserts.assertMismatch(MdPattern.COVERS_INT, text); diff --git a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java index 3a5d3863..48099d3a 100644 --- a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java +++ b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java @@ -19,7 +19,8 @@ enum RstPattern // @formatter:off COMMENT("Comment:\\s*"), - COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE + "\\s*"), + COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE + + "(?:\\s*,\\s*" + PatternConstants.REFERENCE_INLINE + ")*\\s*"), COVERS("Covers:\\s*"), COVERS_REF(PatternConstants.REFERENCE_AFTER_BULLET), DEPENDS("Depends:\\s*"), From 99a545a1aa6213b137a35ab9581e01be6e8f4387 Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Thu, 19 Nov 2026 08:27:39 +0100 Subject: [PATCH 11/11] refactor: clean up inline reference pattern and enforce balanced backticks --- .../lightweightmarkup/PatternConstants.java | 11 ++++++++--- .../lightweightmarkup/PatternConstantsTest.java | 15 +++++++++++---- .../importer/markdown/MdPattern.java | 3 +-- .../importer/markdown/TestMarkdownImporter.java | 3 ++- .../importer/restructuredtext/RstPattern.java | 3 +-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java index 3657b305..9bae2954 100644 --- a/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java +++ b/importer/lightweightmarkup/src/main/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstants.java @@ -27,10 +27,15 @@ public final class PatternConstants + "(" + SpecificationItemId.ID_PATTERN + ")" + "(?:\\W.*)?"; + private static final String BOUNDED_ID = "\\b" + SpecificationItemId.ID_PATTERN + "\\b"; + // [impl->dsn~md.covers-single-line~1] - /** Matches inline specification item ID reference. Capture group 1 holds the ID. */ - public static final String REFERENCE_INLINE = "`?\\b(" - + SpecificationItemId.ID_PATTERN + ")\\b`?"; + /** Matches an inline specification item ID reference (plain or enclosed in backticks). */ + public static final String REFERENCE_INLINE = "(?:`" + BOUNDED_ID + "`|" + BOUNDED_ID + ")"; + + /** Matches a comma-separated list of inline specification item ID references. */ + public static final String REFERENCE_INLINE_LIST = REFERENCE_INLINE + + "(?:\\s*,\\s*" + REFERENCE_INLINE + ")*"; private PatternConstants() { diff --git a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java index 228fb705..3078e281 100644 --- a/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java +++ b/importer/lightweightmarkup/src/test/java/org/itsallcode/openfasttrace/importer/lightweightmarkup/PatternConstantsTest.java @@ -93,17 +93,24 @@ void testReferenceAfterBulletRejectsInvalid(final String input) @ValueSource(strings = { "req~name~1", "`req~name~1`" }) void testReferenceInlineMatchesValid(final String input) { - final Matcher matcher = Pattern.compile(PatternConstants.REFERENCE_INLINE).matcher(input); - assertAll(() -> assertThat(matcher.matches(), is(true)), - () -> assertThat(matcher.group(1), equalTo("req~name~1"))); + assertThat(PatternConstants.REFERENCE_INLINE, PatternMatcher.patternMatches(input)); } // [utest->dsn~md.covers-single-line~1] @ParameterizedTest @ValueSource(strings = { "", " ", "invalid", "not~an~id", "also~not-an-id~3b", - "someone~forgot~1a~comma-1" }) + "someone~forgot~1a~comma-1", "`req~name~1", "req~name~1`" }) void testReferenceInlineRejectsInvalid(final String input) { assertThat(PatternConstants.REFERENCE_INLINE, not(PatternMatcher.patternMatches(input))); } + + // [utest->dsn~md.covers-single-line~1] + @ParameterizedTest + @ValueSource(strings = { "req~name~1", "`req~name~1`", "req~name~1, req~name~2", + "`req~name~1`, `req~name~2`", "`req~name~1`, req~name~2" }) + void testReferenceInlineListMatchesValid(final String input) + { + assertThat(PatternConstants.REFERENCE_INLINE_LIST, PatternMatcher.patternMatches(input)); + } } diff --git a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java index 0bc82b69..e86ee3c4 100644 --- a/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java +++ b/importer/markdown/src/main/java/org/itsallcode/openfasttrace/importer/markdown/MdPattern.java @@ -21,8 +21,7 @@ enum MdPattern CODE_BEGIN(" *[`~]{3,30}\\w*\\s*"), CODE_END(" *[`~]{3,30}\\s*"), COMMENT("Comment:\\s*"), - COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE - + "(?:\\s*,\\s*" + PatternConstants.REFERENCE_INLINE + ")*\\s*"), + COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE_LIST + "\\s*"), COVERS("Covers:\\s*"), COVERS_REF(PatternConstants.REFERENCE_AFTER_BULLET), DEPENDS("Depends:\\s*"), diff --git a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java index 84d5b8dc..8ab144f5 100644 --- a/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java +++ b/importer/markdown/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java @@ -109,7 +109,8 @@ void testIdentifyCoversInline(final String text) @ParameterizedTest @ValueSource(strings = { "Covers:", "#Covers: req~foo~1", " Covers: req~foo~1", "Covers: abc", "Covers; req~foo~1", "Covers req~foo~1", "Covers: req~foo~1 req~bar~2", - "Covers: req~foo~1; req~bar~2", "Covers: someone~forgot~1a~comma-1" }) + "Covers: req~foo~1; req~bar~2", "Covers: someone~forgot~1a~comma-1", + "Covers: `req~foo~1", "Covers: req~foo~1`" }) void testIdentifyNonCoversInline(final String text) { MarkdownAsserts.assertMismatch(MdPattern.COVERS_INT, text); diff --git a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java index 48099d3a..f1197242 100644 --- a/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java +++ b/importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RstPattern.java @@ -19,8 +19,7 @@ enum RstPattern // @formatter:off COMMENT("Comment:\\s*"), - COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE - + "(?:\\s*,\\s*" + PatternConstants.REFERENCE_INLINE + ")*\\s*"), + COVERS_INT("Covers:\\s*" + PatternConstants.REFERENCE_INLINE_LIST + "\\s*"), COVERS("Covers:\\s*"), COVERS_REF(PatternConstants.REFERENCE_AFTER_BULLET), DEPENDS("Depends:\\s*"),