badguardhome/internal/aghstrings/set_test.go
Ainar Garipov 71030bafd8 Pull request: all: imp dhcp host normalization, validation
Updates #2952.

Squashed commit of the following:

commit 45afcab5d33c1ec8176c0ad05423288c8770b772
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Apr 20 15:02:34 2021 +0300

    all: imp docs

commit d844ce1e2bb0b92a892119161774ec95f3e59711
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Apr 20 14:57:49 2021 +0300

    all: more code imp

commit eef08cb69015ead0ffaef866e12a2c6556786d37
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Apr 20 14:52:33 2021 +0300

    all: imp code, docs

commit 20748f20ab9fcc410b11daf0e23eaf156dcdc7cd
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Apr 20 14:30:57 2021 +0300

    all: imp dhcp host normalization, validation
2021-04-20 15:07:57 +03:00

57 lines
828 B
Go

package aghstrings
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSet(t *testing.T) {
const s = "a"
t.Run("nil", func(t *testing.T) {
var set *Set
assert.NotPanics(t, func() {
set.Del(s)
})
assert.NotPanics(t, func() {
assert.False(t, set.Has(s))
})
assert.NotPanics(t, func() {
assert.Equal(t, 0, set.Len())
})
assert.NotPanics(t, func() {
assert.Nil(t, set.Values())
})
assert.Panics(t, func() {
set.Add(s)
})
})
t.Run("non_nil", func(t *testing.T) {
set := NewSet()
assert.Equal(t, 0, set.Len())
ok := set.Has(s)
assert.False(t, ok)
set.Add(s)
ok = set.Has(s)
assert.True(t, ok)
assert.Equal(t, []string{s}, set.Values())
set.Del(s)
ok = set.Has(s)
assert.False(t, ok)
set = NewSet(s)
assert.Equal(t, 1, set.Len())
})
}