...

Source file src/github.com/thoas/go-funk/fill_test.go

Documentation: github.com/thoas/go-funk

     1  package funk
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"testing"
     6  )
     7  
     8  func TestFillMismatchedTypes(t *testing.T) {
     9  	_, err := Fill([]string{"a", "b"}, 1)
    10  	assert.EqualError(t, err, "Cannot fill '[]string' with 'int'")
    11  }
    12  
    13  func TestFillUnfillableTypes(t *testing.T) {
    14  	var stringVariable string
    15  	var uint32Variable uint32
    16  	var boolVariable bool
    17  
    18  	types := [](interface{}){
    19  		stringVariable,
    20  		uint32Variable,
    21  		boolVariable,
    22  	}
    23  
    24  	for _, unfillable := range types {
    25  		_, err := Fill(unfillable, 1)
    26  		assert.EqualError(t, err, "Can only fill slices and arrays")
    27  	}
    28  }
    29  
    30  func TestFillSlice(t *testing.T) {
    31  	input := []int{1, 2, 3}
    32  	result, err := Fill(input, 1)
    33  	assert.NoError(t, err)
    34  	assert.Equal(t, []int{1, 1, 1}, result)
    35  
    36  	// Assert that input does not change
    37  	assert.Equal(t, []int{1, 2, 3}, input)
    38  }
    39  
    40  func TestFillArray(t *testing.T) {
    41  	input := [...]int{1, 2, 3}
    42  	result, err := Fill(input, 2)
    43  	assert.NoError(t, err)
    44  	assert.Equal(t, []int{2, 2, 2}, result)
    45  
    46  	// Assert that input does not change
    47  	assert.Equal(t, [...]int{1, 2, 3}, input)
    48  }
    49  

View as plain text