From 89f75f1709b6506f903d91af8aa1d531990c79d8 Mon Sep 17 00:00:00 2001 From: Elara6331 Date: Mon, 12 Feb 2024 11:05:19 -0800 Subject: [PATCH] Add TestValidateFunc --- func_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/func_test.go b/func_test.go index c73be69..0b86eac 100644 --- a/func_test.go +++ b/func_test.go @@ -2,6 +2,8 @@ package salix import ( "errors" + "fmt" + "reflect" "strings" "testing" @@ -197,3 +199,20 @@ func TestFuncCallAssignment(t *testing.T) { t.Error("Expected error, got nil") } } + +func TestValidateFunc(t *testing.T) { + testCases := []reflect.Type{ + reflect.TypeFor[func()](), // Template functions must return at least one value + reflect.TypeFor[func() (x, y int)](), // Second return value must be an error + reflect.TypeFor[func() (x, y, z int)](), // Template functions cannot have more than two return values + } + + for index, testCase := range testCases { + t.Run(fmt.Sprint(index), func(t *testing.T) { + err := validateFunc(testCase, ast.Bool{Value: true, Position: testPos(t)}) + if err == nil { + t.Error("Expected error, got nil") + } + }) + } +}