github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/common/cpe/utils_test.go (about) 1 package cpe 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_normalizeName(t *testing.T) { 10 tests := []struct { 11 input string 12 expects string 13 }{ 14 { 15 // note: extra spaces 16 input: " Alex Goodman ", 17 expects: "alexgoodman", 18 }, 19 { 20 input: "Alex Goodman, LLC", 21 expects: "alexgoodman", 22 }, 23 { 24 input: "alex.goodman", 25 expects: "alex.goodman", 26 }, 27 } 28 for _, test := range tests { 29 t.Run(test.input, func(t *testing.T) { 30 assert.Equal(t, test.expects, normalizeName(test.input)) 31 }) 32 } 33 } 34 35 func Test_normalizePersonName(t *testing.T) { 36 tests := []struct { 37 input string 38 expects string 39 }{ 40 { 41 // note: extra spaces 42 input: " Alex Goodman ", 43 expects: "alex_goodman", 44 }, 45 { 46 input: "Alex Goodman", 47 expects: "alex_goodman", 48 }, 49 { 50 input: "Alex.Goodman", 51 expects: "alex_goodman", 52 }, 53 { 54 input: "Alex.Goodman", 55 expects: "alex_goodman", 56 }, 57 { 58 input: "AlexGoodman", 59 expects: "alexgoodman", 60 }, 61 { 62 input: "The Apache Software Foundation", 63 expects: "apache_software_foundation", 64 }, 65 } 66 for _, test := range tests { 67 t.Run(test.input, func(t *testing.T) { 68 assert.Equal(t, test.expects, normalizePersonName(test.input)) 69 }) 70 } 71 }