Skip to content

Commit

Permalink
Add TestSobekEmptyString
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Nov 26, 2024
1 parent 5aa78f5 commit 0fbb4c7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions browser/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package browser

import (
"testing"

"github.com/grafana/sobek"
"github.com/stretchr/testify/require"
)

func TestSobekEmptyString(t *testing.T) {
// SobekEmpty string should return true if the argument
// is an empty string or not defined in the Sobek runtime.
rt := sobek.New()
require.NoError(t, rt.Set("sobekEmptyString", sobekEmptyString))
for _, s := range []string{"() => true", "'() => false'"} { // not empty
v, err := rt.RunString(`sobekEmptyString(` + s + `)`)
require.NoError(t, err)
require.Falsef(t, v.ToBoolean(), "got: true, want: false for %q", s)
}
for _, s := range []string{"", " ", "null", "undefined"} { // empty
v, err := rt.RunString(`sobekEmptyString(` + s + `)`)
require.NoError(t, err)
require.Truef(t, v.ToBoolean(), "got: false, want: true for %q", s)
}
}

0 comments on commit 0fbb4c7

Please sign in to comment.