-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ValidateLocationID function an location id validation
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package fiskalhrgo | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
// ValidateLocationID validates the locationID | ||
// It can contain only digits (0-9) and letters (a-z, A-Z), with a maximum length of 20. | ||
func ValidateLocationID(locationID string) bool { | ||
// Regex pattern to match valid locationID | ||
validLocationID := regexp.MustCompile(`^[a-zA-Z0-9]{1,20}$`) | ||
return validLocationID.MatchString(locationID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fiskalhrgo | ||
|
||
import "testing" | ||
|
||
func TestValidateLocationID(t *testing.T) { | ||
t.Logf("Testing location ID validation...") | ||
|
||
if !ValidateLocationID("12345678") { | ||
t.Fatalf("Expected location ID 12345678 to be valid") | ||
} | ||
|
||
if !ValidateLocationID("TEST3") { | ||
t.Fatalf("Expected location ID TEST3 to be valid") | ||
} | ||
|
||
if !ValidateLocationID("POS1") { | ||
t.Fatalf("Expected location ID POS1 to be valid") | ||
} | ||
|
||
if !ValidateLocationID("1") { | ||
t.Fatalf("Expected location ID 1 to be valid") | ||
} | ||
|
||
if !ValidateLocationID("1234567a") { | ||
t.Fatalf("Expected location ID 1234567a to be valid") | ||
} | ||
|
||
if ValidateLocationID("1234567!") { | ||
t.Fatalf("Expected location ID 1234567! to be invalid") | ||
} | ||
|
||
if ValidateLocationID("1234567.") { | ||
t.Fatalf("Expected location ID 1234567. to be invalid") | ||
} | ||
|
||
if ValidateLocationID("POS 1") { | ||
t.Fatalf("Expected location ID POS 1 to be invalid") | ||
} | ||
|
||
if ValidateLocationID("fdkjhfdhjfdshfshfdkhfd87549549875kjfhhfdshfjhjdshkjdfsk7554875kjgfkjgfsssssssssssssssssssssssss") { | ||
t.Fatalf("Expected location ID fdkjhfdhjfdshfshfdkhfd87549549875kjfhhfdshfjhjdshkjdfsk7554875kjgfkjgfsssssssssssssssssssssssss to be invalid") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters