github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/common/spdxhelpers/none_if_empty_test.go (about) 1 package spdxhelpers 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_noneIfEmpty(t *testing.T) { 10 tests := []struct { 11 name string 12 value string 13 expected string 14 }{ 15 { 16 name: "non-zero value", 17 value: "something", 18 expected: "something", 19 }, 20 { 21 name: "empty", 22 value: "", 23 expected: NONE, 24 }, 25 { 26 name: "space", 27 value: " ", 28 expected: NONE, 29 }, 30 { 31 name: "tab", 32 value: "\t", 33 expected: NONE, 34 }, 35 } 36 for _, test := range tests { 37 t.Run(test.name, func(t *testing.T) { 38 assert.Equal(t, test.expected, NoneIfEmpty(test.value)) 39 }) 40 } 41 }