aboutsummaryrefslogtreecommitdiff
path: root/spdxconv_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-13 01:44:23 +0700
committerShulhan <ms@kilabit.info>2026-01-13 01:45:18 +0700
commit434139fe3918fdb56704558301ad9275f1da06ad (patch)
tree76f4a942f9f47398ab153a8319b2c4d2e442d167 /spdxconv_test.go
parente16e2a4ec74443aa8f4c21a73ee837cb72ed46fb (diff)
downloadspdxconv-434139fe3918fdb56704558301ad9275f1da06ad.tar.xz
all: split the delete_line_pattern into before and after
While at it, also add configuration for delete line before and after for match-copyright section.
Diffstat (limited to 'spdxconv_test.go')
-rw-r--r--spdxconv_test.go30
1 files changed, 26 insertions, 4 deletions
diff --git a/spdxconv_test.go b/spdxconv_test.go
index 77929e8..11a2a72 100644
--- a/spdxconv_test.go
+++ b/spdxconv_test.go
@@ -66,12 +66,22 @@ func TestInit(t *testing.T) {
MatchLicense: []*matchLicense{{
Pattern: `^(//+|#+|/\*+|<!--+)?\s*(.*)governed by a BSD-style(.*)$`,
LicenseIdentifier: `BSD-3-Clause`,
- DeleteLinePattern: []string{
+ DeleteLineBefore: []string{
+ `^(//+|#+|/\*+|<!--+)$`,
+ },
+ DeleteLineAfter: []string{
`^(//+|#+|/\*+|<!--+)?\s*license that can(.*)$`,
+ `^(//+|#+|\*+/|--+>)$`,
},
}},
MatchCopyright: []*matchCopyright{{
Pattern: `^(//+|#+|/\*+|<!--+)?\s*Copyright\s+(?<year>\d{4}),?\s+(?<author>.*)\s+<(?<contact>.*)>.*$`,
+ DeleteLineBefore: []string{
+ `^(//+|#+|/\*+|<!--+)$`,
+ },
+ DeleteLineAfter: []string{
+ `^(//+|#+|\*+/|--+>)$`,
+ },
}},
}
for _, mfc := range exp.MatchFileComment {
@@ -79,13 +89,25 @@ func TestInit(t *testing.T) {
}
for _, ml := range exp.MatchLicense {
ml.rePattern = regexp.MustCompile(ml.Pattern)
- for _, dlp := range ml.DeleteLinePattern {
+ for _, dlp := range ml.DeleteLineBefore {
+ re := regexp.MustCompile(dlp)
+ ml.reDeleteLineBefore = append(ml.reDeleteLineBefore, re)
+ }
+ for _, dlp := range ml.DeleteLineAfter {
re := regexp.MustCompile(dlp)
- ml.reDeleteLine = append(ml.reDeleteLine, re)
+ ml.reDeleteLineAfter = append(ml.reDeleteLineAfter, re)
}
}
for _, mc := range exp.MatchCopyright {
mc.rePattern = regexp.MustCompile(mc.Pattern)
+ for _, dlp := range mc.DeleteLineBefore {
+ re := regexp.MustCompile(dlp)
+ mc.reDeleteLineBefore = append(mc.reDeleteLineBefore, re)
+ }
+ for _, dlp := range mc.DeleteLineAfter {
+ re := regexp.MustCompile(dlp)
+ mc.reDeleteLineAfter = append(mc.reDeleteLineAfter, re)
+ }
}
test.Assert(t, `Init: loadConfig`, exp, conv.cfg)
}
@@ -111,7 +133,7 @@ func TestScan(t *testing.T) {
//spdxconv:header:path,license_id,idx_license_id,year,copyright_id,idx_copyright_id
//spdxconv:regular
test.go,match,1,2022,match,0,// ,
-test.html,match,2,2022,match,1,<!-- ," -->"
+test.html,match,4,2022,match,1,<!-- ," -->"
test.sh,match,1,2022,match,0,# ,
//spdxconv:binary
//spdxconv:unknown`