-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring, and add helpers for calling functions (#226)
- Loading branch information
1 parent
fa3b9e2
commit eef6f59
Showing
8 changed files
with
131 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2024 Hypermode, Inc. | ||
*/ | ||
|
||
package hostfunctions | ||
|
||
import ( | ||
"hmruntime/functions" | ||
"hmruntime/plugins" | ||
"testing" | ||
) | ||
|
||
func Test_VerifyFunctionSignature(t *testing.T) { | ||
|
||
functions.Functions["myFunction"] = functions.FunctionInfo{ | ||
Function: plugins.FunctionSignature{ | ||
Name: "myFunction", | ||
Parameters: []plugins.Parameter{ | ||
{Name: "param1", Type: plugins.TypeInfo{Name: "int"}}, | ||
{Name: "param2", Type: plugins.TypeInfo{Name: "string"}}, | ||
}, | ||
ReturnType: plugins.TypeInfo{Name: "bool"}, | ||
}} | ||
|
||
err := verifyFunctionSignature("myFunction", "int", "string", "bool") | ||
if err != nil { | ||
t.Errorf("verifyFunctionSignature failed: %v", err) | ||
} | ||
|
||
functions.Functions["anotherFunction"] = functions.FunctionInfo{ | ||
Function: plugins.FunctionSignature{ | ||
Name: "anotherFunction", | ||
ReturnType: plugins.TypeInfo{Name: "bool"}, | ||
}, | ||
} | ||
|
||
err = verifyFunctionSignature("anotherFunction", "bool") | ||
if err != nil { | ||
t.Errorf("verifyFunctionSignature failed: %v", err) | ||
} | ||
|
||
err = verifyFunctionSignature("nonExistentFunction", "float64") | ||
if err == nil { | ||
t.Error("verifyFunctionSignature should have returned an error for non-existent function") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters