From 880c237e6d0db7d6a7d3563e5d68889c85c797e0 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sun, 27 Nov 2022 18:35:51 -0700 Subject: [PATCH] Wrapped ph7_function_name --- ph7.go | 5 ++++- ph7_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ph7.go b/ph7.go index 312c461..ad00c55 100644 --- a/ph7.go +++ b/ph7.go @@ -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 diff --git a/ph7_test.go b/ph7_test.go index ba95f65..d29d31d 100644 --- a/ph7_test.go +++ b/ph7_test.go @@ -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)