code.gitea.io/gitea@v1.22.3/modules/container/filter_test.go (about)

     1  // Copyright 2024 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package container
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestFilterMapUnique(t *testing.T) {
    13  	result := FilterSlice([]int{
    14  		0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    15  	}, func(i int) (int, bool) {
    16  		switch i {
    17  		case 0:
    18  			return 0, true // included later
    19  		case 1:
    20  			return 0, true // duplicate of previous (should be ignored)
    21  		case 2:
    22  			return 2, false // not included
    23  		default:
    24  			return i, true
    25  		}
    26  	})
    27  	assert.Equal(t, []int{0, 3, 4, 5, 6, 7, 8, 9}, result)
    28  }