Add TestValidateFunc

This commit is contained in:
Elara 2024-02-12 11:05:19 -08:00
parent eacbd633bd
commit 89f75f1709
1 changed files with 19 additions and 0 deletions

View File

@ -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")
}
})
}
}