Skip to content

Commit

Permalink
Check all IDs match a given regex (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev authored Oct 31, 2024
1 parent b58e931 commit 6d7b6e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ issues:
- linters:
- gocritic
path: spdx.go
- linters:
- gocritic
path: spdx_test.go
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ for _, license := range spdx.AllLicenses() {
}
```

All IDs are guaranteed to match the regular expression `^[a-zA-Z0-9-.+]+$`.

## Status: Beta

This repository is still in beta, however will be promoted to stable very soon.
Expand Down
15 changes: 15 additions & 0 deletions spdx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package spdx

import (
"reflect"
"regexp"
"testing"
)

Expand All @@ -42,3 +43,17 @@ func TestLicenseForID(t *testing.T) {
t.Fatal("failed to get expected license info")
}
}

func TestIDsMatchExpectedRegext(t *testing.T) {
t.Parallel()

regexp, err := regexp.Compile("^[a-zA-Z0-9-.+]+$")
if err != nil {
t.Fatal(err.Error())
}
for _, license := range lowercaseIDToLicense {
if !regexp.Match([]byte(license.ID)) {
t.Fatalf("license ID %q did not match regex", license.ID)
}
}
}

0 comments on commit 6d7b6e6

Please sign in to comment.