github.com/grailbio/base@v0.0.11/cmd/ticket-server/support_test.go (about)

     1  package main
     2  
     3  import (
     4  	"reflect"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func TestStringInSlice(t *testing.T) {
    10  	cases := []struct {
    11  		haystack []string
    12  		match    string
    13  		result   bool
    14  	}{
    15  		{[]string{"a", "b", "c"}, "a", true},
    16  		{[]string{"a", "b", "c"}, "d", false},
    17  	}
    18  
    19  	for _, c := range cases {
    20  		got, want := stringInSlice(c.haystack, c.match), c.result
    21  		if got != want {
    22  			t.Errorf("stringInSlice(%+v, %q): got %t, want %t", c.haystack, c.match, got, want)
    23  		}
    24  	}
    25  }
    26  
    27  func TestFmap(t *testing.T) {
    28  	cases := []struct {
    29  		stringList []string
    30  		f          func(string) string
    31  		result     []string
    32  	}{
    33  		{[]string{"a", "b", "c"}, strings.ToUpper, []string{"A", "B", "C"}},
    34  	}
    35  
    36  	for _, c := range cases {
    37  		got, want := fmap(c.stringList, c.f), c.result
    38  		if !reflect.DeepEqual(got, want) {
    39  			t.Errorf("Map(%+v, ...): got %+v, want %+v", c.stringList, got, want)
    40  		}
    41  	}
    42  }
    43  
    44  func TestEmailDomain(t *testing.T) {
    45  	cases := []struct {
    46  		email  string
    47  		domain string
    48  	}{
    49  		{"aeiser@grailbio.com", "grailbio.com"},
    50  		{"aeisergrailbio.com", ""},
    51  		{"aeiser@grail@bio.com", ""},
    52  	}
    53  
    54  	for _, c := range cases {
    55  		got, want := emailDomain(c.email), c.domain
    56  		if got != want {
    57  			t.Errorf("emailDomain(%q): got %q, want %q", c.email, got, want)
    58  		}
    59  	}
    60  }