Wrapped ph7_function_name

This commit is contained in:
Brandon Dyck 2022-11-27 18:35:51 -07:00
parent 57f15fdbd4
commit 880c237e6d
2 changed files with 17 additions and 1 deletions

5
ph7.go
View File

@ -247,7 +247,10 @@ func (c *Context) RandomString(length int) (string, error) {
// TODO (*Context).PeekAuxData
// TODO (*Context).PopAuxData
// TODO (*Context).ResultBufLength
// TODO (*Context).FunctionName
func (c *Context) FunctionName() string {
return C.GoString(C.ph7_function_name((*C.ph7_context)(c)))
}
// TODO (*Context).AllocChunk
// TODO (*Context).ReallocChunk

View File

@ -198,6 +198,19 @@ func TestContextThrowError(t *testing.T) {
}
}
func TestFunctionName(t *testing.T) {
const script = "echo doStuff();"
vm, close := setupVM(t, script)
defer close()
f := func(ctx *ph7.Context) error {
_, err := fmt.Fprint(ctx, ctx.FunctionName())
return err
}
mustSucceed(t, vm.CreateFunction("doStuff", CtxFunc(f)))
expectOutput(t, vm, "doStuff")
}
func TestContextResultInt(t *testing.T) {
testResultCode(t, "42", func(ctx *ph7.Context) error {
return ctx.ResultInt(42)