github.com/prattmic/llgo-embedded@v0.0.0-20150820070356-41cfecea0e1e/third_party/liner/prefix_test.go (about)

     1  // +build windows linux darwin openbsd freebsd netbsd
     2  
     3  package liner
     4  
     5  import "testing"
     6  
     7  type testItem struct {
     8  	list   []string
     9  	prefix string
    10  }
    11  
    12  func TestPrefix(t *testing.T) {
    13  	list := []testItem{
    14  		{[]string{"food", "foot"}, "foo"},
    15  		{[]string{"foo", "foot"}, "foo"},
    16  		{[]string{"food", "foo"}, "foo"},
    17  		{[]string{"food", "foe", "foot"}, "fo"},
    18  		{[]string{"food", "foot", "barbeque"}, ""},
    19  		{[]string{"cafeteria", "café"}, "caf"},
    20  		{[]string{"cafe", "café"}, "caf"},
    21  		{[]string{"cafè", "café"}, "caf"},
    22  		{[]string{"cafés", "café"}, "café"},
    23  		{[]string{"áéíóú", "áéíóú"}, "áéíóú"},
    24  		{[]string{"éclairs", "éclairs"}, "éclairs"},
    25  		{[]string{"éclairs are the best", "éclairs are great", "éclairs"}, "éclairs"},
    26  		{[]string{"éclair", "éclairs"}, "éclair"},
    27  		{[]string{"éclairs", "éclair"}, "éclair"},
    28  		{[]string{"éclair", "élan"}, "é"},
    29  	}
    30  
    31  	for _, test := range list {
    32  		lcp := longestCommonPrefix(test.list)
    33  		if lcp != test.prefix {
    34  			t.Errorf("%s != %s for %+v", lcp, test.prefix, test.list)
    35  		}
    36  	}
    37  }