github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/break/loop/test/api_go_1_22_test.go (about)

     1  //go:build goexperiment.rangefunc
     2  
     3  package test
     4  
     5  import (
     6  	"strconv"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  
    11  	"github.com/m4gshm/gollections/break/loop"
    12  )
    13  
    14  func Test_IterAll(t *testing.T) {
    15  	var (
    16  		r    []int
    17  		rerr error
    18  	)
    19  	for v, err := range loop.Conv(loop.Of("1", "3", "5", "_7", "9", "11"), strconv.Atoi).All {
    20  		if rerr = err; err == nil {
    21  			r = append(r, v)
    22  		}
    23  	}
    24  
    25  	assert.Equal(t, []int{1, 3, 5}, r)
    26  	assert.Error(t, rerr, "invalid syntax")
    27  }