Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ZauberNerd committed Dec 9, 2021
1 parent 58790da commit 439738e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions pkg/exprparser/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (impl interperterImpl) join(array reflect.Value, sep reflect.Value) (string
if array.Kind() == reflect.Slice {
var items []string
for i := 0; i < array.Len(); i++ {
fmt.Printf("%v\n", array.Index(i).Kind())
items = append(items, impl.coerceToString(array.Index(i)).String())
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/exprparser/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ func TestFunctionEndsWith(t *testing.T) {
}
}

func TestFunctionJoin(t *testing.T) {
table := []struct {
input string
expected interface{}
name string
}{
{"join(fromJSON('[\"a\", \"b\"]'), ',') }}", "a,b", "join-arr"},
}

env := &EvaluationEnvironment{}

for _, tt := range table {
t.Run(tt.name, func(t *testing.T) {
output, _, err := NewInterpeter(env, Config{}).Evaluate(tt.input)
assert.Nil(t, err)

assert.Equal(t, tt.expected, output)
})
}
}

func TestFunctionToJSON(t *testing.T) {
table := []struct {
input string
Expand Down
5 changes: 1 addition & 4 deletions pkg/runner/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ func (ee expressionEvaluator) Evaluate(in string) (string, bool, error) {
return "", false, err
}

fmt.Printf("%+v", evaluated)

return "", false, nil
return fmt.Sprint(evaluated), false, nil
}

func (ee expressionEvaluator) Interpolate(in string) string {
Expand All @@ -98,7 +96,6 @@ const (
)

func (ee expressionEvaluator) InterpolateWithStringCheck(in string) (string, bool) {

output := ""
skip := 0
// replacementIndex := ""
Expand Down
8 changes: 4 additions & 4 deletions pkg/runner/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func TestEvaluate(t *testing.T) {
{"'my text'", "my text", ""},
{"contains('my text', 'te')", "true", ""},
{"contains('my TEXT', 'te')", "true", ""},
{"contains(['my text'], 'te')", "false", ""},
{"contains(['foo','bar'], 'bar')", "true", ""},
{"contains(fromJSON('[\"my text\"]'), 'te')", "false", ""},
{"contains(fromJSON('[\"foo\",\"bar\"]'), 'bar')", "true", ""},
{"startsWith('hello world', 'He')", "true", ""},
{"endsWith('hello world', 'ld')", "true", ""},
{"format('0:{0} 2:{2} 1:{1}', 'zero', 'one', 'two')", "0:zero 2:two 1:one", ""},
{"join(['hello'],'octocat')", "hello octocat", ""},
{"join(['hello','mona','the'],'octocat')", "hello mona the octocat", ""},
{"join(fromJSON('[\"hello\"]'),'octocat')", "hello octocat", ""},
{"join(fromJSON('[\"hello\",\"mona\",\"the\"]'),'octocat')", "hello mona the octocat", ""},
{"join('hello','mona')", "hello mona", ""},
{"toJSON({'foo':'bar'})", "{\n \"foo\": \"bar\"\n}", ""},
{"toJson({'foo':'bar'})", "{\n \"foo\": \"bar\"\n}", ""},
Expand Down

0 comments on commit 439738e

Please sign in to comment.