github.com/vmware/govmomi@v0.51.0/list/path_test.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package list
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func TestToParts(t *testing.T) {
    13  	tests := []struct {
    14  		In  string
    15  		Out []string
    16  	}{
    17  		{
    18  			In:  "/",
    19  			Out: []string{},
    20  		},
    21  		{
    22  			In:  "/foo",
    23  			Out: []string{"foo"},
    24  		},
    25  		{
    26  			In:  "/foo/..",
    27  			Out: []string{},
    28  		},
    29  		{
    30  			In:  "/./foo",
    31  			Out: []string{"foo"},
    32  		},
    33  		{
    34  			In:  "/../foo",
    35  			Out: []string{"foo"},
    36  		},
    37  		{
    38  			In:  "/foo/bar",
    39  			Out: []string{"foo", "bar"},
    40  		},
    41  		{
    42  			In:  "/foo/bar/..",
    43  			Out: []string{"foo"},
    44  		},
    45  		{
    46  			In:  "",
    47  			Out: []string{"."},
    48  		},
    49  		{
    50  			In:  ".",
    51  			Out: []string{"."},
    52  		},
    53  		{
    54  			In:  "foo",
    55  			Out: []string{".", "foo"},
    56  		},
    57  		{
    58  			In:  "foo/..",
    59  			Out: []string{"."},
    60  		},
    61  		{
    62  			In:  "./foo",
    63  			Out: []string{".", "foo"},
    64  		},
    65  		{
    66  			In:  "../foo", // Special case...
    67  			Out: []string{"..", "foo"},
    68  		},
    69  		{
    70  			In:  "foo/bar/..",
    71  			Out: []string{".", "foo"},
    72  		},
    73  	}
    74  
    75  	for _, test := range tests {
    76  		out := ToParts(test.In)
    77  		if !reflect.DeepEqual(test.Out, out) {
    78  			t.Errorf("Expected %s to return: %#v, actual: %#v", test.In, test.Out, out)
    79  		}
    80  	}
    81  }