Skip to content

Commit

Permalink
Merge branch 'main' into add-quote
Browse files Browse the repository at this point in the history
  • Loading branch information
sakajunquality authored Apr 22, 2024
2 parents 7c93be2 + 5d8e8ee commit 696d9d1
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions flow/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,17 @@ func TestRegexTemplate(t *testing.T) {
}

func TestVersionREwriteRegex(t *testing.T) {
change := "version: xyz"

original := `
testcases := []struct {
name string
change func(m regexp2.Match) string
original string
expected string
}{
{
name: "no quotes",
change: func(m regexp2.Match) string { return "version: xyz" },
original: `
version: abc
version: 123 # do-not-rewrite
test:
Expand All @@ -242,8 +250,8 @@ test:
version: abc
foo:
version: aiueo # no-rewrite
`
expected := `
`,
expected: `
version: xyz
version: 123 # do-not-rewrite
test:
Expand All @@ -252,10 +260,42 @@ test:
version: xyz
foo:
version: aiueo # no-rewrite
`
re := regexp2.MustCompile(versionRewriteRegex, 0)
result, err := re.Replace(original, change, 0, -1)
`,
},
{
name: "with quotes",
change: func(m regexp2.Match) string { return `version: "xyz"` },

assert.Nil(t, err)
assert.Equal(t, expected, result)
original: `
version: abc
version: 123 # do-not-rewrite
test:
foo:
bar:
version: abc
foo:
version: aiueo # no-rewrite
`,
expected: `
version: "xyz"
version: 123 # do-not-rewrite
test:
foo:
bar:
version: "xyz"
foo:
version: aiueo # no-rewrite
`,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {

re := regexp2.MustCompile(versionRewriteRegex, 0)
result, err := re.ReplaceFunc(tc.original, tc.change, 0, -1)

assert.Nil(t, err)
assert.Equal(t, tc.expected, result)
})
}
}

0 comments on commit 696d9d1

Please sign in to comment.