github.com/richardwilkes/toolbox@v1.121.0/xio/fs/split_test.go (about)

     1  // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the Mozilla Public
     4  // License, version 2.0. If a copy of the MPL was not distributed with
     5  // this file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  //
     7  // This Source Code Form is "Incompatible With Secondary Licenses", as
     8  // defined by the Mozilla Public License, version 2.0.
     9  
    10  package fs_test
    11  
    12  import (
    13  	"path/filepath"
    14  	"testing"
    15  
    16  	"github.com/richardwilkes/toolbox/check"
    17  	"github.com/richardwilkes/toolbox/xio/fs"
    18  )
    19  
    20  type splitData struct {
    21  	in  string
    22  	out []string
    23  }
    24  
    25  func TestSplit(t *testing.T) {
    26  	full := string([]rune{filepath.Separator})
    27  	data := []splitData{
    28  		{
    29  			in:  "/one/two.txt",
    30  			out: []string{full, "one", "two.txt"},
    31  		},
    32  		{
    33  			in:  "/one",
    34  			out: []string{full, "one"},
    35  		},
    36  		{
    37  			in:  "one",
    38  			out: []string{".", "one"},
    39  		},
    40  		{
    41  			in:  "/one////two.txt",
    42  			out: []string{full, "one", "two.txt"},
    43  		},
    44  		{
    45  			in:  "/one//..//two.txt",
    46  			out: []string{full, "two.txt"},
    47  		},
    48  		{
    49  			in:  "/one/../..//two.txt",
    50  			out: []string{full, "two.txt"},
    51  		},
    52  		{
    53  			in:  "/one/../..//two.txt/",
    54  			out: []string{full, "two.txt"},
    55  		},
    56  		{
    57  			in:  "/one/../..//two.txt/.",
    58  			out: []string{full, "two.txt"},
    59  		},
    60  	}
    61  	for i, one := range data {
    62  		check.Equal(t, one.out, fs.Split(one.in), "%d", i)
    63  	}
    64  }