Skip to content

Commit

Permalink
Merge pull request #75 from truemail-rb/develop
Browse files Browse the repository at this point in the history
truemail-go v1.1.1
  • Loading branch information
bestwebua committed May 10, 2023
2 parents 8f4da49 + 9f363b7 commit cbaa0c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.1] - 2023-05-10

### Fixed

- Fixed `regexCaptureGroup()` index navigation [issue](https://github.com/truemail-rb/truemail-go/issues/71). Thanks [@chiappone](https://github.com/chiappone) for the bug report.

## [1.1.0] - 2023-02-20

### Added
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
reported by contacting the project team at <[email protected]>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
10 changes: 8 additions & 2 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ func validateValidationTypeContext(validationType string) error {
)
}

// Returns string by regex pattern capture group index
// Returns string by regex pattern capture group index for case when capture group found,
// otherwise returns empty string
func regexCaptureGroup(str string, regexPattern string, captureGroup int) string {
regex, _ := newRegex(regexPattern)
matchedStringsSlice := regex.FindStringSubmatch(str)

return regex.FindStringSubmatch(str)[captureGroup]
if captureGroup > (len(matchedStringsSlice) - 1) {
return emptyString
} else {
return matchedStringsSlice[captureGroup]
}
}

// Returns domain from email string
Expand Down
16 changes: 12 additions & 4 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,31 @@ func TestValidateValidationTypeContext(t *testing.T) {
}

func TestRegexCaptureGroup(t *testing.T) {
str, regexPattern := "abbc", `\A(a)(b{2}).+\z`
str := "abbc"

t.Run("returns string when regex capture group found", func(t *testing.T) {
regexPattern := `\A(a)(b{2}).+\z`

assert.Equal(t, "bb", regexCaptureGroup(str, regexPattern, 2))
})

t.Run("panics when regex capture group not found", func(t *testing.T) {
assert.Panics(t, func() { regexCaptureGroup(str, regexPattern, 3) })
t.Run("returns empty string when regex capture group not found", func(t *testing.T) {
regexPattern := `(\d)`

assert.Equal(t, emptyString, regexCaptureGroup(str, regexPattern, 1))
})
}

func TestEmailDomain(t *testing.T) {
t.Run("extracts domain name from email address", func(t *testing.T) {
t.Run("extracts domain name from email address when domain exists", func(t *testing.T) {
email, domain := pairRandomEmailDomain()

assert.Equal(t, domain, emailDomain(email))
})

t.Run("returns empty string as domain name when domain not exists", func(t *testing.T) {
assert.Equal(t, emptyString, emailDomain("email_without_domain"))
})
}

func TestCopyConfigurationByPointer(t *testing.T) {
Expand Down

0 comments on commit cbaa0c0

Please sign in to comment.