github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/easy/yamlx/directive_test.go (about)

     1  package yamlx
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_hasTostrModifier(t *testing.T) {
    10  	testCases := []struct {
    11  		path     string
    12  		isTostr  bool
    13  		modifier string
    14  	}{
    15  		{"0.step.script.0", false, ""},
    16  		{"step|@tostr", true, "|@tostr"},
    17  		{`friends.#(last="Murphy")#.@tostr`, true, ".@tostr"},
    18  		{`friends.#(last="Murphy")#.@tostr.@reverse`, true, ".@tostr.@reverse"},
    19  	}
    20  	for _, tc := range testCases {
    21  		ok, modifier := hasTostrModifier(tc.path)
    22  		assert.Equalf(t, tc.isTostr, ok, "path= %v", tc.path)
    23  		assert.Equalf(t, tc.modifier, modifier, "path= %v", tc.path)
    24  	}
    25  }