Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check all IDs match a given regex #2

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
Loading