Add TestValidateFunc
This commit is contained in:
		
							
								
								
									
										19
									
								
								func_test.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								func_test.go
									
									
									
									
									
								
							| @@ -2,6 +2,8 @@ package salix | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
|  | 	"fmt" | ||||||
|  | 	"reflect" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
|  |  | ||||||
| @@ -197,3 +199,20 @@ func TestFuncCallAssignment(t *testing.T) { | |||||||
| 		t.Error("Expected error, got nil") | 		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") | ||||||
|  | 			} | ||||||
|  | 		}) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user