mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
eval/vals: Test iterate.go.
This commit is contained in:
parent
bbaa846638
commit
f5f49b746e
40
eval/vals/iterate_test.go
Normal file
40
eval/vals/iterate_test.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package vals
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/elves/elvish/tt"
|
||||
"github.com/elves/elvish/util"
|
||||
)
|
||||
|
||||
// An implementation of Iterator.
|
||||
type iterator struct{ elements []interface{} }
|
||||
|
||||
func (i iterator) Iterate(f func(interface{}) bool) {
|
||||
util.Feed(f, i.elements...)
|
||||
}
|
||||
|
||||
// A non-implementation of Iterator.
|
||||
type nonIterator struct{}
|
||||
|
||||
func TestCanIterate(t *testing.T) {
|
||||
tt.Test(t, tt.Fn("CanIterate", CanIterate), tt.Table{
|
||||
Args("foo").Rets(true),
|
||||
Args(MakeList("foo", "bar")).Rets(true),
|
||||
Args(iterator{vs("a", "b")}).Rets(true),
|
||||
Args(nonIterator{}).Rets(false),
|
||||
})
|
||||
}
|
||||
|
||||
func TestCollect(t *testing.T) {
|
||||
tt.Test(t, tt.Fn("Collect", Collect), tt.Table{
|
||||
Args("foo").Rets(vs("f", "o", "o"), nil),
|
||||
Args(MakeList("foo", "bar")).Rets(vs("foo", "bar"), nil),
|
||||
Args(iterator{vs("a", "b")}).Rets(vs("a", "b"), nil),
|
||||
Args(nonIterator{}).Rets(vs(),
|
||||
errors.New("!!vals.nonIterator cannot be iterated")),
|
||||
})
|
||||
}
|
||||
|
||||
// Iterate is tested indirectly by the test against Iterate.
|
Loading…
Reference in New Issue
Block a user