本文整理匯總了Golang中github.com/juju/juju/environs/simplestreams.Filter函數的典型用法代碼示例。如果您正苦於以下問題:Golang Filter函數的具體用法?Golang Filter怎麽用?Golang Filter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Filter函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestFilterRemovesNonMatches
func (*simplestreamsSuite) TestFilterRemovesNonMatches(c *gc.C) {
array := simplestreams.IndexMetadataSlice{&simplestreams.IndexMetadata{}}
c.Check(
simplestreams.Filter(array, func(*simplestreams.IndexMetadata) bool { return false }),
gc.HasLen,
0)
}
示例2: TestFilterReturnsNothingForEmptyArray
func (*simplestreamsSuite) TestFilterReturnsNothingForEmptyArray(c *gc.C) {
empty := simplestreams.IndexMetadataSlice{}
c.Check(
simplestreams.Filter(empty, func(*simplestreams.IndexMetadata) bool { return true }),
gc.HasLen,
0)
}
示例3: TestFilterIncludesMatches
func (*simplestreamsSuite) TestFilterIncludesMatches(c *gc.C) {
metadata := simplestreams.IndexMetadata{}
array := simplestreams.IndexMetadataSlice{&metadata}
c.Check(
simplestreams.Filter(array, func(*simplestreams.IndexMetadata) bool { return true }),
gc.DeepEquals,
simplestreams.IndexMetadataSlice{&metadata})
}
示例4: TestFilterPreservesOrder
func (*simplestreamsSuite) TestFilterPreservesOrder(c *gc.C) {
array := simplestreams.IndexMetadataSlice{
&simplestreams.IndexMetadata{CloudName: "aws"},
&simplestreams.IndexMetadata{CloudName: "maas"},
&simplestreams.IndexMetadata{CloudName: "openstack"},
}
c.Check(
simplestreams.Filter(array, func(metadata *simplestreams.IndexMetadata) bool { return true }),
gc.DeepEquals,
array)
}
示例5: TestFilterCombinesMatchesAndNonMatches
func (*simplestreamsSuite) TestFilterCombinesMatchesAndNonMatches(c *gc.C) {
array := simplestreams.IndexMetadataSlice{
&simplestreams.IndexMetadata{Format: "1.0"},
&simplestreams.IndexMetadata{Format: "1.1"},
&simplestreams.IndexMetadata{Format: "2.0"},
&simplestreams.IndexMetadata{Format: "2.1"},
}
dotOFormats := simplestreams.Filter(array, func(metadata *simplestreams.IndexMetadata) bool {
return strings.HasSuffix(metadata.Format, ".0")
})
c.Check(dotOFormats, gc.DeepEquals, simplestreams.IndexMetadataSlice{array[0], array[2]})
}
示例6: TestFilterLeavesOriginalUnchanged
func (*simplestreamsSuite) TestFilterLeavesOriginalUnchanged(c *gc.C) {
item1 := simplestreams.IndexMetadata{CloudName: "aws"}
item2 := simplestreams.IndexMetadata{CloudName: "openstack"}
array := simplestreams.IndexMetadataSlice{&item1, &item2}
result := simplestreams.Filter(array, func(metadata *simplestreams.IndexMetadata) bool {
return metadata.CloudName == "aws"
})
// This exercises both the "leave out" and the "include" code paths.
c.Assert(result, gc.HasLen, 1)
// The original, however, has not changed.
c.Assert(array, gc.HasLen, 2)
c.Check(array, gc.DeepEquals, simplestreams.IndexMetadataSlice{&item1, &item2})
}