From fd3798b276b237e98218fcb20c9c78e92b3397ff Mon Sep 17 00:00:00 2001 From: Joshua Barton Date: Thu, 30 Jun 2022 17:57:31 -0500 Subject: [PATCH] tests: add test cases around empty values --- internal/lang/functions_test.go | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/internal/lang/functions_test.go b/internal/lang/functions_test.go index b18493c8cd..f2a6f738c4 100644 --- a/internal/lang/functions_test.go +++ b/internal/lang/functions_test.go @@ -323,6 +323,36 @@ func TestFunctions(t *testing.T) { `endswith("hello world", "hello")`, cty.False, }, + { + `endswith("hello world", "")`, + cty.True, + // Completely empty suffix value ( "" ) + // will always evaluate to true for all strings. + }, + { + `endswith("hello world", " ")`, + cty.False, + }, + { + `endswith("", "")`, + cty.True, + }, + { + `endswith("", " ")`, + cty.False, + }, + { + `endswith(" ", "")`, + cty.True, + }, + { + `endswith("", "hello")`, + cty.False, + }, + { + `endswith(" ", "hello")`, + cty.False, + }, }, "file": { @@ -836,6 +866,36 @@ func TestFunctions(t *testing.T) { `startswith("hello world", "world")`, cty.False, }, + { + `startswith("hello world", "")`, + cty.True, + // Completely empty prefix value ( "" ) + // will always evaluate to true for all strings. + }, + { + `startswith("hello world", " ")`, + cty.False, + }, + { + `startswith("", "")`, + cty.True, + }, + { + `startswith("", " ")`, + cty.False, + }, + { + `startswith(" ", "")`, + cty.True, + }, + { + `startswith("", "hello")`, + cty.False, + }, + { + `startswith(" ", "hello")`, + cty.False, + }, }, "strrev": {