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
30 changes: 30 additions & 0 deletions core/mapper/exprmapper/function/string/contains/contains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package contains

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

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

type Contains struct {
}

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

func (co *Contains) GetName() string {
return "contains"
}

func (co *Contains) GetCategory() string {
return "string"
}

func (co *Contains) Eval(s string, substr string) bool {
// Documentation to function: https://golang.org/pkg/strings/#Contains
log.Debugf("Calling function contains with parameters [s = %s, substr = %s]", s, substr)
return strings.Contains(s, substr);
}
21 changes: 21 additions & 0 deletions core/mapper/exprmapper/function/string/contains/contains_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package contains

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

var co = &Contains{}

func TestContains(t *testing.T) {

sub := co.Eval("Flogo is the most awesome project ever", "awesome")
fmt.Printf("Result [%t] should be equal to: true\n", sub)
assert.Equal(t, true, sub)

sub = co.Eval("Flogo is the most awesome project ever", "XXXXXXXX")
fmt.Printf("Result [%t] should be equal to: false\n", sub)
assert.Equal(t, false, sub)

}
30 changes: 30 additions & 0 deletions core/mapper/exprmapper/function/string/containsany/containsany.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package containsany

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

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

type Containsany struct {
}

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

func (co *Containsany) GetName() string {
return "containsany"
}

func (co *Containsany) GetCategory() string {
return "string"
}

