From 6e67b7cc7f01c8046b01650d007b8d643a95206a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 25 Nov 2024 10:42:35 -0500 Subject: [PATCH] Add TestSobekEmptyString --- browser/helpers_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 browser/helpers_test.go diff --git a/browser/helpers_test.go b/browser/helpers_test.go new file mode 100644 index 000000000..d2cda1170 --- /dev/null +++ b/browser/helpers_test.go @@ -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) + } +}