-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d19534e
commit 6e67b7c
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: false, want: true 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) | ||
} | ||
} |