github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/internal/spdxlicense/license_test.go (about) 1 package spdxlicense 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestSPDXIDRecognition(t *testing.T) { 10 var tests = []struct { 11 shortName string 12 id string 13 found bool 14 }{ 15 { 16 "GPL-1-only", 17 "GPL-1.0-only", 18 true, 19 }, 20 { 21 "gpl1", 22 "GPL-1.0-only", 23 true, 24 }, 25 { 26 "gpl-1", 27 "GPL-1.0-only", 28 true, 29 }, 30 { 31 "GPL-2", 32 "GPL-2.0-only", 33 true, 34 }, 35 { 36 "GPL-2+", 37 "GPL-2.0-or-later", 38 true, 39 }, 40 { 41 "GPL-3.0.0-or-later", 42 "GPL-3.0-or-later", 43 true, 44 }, 45 { 46 "GPL-3-with-autoconf-exception", 47 "GPL-3.0-with-autoconf-exception", 48 true, 49 }, 50 { 51 "CC-by-nc-3-de", 52 "CC-BY-NC-3.0-DE", 53 true, 54 }, 55 // the below few cases are NOT expected, however, seem unavoidable given the current approach 56 { 57 "spencer-86.0.0", 58 "Spencer-86", 59 true, 60 }, 61 { 62 "unicode-dfs-2015.0.0", 63 "Unicode-DFS-2015", 64 true, 65 }, 66 { 67 "Unknown", 68 "", 69 false, 70 }, 71 { 72 " ", 73 "", 74 false, 75 }, 76 } 77 78 for _, test := range tests { 79 t.Run(test.shortName, func(t *testing.T) { 80 value, exists := ID(test.shortName) 81 assert.Equal(t, test.found, exists) 82 assert.Equal(t, test.id, value) 83 }) 84 } 85 }