github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/path/clean_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 TestClean(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.Clean(context.Background())
    18  
    19  			So(err, ShouldBeError)
    20  		})
    21  	})
    22  
    23  	Convey("Wrong argument", t, func() {
    24  		var err error
    25  		_, err = path.Clean(context.Background(), values.NewInt(0))
    26  
    27  		So(err, ShouldBeError)
    28  	})
    29  
    30  	Convey("Clean('pkg//path//clean.go') should return 'pkg/path/clean.go'", t, func() {
    31  		out, _ := path.Clean(
    32  			context.Background(),
    33  			values.NewString("pkg//path//clean.go"),
    34  		)
    35  
    36  		So(out, ShouldEqual, "pkg/path/clean.go")
    37  	})
    38  
    39  	Convey("Clean('/cmd/main/../../..') should return '/'", t, func() {
    40  		out, _ := path.Clean(
    41  			context.Background(),
    42  			values.NewString("/cmd/main/../../.."),
    43  		)
    44  
    45  		So(out, ShouldEqual, "/")
    46  	})
    47  }