mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-04 10:30:19 -05:00
0e57ff7eee
This PR adds a generic set type to get rid of maps used as sets. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
37 lines
853 B
Go
37 lines
853 B
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package container
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSet(t *testing.T) {
|
|
s := make(Set[string])
|
|
|
|
assert.True(t, s.Add("key1"))
|
|
assert.False(t, s.Add("key1"))
|
|
assert.True(t, s.Add("key2"))
|
|
|
|
assert.True(t, s.Contains("key1"))
|
|
assert.True(t, s.Contains("key2"))
|
|
assert.False(t, s.Contains("key3"))
|
|
|
|
assert.True(t, s.Remove("key2"))
|
|
assert.False(t, s.Contains("key2"))
|
|
|
|
assert.False(t, s.Remove("key3"))
|
|
|
|
s.AddMultiple("key4", "key5")
|
|
assert.True(t, s.Contains("key4"))
|
|
assert.True(t, s.Contains("key5"))
|
|
|
|
s = SetOf("key6", "key7")
|
|
assert.False(t, s.Contains("key1"))
|
|
assert.True(t, s.Contains("key6"))
|
|
assert.True(t, s.Contains("key7"))
|
|
}
|