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

     1  package pathsplit_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/pathsplit"
     9  )
    10  
    11  type testSplitT struct {
    12  	Path  string
    13  	Split []string
    14  	Error bool
    15  }
    16  
    17  func TestSplit(t *testing.T) {
    18  	tests := []testSplitT{
    19  		{
    20  			Path:  "",
    21  			Error: true,
    22  		},
    23  		{
    24  			Path:  "/",
    25  			Error: true,
    26  		},
    27  		{
    28  			Path:  "//",
    29  			Split: []string{""},
    30  		},
    31  		{
    32  			Path:  "##",
    33  			Split: []string{""},
    34  		},
    35  		{
    36  			Path:  ".0",
    37  			Split: []string{"0"},
    38  		},
    39  		{
    40  			Path:  ":hello:world!",
    41  			Split: []string{"hello", "world!"},
    42  		},
    43  	}
    44  
    45  	count.Tests(t, len(tests))
    46  
    47  	for i, test := range tests {
    48  		actual, err := pathsplit.Split(test.Path)
    49  
    50  		if (err != nil) != test.Error {
    51  			t.Errorf("Error mismatch in test %d", i)
    52  			t.Logf("Path:     '%s'", test.Path)
    53  			t.Logf("Expected:  %s", json.LazyLogging(test.Split))
    54  			t.Logf("Actual:    %s", json.LazyLogging(actual))
    55  			t.Logf("exp err:   %v", test.Error)
    56  			t.Logf("act err:   %v", err)
    57  		}
    58  
    59  		if json.LazyLogging(actual) != json.LazyLogging(test.Split) {
    60  			t.Errorf("Output value doesn't match expected in test %d", i)
    61  			t.Logf("Path:     '%s'", test.Path)
    62  			t.Logf("Expected:  %s", json.LazyLogging(test.Split))
    63  			t.Logf("Actual:    %s", json.LazyLogging(actual))
    64  			t.Logf("exp err:   %v", test.Error)
    65  			t.Logf("act err:   %v", err)
    66  		}
    67  	}
    68  }