amuz.es/src/go/misc@v1.0.1/strutil/mask_test.go (about)

     1  package strutil
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMaskText(t *testing.T) {
     8  	type args struct {
     9  		input string
    10  	}
    11  	tests := []struct {
    12  		name    string
    13  		args    args
    14  		wantVal string
    15  	}{
    16  		{
    17  			"address",
    18  			args{"test@example.com"},
    19  			"t*st@example.com",
    20  		},
    21  		{
    22  			"address_long",
    23  			args{"testtesttesttest@example.com"},
    24  			"t*************st@example.com",
    25  		},
    26  		{
    27  			"address_short",
    28  			args{"tst@example.com"},
    29  			"*st@example.com",
    30  		},
    31  		{
    32  			"address_short_2",
    33  			args{"tt@example.com"},
    34  			"*t@example.com",
    35  		},
    36  		{
    37  			"address_very_short",
    38  			args{"t@example.com"},
    39  			"*@example.com",
    40  		},
    41  		{
    42  			"non-formal",
    43  			args{"texample.com"},
    44  			"t**********m",
    45  		},
    46  		{
    47  			"non-formal2",
    48  			args{"te🧭ample.co🧭"},
    49  			"t**********🧭",
    50  		},
    51  		{
    52  			"non-formal short",
    53  			args{"com"},
    54  			"c*m",
    55  		},
    56  		{
    57  			"non-formal short 2",
    58  			args{"⏰om"},
    59  			"⏰*m",
    60  		},
    61  	}
    62  	for _, tt := range tests {
    63  		t.Run(tt.name, func(t *testing.T) {
    64  			if gotVal := MaskText(tt.args.input); gotVal != tt.wantVal {
    65  				t.Errorf("MaskText() = %v, want %v", gotVal, tt.wantVal)
    66  			} else {
    67  				t.Log("==> ", gotVal)
    68  			}
    69  		})
    70  	}
    71  }