From 1f596f23164e77ed9f1f280e2fec4e1d4cd4dbdf Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Mon, 25 Dec 2023 17:05:28 +0100 Subject: [PATCH] Use multi-line for current version regexp More useful and probably more expected --- internal/bump/fileset.go | 7 +++++-- internal/cli/cli_test.go | 2 +- internal/cli/testdata/bumpfile_match_line_end | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 internal/cli/testdata/bumpfile_match_line_end diff --git a/internal/bump/fileset.go b/internal/bump/fileset.go index 18d3fbb..ff6d1c1 100644 --- a/internal/bump/fileset.go +++ b/internal/bump/fileset.go @@ -44,6 +44,7 @@ type Check struct { // bump: // PipelineLineNr int + CurrentREStr string CurrentRE *regexp.Regexp Pipeline pipeline.Pipeline PipelineDuration time.Duration @@ -80,7 +81,7 @@ type Current struct { } func (c *Check) String() string { - return fmt.Sprintf("%s /%s/ %s", c.Name, c.CurrentRE, c.Pipeline) + return fmt.Sprintf("%s /%s/ %s", c.Name, c.CurrentREStr, c.Pipeline) } // FileSet is a set of File:s, filters and checks found in files @@ -443,7 +444,8 @@ func (fs *FileSet) parseCheckLine(file *File, lineNr int, line string, filters [ if err != nil { return fmt.Errorf("%s: %w", pipelineStr, err) } - currentRe, err := regexp.Compile(currentReStr) + // compile in multi-line mode: ^$ matches end/start of line + currentRe, err := regexp.Compile("(?m)" + currentReStr) if err != nil { return fmt.Errorf("invalid current version regexp: %q", currentReStr) } @@ -454,6 +456,7 @@ func (fs *FileSet) parseCheckLine(file *File, lineNr int, line string, filters [ check := &Check{ File: file, Name: name, + CurrentREStr: currentReStr, CurrentRE: currentRe, PipelineLineNr: lineNr, Pipeline: pl, diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index 68eb9ac..4a70119 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -248,7 +248,7 @@ func parseTestCases(s string) []testCase { tc := testCase{} seenRun := false - for _, section := range sectionParser(regexp.MustCompile(`^([/>].*:)|[#\$!].*$`), c) { + for _, section := range sectionParser(regexp.MustCompile(`^([/>].*:)|^[#\$!].*$`), c) { n, v := section.Name, section.Value switch { diff --git a/internal/cli/testdata/bumpfile_match_line_end b/internal/cli/testdata/bumpfile_match_line_end new file mode 100644 index 0000000..e69cf99 --- /dev/null +++ b/internal/cli/testdata/bumpfile_match_line_end @@ -0,0 +1,6 @@ +/a: +bump: name /^name: (1)$/ static:2 +name: 1 +$ bump current a +>stdout: +a:2: name 1 \ No newline at end of file