Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-registry all functions #153

Merged
merged 4 commits into from
Mar 29, 2018
Merged
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
13 changes: 9 additions & 4 deletions core/mapper/exprmapper/exprmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ import (

"reflect"

"github.com/TIBCOSoftware/flogo-lib/core/data"
"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression"
"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/ref"
"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/json"
"github.com/TIBCOSoftware/flogo-lib/core/data"
"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/ref"
"github.com/TIBCOSoftware/flogo-lib/logger"

//Pre registry all function for now
_ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/number/random"
_ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/concat"
_ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/equals"
_ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/equalsignorecase"
_ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/length"
)

var log = logger.GetLogger("mapper")
Expand Down Expand Up @@ -178,7 +185,6 @@ func SetAttribute(fieldName string, value interface{}, outputScope data.Scope) e
return nil
}


func RemovePrefixInput(str string) string {
if str != "" && strings.HasPrefix(str, MAP_TO_INPUT) {
//Remove $INPUT for mapTo
Expand All @@ -190,4 +196,3 @@ func RemovePrefixInput(str string) string {
}
return str
}

9 changes: 2 additions & 7 deletions core/mapper/exprmapper/function/string/equals/equals.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package equals

import (
"strings"

"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
Expand All @@ -23,10 +21,7 @@ func (s *Equals) GetName() string {
func (s *Equals) GetCategory() string {
return "string"
}
func (s *Equals) Eval(str, str2 string, ignoreCase bool) bool {
log.Debugf(`Reports whether "%s" equels "%s" with ignore case %s`, str, str2, ignoreCase)
if ignoreCase {
return strings.EqualFold(str, str2)
}
func (s *Equals) Eval(str, str2 string) bool {
log.Debugf(`Reports whether "%s" equals "%s" `, str, str2)
return str == str2
}
18 changes: 4 additions & 14 deletions core/mapper/exprmapper/function/string/equals/equals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,18 @@ import (
var s = &Equals{}

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

final2 := s.Eval("TIBCO", "tibco", true)
final2 := s.Eval("TIBCO", "tibco")
fmt.Println(final2)
assert.Equal(t, true, final2)
assert.Equal(t, false, final2)

}

func TestExpression(t *testing.T) {
fun, err := expression.NewFunctionExpression(`string.equals("TIBCO FLOGO", "TIBCO FLOGO", false)`).GetFunction()
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[0])
}

func TestExpressionIgnoreCase(t *testing.T) {
fun, err := expression.NewFunctionExpression(`string.equals("TIBCO flogo", "TIBCO FLOGO", true)`).GetFunction()
fun, err := expression.NewFunctionExpression(`string.equals("TIBCO FLOGO", "TIBCO FLOGO")`).GetFunction()
assert.Nil(t, err)
assert.NotNil(t, fun)
v, err := fun.Eval()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package equalsignorecase

import (
"strings"

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

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

type EqualsIgnoreCase struct {
}

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

func (s *EqualsIgnoreCase) GetName() string {
return "equalsIgnoreCase"
}

func (s *EqualsIgnoreCase) GetCategory() string {
return "string"
}
func (s *EqualsIgnoreCase) Eval(str, str2 string) bool {
log.Debugf(`Reports whether "%s" equels "%s" with ignore case`, str, str2)
return strings.EqualFold(str, str2)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package equalsignorecase

import (
"fmt"
"testing"

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

var s = &EqualsIgnoreCase{}

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

final2 := s.Eval("TIBCO", "tibco")
fmt.Println(final2)
assert.Equal(t, true, final2)

}

func TestExpression(t *testing.T) {
fun, err := expression.NewFunctionExpression(`string.equalsIgnoreCase("TIBCO FLOGO", "TIBCO FLOGO")`).GetFunction()
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[0])
}

func TestExpressionIgnoreCase(t *testing.T) {
fun, err := expression.NewFunctionExpression(`string.equalsIgnoreCase("TIBCO flogo", "TIBCO FLOGO")`).GetFunction()
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[0])
}