github.com/elves/elvish@v0.15.0/pkg/eval/vals/iterate_keys_test.go (about)

     1  package vals
     2  
     3  import (
     4  	"testing"
     5  
     6  	. "github.com/elves/elvish/pkg/tt"
     7  )
     8  
     9  func vs(xs ...interface{}) []interface{} { return xs }
    10  
    11  type keysIterator struct{ keys []interface{} }
    12  
    13  func (k keysIterator) IterateKeys(f func(interface{}) bool) {
    14  	Feed(f, k.keys...)
    15  }
    16  
    17  type nonKeysIterator struct{}
    18  
    19  func TestIterateKeys(t *testing.T) {
    20  	Test(t, Fn("collectKeys", collectKeys), Table{
    21  		Args(MakeMap("k1", "v1", "k2", "v2")).Rets(vs("k1", "k2"), nil),
    22  		Args(keysIterator{vs("lorem", "ipsum")}).Rets(vs("lorem", "ipsum")),
    23  		Args(nonKeysIterator{}).Rets(
    24  			Any, cannotIterateKeysOf{"!!vals.nonKeysIterator"}),
    25  	})
    26  }