Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
[#3] Ignore case, starting and trailing whitespaces, trailing dots
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Biville committed Oct 26, 2018
1 parent e0b2675 commit fa310c0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ func injectDataRegex(result string, data map[string]string) (string, error) {

func regexLines(lines []string) []string {
result := make([]string, 0)
result = append(result, `(?m)(?:\/\*\n)?`)
result = append(result, `(?im)(?:\/\*\n)?`)
for _, line := range lines {
result = append(result, fmt.Sprintf(`%s\Q%s\E\n?`, `(?:\/{2}| \*) ?`, line))
result = append(result, fmt.Sprintf(`%s\Q%s\E[ \t\.]*\n?`, `(?:\/{2}| \*)[ \t]*`, line))
}
result = append(result, `(?:(?:\/{2}| \*) ?\n)*`)
result = append(result, `(?: \*\/)?`)
Expand Down
2 changes: 1 addition & 1 deletion core/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestHeaderDetectionRegexComputation(t *testing.T) {
* Copyright {{.Year}} ACME Labs
*/`))
regex := configuration.HeaderRegex
I.Expect(regex.String()).To(Equal(`(?m)(?:\/\*\n)?(?:\/{2}| \*) ?\QCopyright \E.*\Q \E.*\Q\E\n?(?:(?:\/{2}| \*) ?\n)*(?: \*\/)?`))
I.Expect(regex.String()).To(Equal(`(?im)(?:\/\*\n)?(?:\/{2}| \*)[ \t]*\QCopyright \E.*\Q \E.*\Q\E[ \t\.]*\n?(?:(?:\/{2}| \*) ?\n)*(?: \*\/)?`))
I.Expect(regex.MatchString(configuration.HeaderContents)).To(BeTrue(), "Regex should match contents")
I.Expect(regex.MatchString("// Copyright 2018 ACME Labs")).To(BeTrue(), "Regex should match contents in different comment style")
I.Expect(regex.MatchString(`/*
Expand Down
11 changes: 6 additions & 5 deletions core/headache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ file:../fixtures/bonjour_world.txt

func TestSimilarHeaderReplacement(t *testing.T) {
I := NewGomegaWithT(t)
regex, _ := computeDetectionRegex([]string{"some header {{.Year}}"},
regex, _ := computeDetectionRegex([]string{"some header {{.Year}} and stuff"},
map[string]string{
"Year": "{{.Year}}",
})
file, err := DryRun(&configuration{
HeaderRegex: regexp.MustCompile(regex),
HeaderContents: "// some header {{.Year}}",
HeaderContents: "// some header {{.Year}} and stuff",
vcsChanges: []versioning.FileChange{{
Path: "../fixtures/hello_world_similar.txt",
CreationYear: 2022,
Expand All @@ -271,15 +271,16 @@ func TestSimilarHeaderReplacement(t *testing.T) {
})

I.Expect(err).To(BeNil())
I.Expect(readFile(file)).To(Equal(`file:../fixtures/hello_world_similar.txt
s := readFile(file)
I.Expect(s).To(Equal(`file:../fixtures/hello_world_similar.txt
---
1,4c1
< /*
< * some header 2022
< * Some Header 2022 and stuff .
< *
< */
---
> // some header 2022
> // some header 2022 and stuff
---
`))
}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/hello_world_similar.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* some header 2022
* Some Header 2022 and stuff .
*
*/

Expand Down

0 comments on commit fa310c0

Please sign in to comment.