From 7f29f43fe2022671cc66502acb5e6d95eb777bc0 Mon Sep 17 00:00:00 2001 From: ewy Date: Wed, 22 Apr 2026 21:02:44 +0200 Subject: add tests for identities --- identity/identity.go | 5 +++++ identity/identity_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 identity/identity_test.go 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)) +} -- cgit v1.3.1