本文整理匯總了Golang中fubsy/types.FuObject.ActionExpand方法的典型用法代碼示例。如果您正苦於以下問題:Golang FuObject.ActionExpand方法的具體用法?Golang FuObject.ActionExpand怎麽用?Golang FuObject.ActionExpand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fubsy/types.FuObject
的用法示例。
在下文中一共展示了FuObject.ActionExpand方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: assertExpand
func assertExpand(
t *testing.T, ns types.Namespace, expect []string, obj types.FuObject) {
if ns == nil {
ns = types.NewValueMap()
}
actualobj, err := obj.ActionExpand(ns, nil)
assert.Nil(t, err)
// convert FuList of FileNode to slice of string
actualstr := make([]string, len(actualobj.List()))
for i, obj := range actualobj.List() {
actualstr[i] = obj.ValueString()
}
assert.Equal(t, expect, actualstr)
}
示例2: Test_evaluateCall_no_expand
func Test_evaluateCall_no_expand(t *testing.T) {
calls := 0
fn_foo := func(argsource types.ArgSource) (types.FuObject, []error) {
calls++
return types.MakeFuString("arg: " + argsource.Args()[0].ValueString()), nil
}
foo := types.NewFixedFunction("foo", 1, fn_foo)
rt := minimalRuntime()
args := RuntimeArgs{runtime: rt}
// call bar() with an arg that needs to be expanded to test that
// expansion does *not* happen -- evaluateCall() doesn't know
// which phase it's in, so it has to rely on someone else to
// ActionExpand() each value in the build phase
args.SetArgs([]types.FuObject{types.MakeFuString(">$src<")})
result, errs := rt.evaluateCall(foo, args, nil)
assert.Equal(t, 1, calls)
assert.Equal(t, types.MakeFuString("arg: >$src<"), result)
if len(errs) != 0 {
t.Errorf("expected no errors, but got: %v", errs)
}
// now make a value that expands to three values
expansion := types.MakeStringList("a", "b", "c")
var val types.FuObject = types.NewStubObject("val", expansion)
valexp, _ := val.ActionExpand(nil, nil)
assert.Equal(t, expansion, valexp) // this actually tests StubObject
// call foo() with that expandable value, and make sure it is
// really called with the unexpanded value
args.SetArgs([]types.FuObject{val})
result, errs = rt.evaluateCall(foo, args, nil)
assert.Equal(t, 2, calls)
assert.Equal(t, types.MakeFuString("arg: val"), result)
if len(errs) != 0 {
t.Errorf("expected no errors, but got: %v", errs)
}
}