diff options
| author | ewy <ewy0@protonmail.com> | 2026-04-22 21:02:44 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-04-22 21:02:44 +0200 |
| commit | 7f29f43fe2022671cc66502acb5e6d95eb777bc0 (patch) | |
| tree | 1541ef56be13c15e628620b481c5a818f41cda4b /identity | |
| parent | 35fd641be06ed0e79ed995f685f40fec8fc57504 (diff) | |
add tests for identities
Diffstat (limited to 'identity')
| -rw-r--r-- | identity/identity.go | 5 | ||||
| -rw-r--r-- | identity/identity_test.go | 46 |
2 files changed, 51 insertions, 0 deletions
diff --git a/identity/identity.go b/identity/identity.go index 1ae13c6..06bd421 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -7,6 +7,10 @@ type Identity struct { Reduced string } +func (i Identity) I(other Identity) bool { + return i.Reduced == other.Reduced +} + func (i Identity) Is(input string) bool { reduced := Reduce(input) return i.Reduced == reduced @@ -23,6 +27,7 @@ func New(input string) Identity { func Reduce(input string) string { reduced := input + reduced = strings.TrimPrefix(input, ".") if !strings.HasPrefix(reduced, ".") { reduced = strings.Split(reduced, ".")[0] } diff --git a/identity/identity_test.go b/identity/identity_test.go new file mode 100644 index 0000000..5dae8be --- /dev/null +++ b/identity/identity_test.go @@ -0,0 +1,46 @@ +//go:build test + +package identity + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestIdentity(t *testing.T) { + a := New("asdf") + b := New("asdf") + c := New("hhhh") + assert.True(t, a.I(b)) + assert.False(t, a.I(c)) +} + +func TestIdentity_Extension(t *testing.T) { + a := New("asdf.sh") + b := New("asdf") + c := New("hhhh") + assert.True(t, a.I(b)) + assert.False(t, a.I(c)) +} + +func TestIdentity_Hidden(t *testing.T) { + a := New(".asdf") + b := New("asdf") + c := New("hhhh") + assert.True(t, a.I(b)) + assert.False(t, a.I(c)) +} + +func TestIdentity_I_Tagged(t *testing.T) { + a := New("asdf.pre.sh") + b := New("asdf") + c := New("hhhh") + assert.True(t, a.I(b)) + assert.False(t, a.I(c)) +} + +func TestIdentity_Is(t *testing.T) { + a := New(".asdf.iahsodiu.txt") + b := "asdf" + assert.True(t, a.Is(b)) +} |
