Skip to content

Improve tests embebbing#40

Open
Vladyslav-Kuksiuk wants to merge 8 commits into
masterfrom
improve-tests-embebbing
Open

Improve tests embebbing#40
Vladyslav-Kuksiuk wants to merge 8 commits into
masterfrom
improve-tests-embebbing

Conversation

@Vladyslav-Kuksiuk
Copy link
Copy Markdown
Collaborator

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk commented May 26, 2026

This PR improves pattern-based embedding by adding explicit multi-line matching for start, end and line patterns. Instead of requiring a single source line to identify a fragment boundary, patterns can now use \n to match consecutive source lines.

For example:

<embed-code
  file="$test/JunitTest.java"
  start="Test \n adds two values"
  end="assertEquals(2, value); \n }"
/>
```java
@Test
@DisplayName("adds two values")
void addsTwoValues() {
    int value = 1 + 1;

    assertEquals(2, value);
}
```

Each line in a multi-line pattern follows the same glob rules as regular one-line patterns, including ^ and $ for exact matching.

Spaces around \n are ignored.

Additional change: added possibility to write quote characters in patterns as \" instead of the XML entity &quot;.

Resolves #44.

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk self-assigned this May 26, 2026
@Vladyslav-Kuksiuk Vladyslav-Kuksiuk marked this pull request as ready for review May 26, 2026 11:31
Copy link
Copy Markdown
Collaborator

@dmytro-kashcheiev dmytro-kashcheiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vladyslav-Kuksiuk LGTM with minor comment.


class MultiLinePatternSample {

private static final String LINE_SEPARATOR = "\n";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I takes some time for me to understand that LINE_SEPARATOR in readme is a part of source code and not a part of the Glob syntax. Lets change this constant name to something that doesn't sound like a property for <embed-code tag

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends embed-code’s glob-based matching to support multi-line start/end/line patterns separated by \n, and adds support for writing quotes in XML attributes as \" (converted to &quot; internally). It updates documentation and adds new test fixtures + test cases to validate the behavior.

Changes:

  • Add multi-line pattern parsing/matching for start, end, and line patterns using \n separators (with \\n for literal \n text).
  • Allow backslash-escaped quotes (\") in <embed-code ...> XML attributes by converting them to &quot; before XML unmarshalling.
  • Add new embedding/parsing tests and documentation examples; bump version to 1.2.1.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
embedding/parsing/pattern.go Adds multi-line pattern splitting and matching helpers.
embedding/parsing/instruction.go Implements multi-line matching for line, and multi-line-aware start/end matching.
embedding/parsing/xml_parse.go Preprocesses \" into &quot; prior to xml.Unmarshal.
embedding/parsing/instruction_test.go Adds tests for \" parsing and literal glob-character escaping.
embedding/embedding_test.go Adds end-to-end embedding tests covering multi-line patterns and literal \\n matching.
EMBEDDING.md Documents multi-line patterns and escaping rules (including \").
test/resources/docs/escaped-newline-pattern.md New doc fixture for multi-line start/end patterns.
test/resources/docs/escaped-newline-exact-pattern.md New doc fixture for exact (^...$) multi-line patterns.
test/resources/docs/escaped-newline-line-pattern.md New doc fixture for multi-line line patterns.
test/resources/docs/escaped-newline-literal-pattern.md New doc fixture for matching literal \\n text.
test/resources/code/java/org/example/MultiLinePatternSample.java New code fixture used by multi-line pattern embedding tests.
test/resources/code/java/literal-patterns.txt New text fixture for literal wildcard/caret/dollar matching tests.
main.go Bumps application version to 1.2.1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +308 to +315
func matchLineSequence(pattern *Pattern, lines []string, startFrom int) (int, int, bool) {
patternLines, _ := pattern.linePatterns()
lineCount := len(patternLines)
lastStart := len(lines) - lineCount
for start := startFrom; start <= lastStart; start++ {
end := start + lineCount
if pattern.MatchLineSequence(lines[start:end]) {
return start, end - 1, true
Comment thread EMBEDDING.md
```
````

It s possible to write quote characters in patterns as `\"` instead of the XML entity `&quot;`.
Comment on lines +134 to +156
// linePatterns returns trimmed pattern lines separated by an escaped newline.
func (p Pattern) linePatterns() ([]string, bool) {
var patternLines []string
var line strings.Builder
hasSeparator := false
for i := 0; i < len(p.sourceGlob); {
remaining := p.sourceGlob[i:]
switch {
case strings.HasPrefix(remaining, escapedLineSeparator):
line.WriteString(escapedLineSeparator)
i += len(escapedLineSeparator)
case strings.HasPrefix(remaining, lineSeparator):
patternLines = append(patternLines, strings.TrimSpace(line.String()))
line.Reset()
hasSeparator = true
i += len(lineSeparator)
default:
line.WriteByte(p.sourceGlob[i])
i++
}
}
patternLines = append(patternLines, strings.TrimSpace(line.String()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support embedding JUnit test methods

3 participants