File: prefix_test.go

package info (click to toggle)
golang-github-go-delve-liner 0.0~git20211124.709274f-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 216 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,144 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build windows || linux || darwin || openbsd || freebsd || netbsd || solaris
// +build windows linux darwin openbsd freebsd netbsd solaris

package liner

import "testing"

type testItem struct {
	list   []string
	prefix string
}

func TestPrefix(t *testing.T) {
	list := []testItem{
		{[]string{"food", "foot"}, "foo"},
		{[]string{"foo", "foot"}, "foo"},
		{[]string{"food", "foo"}, "foo"},
		{[]string{"food", "foe", "foot"}, "fo"},
		{[]string{"food", "foot", "barbeque"}, ""},
		{[]string{"cafeteria", "café"}, "caf"},
		{[]string{"cafe", "café"}, "caf"},
		{[]string{"cafè", "café"}, "caf"},
		{[]string{"cafés", "café"}, "café"},
		{[]string{"áéíóú", "áéíóú"}, "áéíóú"},
		{[]string{"éclairs", "éclairs"}, "éclairs"},
		{[]string{"éclairs are the best", "éclairs are great", "éclairs"}, "éclairs"},
		{[]string{"éclair", "éclairs"}, "éclair"},
		{[]string{"éclairs", "éclair"}, "éclair"},
		{[]string{"éclair", "élan"}, "é"},
	}

	for _, test := range list {
		lcp := longestCommonPrefix(test.list)
		if lcp != test.prefix {
			t.Errorf("%s != %s for %+v", lcp, test.prefix, test.list)
		}
	}
}