Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions core/mapper/exprmapper/function/string/match/match.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package match

import (
"regexp"

"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function"
"github.com/TIBCOSoftware/flogo-lib/logger"
)

var log = logger.GetLogger("match-function")

type Match struct {
}

func init() {
function.Registry(&Match{})
}

func (s *Match) GetName() string {
return "match"
}

func (s *Match) GetCategory() string {
return "string"
}
func (s *Match) Eval(expr string, inp string) bool {

match, _ := regexp.MatchString(expr, inp)
log.Infof(`Input "%v" matches: "%v" `, inp, match)
return match
}
28 changes: 28 additions & 0 deletions core/mapper/exprmapper/function/string/match/match_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package match

import (
"fmt"
"testing"

"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression"
"github.com/stretchr/testify/assert"
)

var s = &Match{}

func TestStaticFunc_Starts_with(t *testing.T) {
final1 := s.Eval("p([a-z]+)ch", "peach")
fmt.Println(final1)
assert.Equal(t, true, final1)

}

func TestExpression(t *testing.T) {
fun, err := expression.ParseExpression(`string.match("p([a-z]+)ch", "peach")`)
assert.Nil(t, err)
assert.NotNil(t, fun)
v, err := fun.Eval()
assert.Nil(t, err)
assert.NotNil(t, v)
assert.Equal(t, true, v)
}
31 changes: 31 additions & 0 deletions core/mapper/exprmapper/function/string/tostring/tostring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tostring

import (
"fmt"

"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function"
"github.com/TIBCOSoftware/flogo-lib/logger"
)

var log = logger.GetLogger("tostring-function")

type ToString struct {
}

func init() {
function.Registry(&ToString{})
}

func (s *ToString) GetName() string {
return "toString"
}

func (s *ToString) GetCategory() string {
return "string"
}
func (s *ToString) Eval(inp interface{}) string {

result := fmt.Sprintf("%v", inp)
log.Debugf(`Converts value to a simple string: "%s" `, result)
return result
}
32 changes: 32 additions & 0 deletions core/mapper/exprmapper/function/string/tostring/tostring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tostring

import (
"fmt"
"testing"

"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression"
"github.com/stretchr/testify/assert"
)

var s = &ToString{}

func TestStaticFunc_Starts_with(t *testing.T) {
final1 := s.Eval(1)
fmt.Println(final1)
assert.Equal(t, "1", final1)

final2 := s.Eval(1.23)
fmt.Println(final2)
assert.Equal(t, "1.23", final2)

}

func TestExpression(t *testing.T) {
fun, err := expression.ParseExpression(`string.tostring(3.456)`)
assert.Nil(t, err)
assert.NotNil(t, fun)
v, err := fun.Eval()
assert.Nil(t, err)
assert.NotNil(t, v)
assert.Equal(t, "3.456", v)
}