diff --git a/ident/ident_test.go b/ident/ident_test.go deleted file mode 100644 index 2f71af7..0000000 --- a/ident/ident_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package ident_test - -import ( - "testing" - - "github.com/origadmin/toolkits/ident" -) - -type mockIdentifier struct{} - -func (m *mockIdentifier) Name() string { - return "MockIdentifier" -} - -func (m *mockIdentifier) Gen() string { - return "mock-generated-id" -} - -func (m *mockIdentifier) Validate(id string) bool { - return id == "mock-generated-id" -} - -func (m *mockIdentifier) Size() int { - return 12 // Replace with the actual size of the generated identifier -} - -func TestGenID(t *testing.T) { - ident.Use(&mockIdentifier{}) - generatedID := ident.GenID() - expectedID := "mock-generated-id" - - if generatedID != expectedID { - t.Errorf("GenID() = %v, want %v", generatedID, expectedID) - } -} - -func TestGenSize(t *testing.T) { - ident.Use(&mockIdentifier{}) - size := ident.GenSize() - expectedSize := 12 // Replace with the actual size of the generated identifier - - if size != expectedSize { - t.Errorf("GenSize() = %v, want %v", size, expectedSize) - } -} - -func TestValidate(t *testing.T) { - ident.Use(&mockIdentifier{}) - validID := "mock-generated-id" - invalidID := "invalid-id" - - if !ident.Validate(validID) { - t.Errorf("Validate(%v) = %v, want %v", validID, false, true) - } - - if ident.Validate(invalidID) { - t.Errorf("Validate(%v) = %v, want %v", invalidID, true, false) - } -} diff --git a/ident/number.go b/ident/number.go deleted file mode 100644 index 9c47733..0000000 --- a/ident/number.go +++ /dev/null @@ -1,53 +0,0 @@ -package ident - -import ( - "strconv" - "sync/atomic" -) - -type ident struct { - start int64 - size int -} - -var NumberStart int64 = 1 - -// Name returns the name of the object identifier. -// -// This method, associated with the ident type, aims to retrieve the name of the object. -// It is particularly useful in scenarios where unique identification or representation is required. -// The method does not accept any parameters as it is intended to access an inherent property of the object itself. -// The return value is a string that represents the name of the object. -func (obj *ident) Name() string { - return "number" -} - -// Gen method generates an identifier. -// It returns a string which represents the generated identifier. -func (obj *ident) Gen() string { - num := atomic.AddInt64(&obj.start, 1) - return strconv.FormatInt(num, 10) -} - -// Validate method checks if the given identifier is valid. -// It takes an argument: -// - id: a string, the identifier to be validated. -// -// The function returns a boolean indicating whether the given identifier is valid or not. -func (obj *ident) Validate(id string) bool { - num, err := strconv.ParseInt(id, 10, 64) - return err != nil || num == 0 -} - -// Size method returns the size of the identifier. -// It returns an integer representing the size. -func (obj *ident) Size() int { - return obj.size -} - -func newNumber() *ident { - return &ident{ - start: NumberStart, - size: 8, - } -}