github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/path/base_test.go (about) 1 package path_test 2 3 import ( 4 "context" 5 "testing" 6 7 . "github.com/smartystreets/goconvey/convey" 8 9 "github.com/MontFerret/ferret/pkg/runtime/values" 10 "github.com/MontFerret/ferret/pkg/stdlib/path" 11 ) 12 13 func TestBase(t *testing.T) { 14 Convey("When arg is not passed", t, func() { 15 Convey("It should return an error", func() { 16 var err error 17 _, err = path.Base(context.Background()) 18 19 So(err, ShouldBeError) 20 }) 21 }) 22 23 Convey("Wrong argument", t, func() { 24 var err error 25 _, err = path.Base(context.Background(), values.NewInt(0)) 26 27 So(err, ShouldBeError) 28 }) 29 30 Convey("Base('') should return '.'", t, func() { 31 out, _ := path.Base( 32 context.Background(), 33 values.NewString(""), 34 ) 35 36 So(out, ShouldEqual, ".") 37 }) 38 39 Convey("Base('.') should return '.'", t, func() { 40 out, _ := path.Base( 41 context.Background(), 42 values.NewString("."), 43 ) 44 45 So(out, ShouldEqual, ".") 46 }) 47 48 Convey("Base('pkg/path/base.go') should return 'base.go'", t, func() { 49 out, _ := path.Base( 50 context.Background(), 51 values.NewString("pkg/path/base.go"), 52 ) 53 54 So(out, ShouldEqual, "base.go") 55 }) 56 }