github.com/charlievieth/fastwalk@v1.0.3/dirent_export_test.go (about)

     1  package fastwalk
     2  
     3  import (
     4  	"fmt"
     5  	"io/fs"
     6  	"os"
     7  	"testing"
     8  	"time"
     9  )
    10  
    11  // Export funcs for testing (because I'm too lazy to move the
    12  // symlink() and writeFile() funcs)
    13  
    14  func FormatFileInfo(fi fs.FileInfo) string {
    15  	return fmt.Sprintf("%+v", struct {
    16  		Name    string
    17  		Size    int64
    18  		Mode    os.FileMode
    19  		ModTime time.Time
    20  		IsDir   bool
    21  		Sys     string
    22  	}{
    23  		Name:    fi.Name(),
    24  		Size:    fi.Size(),
    25  		Mode:    fi.Mode(),
    26  		ModTime: fi.ModTime(),
    27  		IsDir:   fi.IsDir(),
    28  		Sys:     fmt.Sprintf("%+v", fi.Sys()),
    29  	})
    30  }
    31  
    32  func TestCleanRootPath(t *testing.T) {
    33  	tests := map[string]string{
    34  		"":      "",
    35  		"/":     "/",
    36  		"//":    "/",
    37  		"/foo":  "/foo",
    38  		"/foo/": "/foo",
    39  		"a":     "a",
    40  		`C:/`:   `C:`,
    41  	}
    42  	if os.PathSeparator != '/' {
    43  		const sep = string(os.PathSeparator)
    44  		tests["C:"+sep] = `C:`
    45  		tests["C:"+sep+sep] = `C:`
    46  		tests[sep+sep] = sep
    47  	}
    48  	for in, want := range tests {
    49  		got := cleanRootPath(in)
    50  		if got != want {
    51  			t.Errorf("cleanRootPath(%q) = %q; want: %q", in, got, want)
    52  		}
    53  	}
    54  }