github.com/jfrog/jfrog-cli-core/v2@v2.51.0/utils/coreutils/tableutils_test.go (about)

     1  package coreutils
     2  
     3  import (
     4  	"github.com/magiconair/properties/assert"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  func TestCountLinesInCell(t *testing.T) {
    10  	tests := []struct {
    11  		content               string
    12  		maxWidth              int
    13  		expectedNumberOfLines int
    14  	}{
    15  		{
    16  			"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
    17  			0,
    18  			1,
    19  		},
    20  		{
    21  			"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
    22  			15,
    23  			9,
    24  		},
    25  		{
    26  			"Lorem\n" +
    27  				"ipsum dolor sit amet,\n" +
    28  				"consectetur adipiscing elit,\n" +
    29  				"sed do eiusmod tempor incididunt\n" +
    30  				"ut labore et dolore magna aliqua.",
    31  			15,
    32  			11,
    33  		},
    34  	}
    35  	for _, test := range tests {
    36  		actualNumberOfLines := countLinesInCell(test.content, test.maxWidth)
    37  		assert.Equal(t, test.expectedNumberOfLines, actualNumberOfLines)
    38  	}
    39  }
    40  
    41  func TestIsColumnEmpty_NotEmptyScenario(t *testing.T) {
    42  	vulnerabilityRows := []struct {
    43  		Severity         string
    44  		Applicable       string
    45  		SeverityNumValue int
    46  	}{
    47  		{Severity: "Medium", Applicable: "", SeverityNumValue: 2},
    48  		{Severity: "High", Applicable: "Applicable", SeverityNumValue: 3},
    49  		{Severity: "High", Applicable: "", SeverityNumValue: 3},
    50  		{Severity: "Low", Applicable: "", SeverityNumValue: 1},
    51  	}
    52  	rows := reflect.ValueOf(vulnerabilityRows)
    53  
    54  	columnEmpty := isColumnEmpty(rows, 1)
    55  	assert.Equal(t, false, columnEmpty)
    56  }
    57  
    58  func TestIsColumnEmpty_EmptyScenario(t *testing.T) {
    59  	vulnerabilityRows := []struct {
    60  		Severity         string
    61  		Applicable       string
    62  		SeverityNumValue int
    63  	}{
    64  		{Severity: "Medium", Applicable: "", SeverityNumValue: 2},
    65  		{Severity: "High", Applicable: "", SeverityNumValue: 3},
    66  		{Severity: "High", Applicable: "", SeverityNumValue: 3},
    67  		{Severity: "Low", Applicable: "", SeverityNumValue: 1},
    68  	}
    69  	rows := reflect.ValueOf(vulnerabilityRows)
    70  
    71  	columnEmpty := isColumnEmpty(rows, 1)
    72  	assert.Equal(t, true, columnEmpty)
    73  }