2021-09-30 20:54:36 +00:00
|
|
|
package spdxlicense
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2023-03-23 15:48:24 +00:00
|
|
|
func TestSPDXIDRecognition(t *testing.T) {
|
2021-09-30 20:54:36 +00:00
|
|
|
var tests = []struct {
|
|
|
|
shortName string
|
2023-02-07 16:47:04 +00:00
|
|
|
id string
|
|
|
|
found bool
|
2021-09-30 20:54:36 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"GPL-1-only",
|
|
|
|
"GPL-1.0-only",
|
2023-03-23 15:48:24 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"gpl1",
|
|
|
|
"GPL-1.0-only",
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"gpl-1",
|
|
|
|
"GPL-1.0-only",
|
2023-02-07 16:47:04 +00:00
|
|
|
true,
|
2021-09-30 20:54:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"GPL-2",
|
2022-08-02 19:25:33 +00:00
|
|
|
"GPL-2.0-only",
|
2023-02-07 16:47:04 +00:00
|
|
|
true,
|
2021-09-30 20:54:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"GPL-2+",
|
2022-08-02 19:25:33 +00:00
|
|
|
"GPL-2.0-or-later",
|
2023-02-07 16:47:04 +00:00
|
|
|
true,
|
2021-09-30 20:54:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"GPL-3.0.0-or-later",
|
|
|
|
"GPL-3.0-or-later",
|
2023-02-07 16:47:04 +00:00
|
|
|
true,
|
2021-09-30 20:54:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"GPL-3-with-autoconf-exception",
|
|
|
|
"GPL-3.0-with-autoconf-exception",
|
2023-02-07 16:47:04 +00:00
|
|
|
true,
|
2021-09-30 20:54:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"CC-by-nc-3-de",
|
|
|
|
"CC-BY-NC-3.0-DE",
|
2023-02-07 16:47:04 +00:00
|
|
|
true,
|
2021-09-30 20:54:36 +00:00
|
|
|
},
|
|
|
|
// the below few cases are NOT expected, however, seem unavoidable given the current approach
|
|
|
|
{
|
|
|
|
"spencer-86.0.0",
|
|
|
|
"Spencer-86",
|
2023-02-07 16:47:04 +00:00
|
|
|
true,
|
2021-09-30 20:54:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"unicode-dfs-2015.0.0",
|
|
|
|
"Unicode-DFS-2015",
|
2023-02-07 16:47:04 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Unknown",
|
|
|
|
"",
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
2023-03-23 15:48:24 +00:00
|
|
|
" ",
|
2023-02-07 16:47:04 +00:00
|
|
|
"",
|
|
|
|
false,
|
2021-09-30 20:54:36 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.shortName, func(t *testing.T) {
|
2023-03-23 15:48:24 +00:00
|
|
|
value, exists := ID(test.shortName)
|
2023-02-07 16:47:04 +00:00
|
|
|
assert.Equal(t, test.found, exists)
|
|
|
|
assert.Equal(t, test.id, value)
|
2021-09-30 20:54:36 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|