func (co *Containsany) Eval(s string, chars string) bool {
// Documentation to function: https://golang.org/pkg/strings/#ContainsAny
log.Debugf("Calling function containsany with parameters [s = %s, chars = %s]", s, chars)
return strings.ContainsAny(s, chars);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package containsany

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

var co = &Containsany{}

func TestContainsany(t *testing.T) {

sub := co.Eval("Flogo is the most awesome project ever", "o")
fmt.Printf("Result [%t] should be equal to: true\n", sub)
assert.Equal(t, true, sub)

sub = co.Eval("Flogo is the most awesome project ever", "i & z")
fmt.Printf("Result [%t] should be equal to: true\n", sub)
assert.Equal(t, true, sub)

sub = co.Eval("Flogo is the most awesome project ever", "z & go")
fmt.Printf("Result [%t] should be equal to: true\n", sub)
assert.Equal(t, true, sub)

sub = co.Eval("Flogo is the most awesome project ever", "z")
fmt.Printf("Result [%t] should be equal to: false\n", sub)
assert.Equal(t, false, sub)
}
30 changes: 30 additions & 0 deletions core/mapper/exprmapper/function/string/count/count.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package count

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

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

type Count struct {
}

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

func (co *Count) GetName() string {
return "count"
}

func (co *Count) GetCategory() string {
return "string"
}

func (co *Count) Eval(s string, substr string) int {
// Documentation to function: https://golang.org/pkg/strings/#Count
log.Debugf("Calling function count with parameters [s = %s, substr = %s]", s, substr)
return strings.Count(s, substr);
}
28 changes: 28 additions & 0 deletions core/mapper/exprmapper/function/string/count/count_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package count

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

var co = &Count{}

func TestCount(t *testing.T) {

sub := co.Eval("Flogo is the most awesome project ever", "Flogo")
fmt.Printf("Result [%d] should be equal to: 1\n", sub)
assert.Equal(t, 1, sub)

sub = co.Eval("Flogo is the most awesome project ever", "flogo")
fmt.Printf("Result [%d] should be equal to: 0\n", sub)
assert.Equal(t, 0, sub)

sub = co.Eval("Flogo is the most awesome project ever", "XXXXXXXX")
fmt.Printf("Result [%d] should be equal to: 0\n", sub)
assert.Equal(t, 0, sub)

sub = co.Eval("Flogo is the most awesome project ever", "o")
fmt.Printf("Result [%d] should be equal to: 5\n", sub)
assert.Equal(t, 5, sub)
}
30 changes: 30 additions & 0 deletions core/mapper/exprmapper/function/string/hasprefix/hasprefix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hasprefix

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

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

type Hasprefix struct {
}

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

func (ha *Hasprefix) GetName() string {
return "hasprefix"
}

func (ha *Hasprefix) GetCategory() string {
return "string"
}

func (ha *Hasprefix) Eval(s string, prefix string) bool {
// Documentation to function: https://golang.org/pkg/strings/#HasPrefix
log.Debugf("Calling function hasprefix with parameters [s = %s, prefix = %s]", s, prefix)
return strings.HasPrefix(s, prefix);
}
29 changes: 29 additions & 0 deletions core/mapper/exprmapper/function/string/hasprefix/hasprefix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package hasprefix

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

var ha = &Hasprefix{}

func TestHasprefix(t *testing.T) {

sub := ha.Eval("Flogo is the most awesome project ever", "Flogo")
fmt.Printf("Result [%t] should be equal to: true\n", sub)
assert.Equal(t, true, sub)

sub = ha.Eval("Flogo is the most awesome project ever", "flogo")
fmt.Printf("Result [%t] should be equal to: false\n", sub)
assert.Equal(t, false, sub)

sub = ha.Eval("Flogo is the most awesome project ever", "Any other thing")
fmt.Printf("Result [%t] should be equal to: false\n", sub)
assert.Equal(t, false, sub)

sub = ha.Eval("Flogo is the most awesome project ever", "")
fmt.Printf("Result [%t] should be equal to: true\n", sub)
assert.Equal(t, true, sub)

}
30 changes: 30 additions & 0 deletions core/mapper/exprmapper/function/string/hassuffix/hassuffix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hassuffix

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

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

type Hassuffix struct {
}

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

func (ha *Hassuffix) GetName() string {
return "hassuffix"
}

func (ha *Hassuffix) GetCategory() string {
return "string"
}

func (ha *Hassuffix) Eval(s string, suffix string) bool {
// Documentation to function: https://golang.org/pkg/strings/#HasSuffix
log.Debugf("Calling function hassuffix with parameters [s = %s, suffix = %s]", s, suffix)
return strings.HasSuffix(s, suffix);
}
29 changes: 29 additions & 0 deletions core/mapper/exprmapper/function/string/hassuffix/hassuffix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package hassuffix

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

var ha = &Hassuffix{}

func TestHassuffix(t *testing.T) {

sub := ha.Eval("Flogo is the most awesome project ever", "ever")
fmt.Printf("Result [%t] should be equal to: true\n", sub)
assert.Equal(t, true, sub)

sub = ha.Eval("Flogo is the most awesome project ever", "EVER")
fmt.Printf("Result [%t] should be equal to: false\n", sub)
assert.Equal(t, false, sub)

sub = ha.Eval("Flogo is the most awesome project ever", "XXXX")
fmt.Printf("Result [%t] should be equal to: false\n", sub)
assert.Equal(t, false, sub)

sub = ha.Eval("Flogo is the most awesome project ever", "")
fmt.Printf("Result [%t] should be equal to: true\n", sub)
assert.Equal(t, true, sub)

}
30 changes: 30 additions & 0 deletions core/mapper/exprmapper/function/string/index/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package index

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

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

type Index struct {
}

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

func (in *Index) GetName() string {
return "index"
}

func (in *Index) GetCategory() string {
return "string"
}

func (in *Index) Eval(s string, substr string) int {
// Documentation to function: https://golang.org/pkg/strings/#Index
log.Debugf("Calling function index with parameters [s = %s, substr = %s]", s, substr)
return strings.Index(s, substr);
}
25 changes: 25 additions & 0 deletions core/mapper/exprmapper/function/string/index/index_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package index

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

var in = &Index{}

func TestIndex(t *testing.T) {

sub := in.Eval("Flogo is the most awesome project ever", "Flogo")
fmt.Printf("Result [%d] should be equal to: 0\n", sub)
assert.Equal(t, 0, sub)

sub = in.Eval("Flogo is the most awesome project ever", "flogo")
fmt.Printf("Result [%d] should be equal to: -1\n", sub)
assert.Equal(t, -1, sub)

sub = in.Eval("Flogo is the most awesome project ever", "awesome")
fmt.Printf("Result [%d] should be equal to: 18\n", sub)
assert.Equal(t, 18, sub)

}
30 changes: 30 additions & 0 deletions core/mapper/exprmapper/function/string/join/join.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package join

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

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

type Join struct {
}

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

func (jo *Join) GetName() string {
return "join"
}

func (jo *Join) GetCategory() string {
return "string"
}

func (jo *Join) Eval(a []string, sep string) string {
// Documentation to function: https://golang.org/pkg/strings/#Join
log.Debugf("Calling function join with parameters [a = %s, sep = %s]", a, sep)
return strings.Join(a, sep);
}
Loading