github.com/mem/u-root@v2.0.1-0.20181004165302-9b18b4636a33+incompatible/cmds/elvish/edit/location/location_unix_test.go (about)

     1  // +build !windows,!plan9
     2  
     3  package location
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/u-root/u-root/cmds/elvish/eval/vals"
     9  	"github.com/u-root/u-root/cmds/elvish/tt"
    10  )
    11  
    12  var workspaces = vals.MakeMapFromKV(
    13  	// Pattern is always anchored at beginning; this won't match anything
    14  	"bad", "bad",
    15  	// This is a normal pattern.
    16  	"linux", "/src/linux/[^/]+",
    17  	// Pattern may match a trailing /, in which case it only matches subdirs
    18  	"bsd", "/src/bsd/[^/]+/",
    19  )
    20  
    21  func TestMatchWorkspace(t *testing.T) {
    22  	var nilWsInfo *wsInfo
    23  
    24  	tt.Test(t, tt.Fn("matchWorkspace", matchWorkspace), tt.Table{
    25  		tt.Args("/bad", workspaces).Rets(nilWsInfo),
    26  		tt.Args("/src/linux/ws1", workspaces).Rets(
    27  			&wsInfo{"linux", "/src/linux/ws1"}),
    28  		tt.Args("/src/linux/ws1/dir", workspaces).Rets(
    29  			&wsInfo{"linux", "/src/linux/ws1"}),
    30  		tt.Args("/src/bsd/ws1", workspaces).Rets(nilWsInfo),
    31  		tt.Args("/src/bsd/ws1/dir", workspaces).Rets(
    32  			&wsInfo{"bsd", "/src/bsd/ws1/"}),
    33  	})
    34  }