github.com/TIBCOSoftware/flogo-lib@v0.5.9/core/mapper/exprmapper/function/string/substring/substring_test.go (about) 1 package substring 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 var s = &Substring{} 11 12 func TestSubstring(t *testing.T) { 13 // Substring(string, int, int) 14 // string : input string 15 // int : starting position for substring 16 // int : length of the substring 17 18 // Should produce "Flogo" 19 sub := s.Eval("Flogo is the most awesome project ever", 0, 5) 20 fmt.Printf("Result [%s] should be equal to: Flogo\n", sub) 21 assert.Equal(t, "Flogo", sub) 22 23 // Should produce "awesome" 24 sub = s.Eval("Flogo is the most awesome project ever", 18, 7) 25 fmt.Printf("Result [%s] should be equal to: awesome\n", sub) 26 assert.Equal(t, "awesome", sub) 27 28 // Should produce "ever" 29 // When setting the length to negative, it will always start at the end of 30 // the string and work backwards (ignoring the starting position) 31 sub = s.Eval("Flogo is the most awesome project ever", 0, -4) 32 fmt.Printf("Result [%s] should be equal to: ever\n", sub) 33 assert.Equal(t, "ever", sub) 34 35 // Should produce "ever" 36 // When setting the length to negative, it will always start at the end of 37 // the string and work backwards (ignoring the starting position) 38 sub = s.Eval("Flogo is the most awesome project ever", 2, -4) 39 fmt.Printf("Result [%s] should be equal to: ever\n", sub) 40 assert.Equal(t, "ever", sub) 41 42 // Should produce "" 43 // When setting the length to a negative number higher than the length of 44 // the string it will return an empty string 45 sub = s.Eval("Flogo is the most awesome project ever", 0, -40) 46 fmt.Printf("Result [%s] should be equal to: <empty>\n", sub) 47 assert.Equal(t, "", sub) 48 }