Skip to content

Commit

Permalink
Added custom rune tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelay committed Oct 2, 2022
1 parent adcde1e commit 11eaa3c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 22 deletions.
5 changes: 2 additions & 3 deletions domain.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package Anonymize is a small and simple package for anonymizing names, e-mails and domains.
//
// Copyright 2022 Emmanuel Ay. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
Expand All @@ -17,9 +19,6 @@ func DomainWithCustomRune(input string, anonRune rune) string {
}

func processDomain(input string, anonRune rune) string {
if len(input) == 0 || len(strings.TrimSpace(input)) == 0 {
return ""
}

dotSplit := strings.Split(input, ".")

Expand Down
23 changes: 20 additions & 3 deletions domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import (

func TestAnonymizeDomain(t *testing.T) {
tests := []struct {
got string
want string
got string
want string
anonRune rune
}{
{
got: "www.somedomain.com",
want: "www.s*********.com",
},
{
got: " ",
want: "",
},
{
got: "f.com",
want: "*.com",
Expand Down Expand Up @@ -44,10 +49,22 @@ func TestAnonymizeDomain(t *testing.T) {
got: "domain.com",
want: "d*****.com",
},
{
got: "www.domain.com",
want: "www.d•••••.com",
anonRune: '•',
},
}

for _, test := range tests {
result := anonymize.Domain(test.got)
var result string

if test.anonRune > 0 {
result = anonymize.DomainWithCustomRune(test.got, test.anonRune)
} else {
result = anonymize.Domain(test.got)
}

if !strings.EqualFold(test.want, result) {
t.Errorf("Incorrect result for '%v': got '%v', want '%v'", test.got, result, test.want)
}
Expand Down
5 changes: 2 additions & 3 deletions email.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package Anonymize is a small and simple package for anonymizing names, e-mails and domains.
//
// Copyright 2022 Emmanuel Ay. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
Expand All @@ -17,9 +19,6 @@ func EmailWithCustomRune(input string, anonRune rune) string {
}

func processEmail(input string, anonRune rune) string {
if len(input) == 0 || len(strings.TrimSpace(input)) == 0 {
return ""
}

atSplit := strings.Split(input, "@")

Expand Down
23 changes: 20 additions & 3 deletions email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (

func TestAnonymizeEmail(t *testing.T) {
tests := []struct {
got string
want string
got string
want string
anonRune rune
}{
{
got: "emmanuel@somedomain.com",
Expand All @@ -20,6 +21,10 @@ func TestAnonymizeEmail(t *testing.T) {
got: "this.is.incorrect@domain@domain.com",
want: "t***.i*.i********@d*****@d*****.com",
},
{
got: " ",
want: "",
},
{
got: "e@f.com",
want: "*@*.com",
Expand Down Expand Up @@ -64,10 +69,22 @@ func TestAnonymizeEmail(t *testing.T) {
got: "Luke.SkyWalker@McDonalds.com",
want: "L***.S**W*****@M*D******.com",
},
{
got: "jane.doe@gmail.com",
want: "j•••.d••@g••••.com",
anonRune: '•',
},
}

for _, test := range tests {
result := anonymize.Email(test.got)
var result string

if test.anonRune > 0 {
result = anonymize.EmailWithCustomRune(test.got, test.anonRune)
} else {
result = anonymize.Email(test.got)
}

if !strings.EqualFold(test.want, result) {
t.Errorf("Incorrect result for '%v': got '%v', want '%v'", test.got, result, test.want)
}
Expand Down
5 changes: 2 additions & 3 deletions name.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package Anonymize is a small and simple package for anonymizing names, e-mails and domains.
//
// Copyright 2022 Emmanuel Ay. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
Expand All @@ -19,9 +21,6 @@ func NameWithCustomRune(input string, anonRune rune) string {
}

func processName(input string, anonRune rune) string {
if len(input) == 0 || len(strings.TrimSpace(input)) == 0 {
return ""
}

parts := strings.Split(input, " ")

Expand Down
6 changes: 1 addition & 5 deletions name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ func TestAnonymizeName(t *testing.T) {
},
{
got: " ",
want: "",
},
{
got: "",
want: "",
want: " ",
},
{
got: "",
Expand Down
9 changes: 7 additions & 2 deletions word.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Package Anonymize is a small and simple package for anonymizing names, e-mails and domains.
//
// Copyright 2022 Emmanuel Ay. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package anonymize

import "unicode"
import (
"strings"
"unicode"
)

func processWord(input string, allowSingleToken bool, anontoken rune) string {

if len(input) == 0 {
if len(input) == 0 || len(strings.TrimSpace(input)) == 0 {
return ""
}

Expand Down

0 comments on commit 11eaa3c

Please sign in to comment.