Skip to content

Commit

Permalink
add correct unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Esonhugh committed Jun 23, 2023
1 parent 8a12f81 commit de6cebc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 49 deletions.
10 changes: 10 additions & 0 deletions dsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import (
"github.com/stretchr/testify/require"
)

func TestIndex(t *testing.T) {
index, err := govaluate.NewEvaluableExpressionWithFunctions("index(split(url, '.', -1), 1) == 'example'", DefaultHelperFunctions)
require.Nil(t, err, "could not compile index")

result, err := index.Evaluate(map[string]interface{}{"url": "https://www.example.com"})
require.Nil(t, err, "could not evaluate index")
require.Equal(t, true, result, "could not get index data")
}

func TestDSLURLEncodeDecode(t *testing.T) {
encoded, err := DefaultHelperFunctions["url_encode"]("&test\"")
require.Nil(t, err, "could not url encode")
Expand Down Expand Up @@ -227,6 +236,7 @@ func TestDslExpressions(t *testing.T) {
`hex_decode("6161")`: "aa",
`len("Hello")`: float64(5),
`len(1234)`: float64(4),
`len(split("1.2.3.4",'.',-1))`: float64(4),
`contains("Hello", "lo")`: true,
`starts_with("Hello", "He")`: true,
`ends_with("Hello", "lo")`: true,
Expand Down
49 changes: 0 additions & 49 deletions test/slice_test.go

This file was deleted.

0 comments on commit de6cebc

Please sign in to comment.