github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/lists/crop_test.go (about)

     1  package lists_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test/count"
     7  	"github.com/lmorg/murex/utils/json"
     8  	"github.com/lmorg/murex/utils/lists"
     9  )
    10  
    11  func TestCropPartial(t *testing.T) {
    12  	type testCropPartialT struct {
    13  		List    []string
    14  		Partial string
    15  		Output  []string
    16  	}
    17  
    18  	tests := []testCropPartialT{
    19  		{
    20  			List:    []string{"Foo", "Bar"},
    21  			Partial: "",
    22  			Output:  []string{"Foo", "Bar"},
    23  		},
    24  		{
    25  			List:    []string{"Foo", "Bar"},
    26  			Partial: "F",
    27  			Output:  []string{"oo"},
    28  		},
    29  		{
    30  			List:    []string{"Foo", "Bar"},
    31  			Partial: "B",
    32  			Output:  []string{"ar"},
    33  		},
    34  		{
    35  			List:    []string{"Foo", "Bar", "Foobar"},
    36  			Partial: "Fo",
    37  			Output:  []string{"o", "obar"},
    38  		},
    39  		{
    40  			List:    []string{"Foo", "Bar", "Foobar"},
    41  			Partial: "Foo",
    42  			Output:  []string{"", "bar"},
    43  		},
    44  		{
    45  			List:    []string{"Foo", "Bar", "Foobar"},
    46  			Partial: "Foob",
    47  			Output:  []string{"ar"},
    48  		},
    49  	}
    50  
    51  	count.Tests(t, len(tests))
    52  
    53  	for i, test := range tests {
    54  		jExp := json.LazyLogging(test.Output)
    55  		actual := lists.CropPartial(test.List, test.Partial)
    56  		jAct := json.LazyLogging(actual)
    57  
    58  		if jExp != jAct {
    59  			t.Errorf("Test %d failed", i)
    60  			t.Logf("  List:     %s", json.LazyLogging(test.List))
    61  			t.Logf("  Partial:  '%s'", test.Partial)
    62  			t.Logf("  Expected: %s", jExp)
    63  			t.Logf("  Actual:   %s", jAct)
    64  		}
    65  	}
    66  }