From 6d7b6e6ee6947c0e4059a850cd37346247160264 Mon Sep 17 00:00:00 2001 From: bufdev <4228796+bufdev@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:42:20 -0400 Subject: [PATCH] Check all IDs match a given regex (#2) --- .golangci.yml | 3 +++ README.md | 2 ++ spdx_test.go | 15 +++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 557e968..815048f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -49,3 +49,6 @@ issues: - linters: - gocritic path: spdx.go + - linters: + - gocritic + path: spdx_test.go diff --git a/README.md b/README.md index 83c1fbe..edc1d12 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/spdx_test.go b/spdx_test.go index 3fec11d..8853d30 100644 --- a/spdx_test.go +++ b/spdx_test.go @@ -16,6 +16,7 @@ package spdx import ( "reflect" + "regexp" "testing" ) @@ -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) + } + } +}