🚚 Move Slug/Hash Generators to own file

This commit is contained in:
Dan Jones 2025-03-14 19:50:24 -05:00
commit 1d0f2238b3
7 changed files with 193 additions and 162 deletions

42
gen_file_test.go Normal file
View file

@ -0,0 +1,42 @@
package nomino
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSlugMissingFilename(t *testing.T) {
conf := NewConfig(WithGenerator(Slug()))
st, err := conf.generator(&conf)
assert.Zero(t, st)
assert.ErrorIs(t, err, ErrMissingOriginal)
}
func TestSlugRemovesOriginal(t *testing.T) {
conf := NewConfig(WithGenerator(Slug()), WithOriginal("Hello, World"))
st, err := conf.generator(&conf)
assert.Zero(t, conf.original)
assert.Equal(t, "hello-world", st)
assert.NoError(t, err)
}
func TestHashBadHash(t *testing.T) {
conf := NewConfig(WithOriginal("foobar"), WithGenerator(Hash(0)))
st, err := conf.generator(&conf)
assert.Equal(t, "", st)
assert.ErrorIs(t, err, ErrInvalidHashType)
assert.ErrorContains(t, err, "invalid hash type: HashType(0)")
}
func TestHashMissingOriginal(t *testing.T) {
conf := NewConfig(WithGenerator(Hash(HashMD5)))
st, err := conf.generator(&conf)
assert.Equal(t, "", st)
assert.ErrorIs(t, err, ErrMissingOriginal)
}
func TestHashTypeStringer(t *testing.T) {
s := HashMD5.String()
assert.Equal(t, "MD5", s)
}