Skip to content

Commit

Permalink
Allow credit invoices (#1)
Browse files Browse the repository at this point in the history
This change allows negative amounts to be reported
  • Loading branch information
ValentinMezev authored Dec 20, 2024
1 parent 736ec4e commit c6838b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion basicvalidators.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// Helper function to validate if the string is a valid currency format (with 2 decimal places)
func IsValidCurrencyFormat(amount string) bool {
// Regex pattern to match valid decimal with exactly two decimal places
validCurrency := regexp.MustCompile(`^\d+(\.\d{2})$`)
validCurrency := regexp.MustCompile(`^-?\d+(\.\d{2})$`)
return validCurrency.MatchString(amount)
}

Expand Down
12 changes: 6 additions & 6 deletions basicvalidators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ func TestCheckCurrency(t *testing.T) {

// Test an invalid currency
if IsValidCurrencyFormat("abc") {
t.Fatalf("Expected currency 100 to be invalid")
t.Fatalf("Expected currency abc to be invalid")
}

// Test an invalid currency
if IsValidCurrencyFormat("abc.fg") {
t.Fatalf("Expected currency 100 to be invalid")
t.Fatalf("Expected currency abc.fg to be invalid")
}

// Test an invalid currency
if IsValidCurrencyFormat("abc.23") {
t.Fatalf("Expected currency 100 to be invalid")
t.Fatalf("Expected currency abc.23 to be invalid")
}

// Test an invalid currency
if IsValidCurrencyFormat("100.ab") {
t.Fatalf("Expected currency 100 to be invalid")
t.Fatalf("Expected currency 100.ab to be invalid")
}

// Test negative currency
if IsValidCurrencyFormat("-100.00") {
t.Fatalf("Expected currency 100 to be invalid")
if !IsValidCurrencyFormat("-100.00") {
t.Fatalf("Expected currency -100.00 to be valid")
}

//Test zero
Expand Down

0 comments on commit c6838b6

Please sign in to comment.