xref: /aosp_15_r20/external/licenseclassifier/stringclassifier/searchset/searchset_test.go (revision 46c4c49da23cae783fa41bf46525a6505638499a)
1*46c4c49dSIbrahim Kanouche// Copyright 2017 Google Inc.
2*46c4c49dSIbrahim Kanouche//
3*46c4c49dSIbrahim Kanouche// Licensed under the Apache License, Version 2.0 (the "License");
4*46c4c49dSIbrahim Kanouche// you may not use this file except in compliance with the License.
5*46c4c49dSIbrahim Kanouche// You may obtain a copy of the License at
6*46c4c49dSIbrahim Kanouche//
7*46c4c49dSIbrahim Kanouche//	http://www.apache.org/licenses/LICENSE-2.0
8*46c4c49dSIbrahim Kanouche//
9*46c4c49dSIbrahim Kanouche// Unless required by applicable law or agreed to in writing, software
10*46c4c49dSIbrahim Kanouche// distributed under the License is distributed on an "AS IS" BASIS,
11*46c4c49dSIbrahim Kanouche// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*46c4c49dSIbrahim Kanouche// See the License for the specific language governing permissions and
13*46c4c49dSIbrahim Kanouche// limitations under the License.
14*46c4c49dSIbrahim Kanouchepackage searchset
15*46c4c49dSIbrahim Kanouche
16*46c4c49dSIbrahim Kanoucheimport (
17*46c4c49dSIbrahim Kanouche	"reflect"
18*46c4c49dSIbrahim Kanouche	"testing"
19*46c4c49dSIbrahim Kanouche
20*46c4c49dSIbrahim Kanouche	"github.com/google/licenseclassifier/stringclassifier/searchset/tokenizer"
21*46c4c49dSIbrahim Kanouche)
22*46c4c49dSIbrahim Kanouche
23*46c4c49dSIbrahim Kanoucheconst (
24*46c4c49dSIbrahim Kanouche	shortPostmodernThesis = "In the works of Joyce, a predominant concept is the concept of semioticist"
25*46c4c49dSIbrahim Kanouche	postmodernThesis      = `1. Joyce and neotextual modernist theory
26*46c4c49dSIbrahim Kanouche
27*46c4c49dSIbrahim KanoucheIn the works of Joyce, a predominant concept is the concept of semioticist
28*46c4c49dSIbrahim Kanoucheculture. The without/within distinction intrinsic to Finnegan's Wake emerges
29*46c4c49dSIbrahim Kanoucheagain in Ulysses, although in a more neomodern sense.
30*46c4c49dSIbrahim Kanouche`
31*46c4c49dSIbrahim Kanouche)
32*46c4c49dSIbrahim Kanouche
33*46c4c49dSIbrahim Kanouchefunc TestSearchSet_New(t *testing.T) {
34*46c4c49dSIbrahim Kanouche	tests := []struct {
35*46c4c49dSIbrahim Kanouche		description string
36*46c4c49dSIbrahim Kanouche		text        string
37*46c4c49dSIbrahim Kanouche		granularity int
38*46c4c49dSIbrahim Kanouche		want        *SearchSet
39*46c4c49dSIbrahim Kanouche	}{
40*46c4c49dSIbrahim Kanouche		{
41*46c4c49dSIbrahim Kanouche			description: "Empty string",
42*46c4c49dSIbrahim Kanouche			text:        "",
43*46c4c49dSIbrahim Kanouche			granularity: DefaultGranularity,
44*46c4c49dSIbrahim Kanouche			want: &SearchSet{
45*46c4c49dSIbrahim Kanouche				Tokens:         nil,
46*46c4c49dSIbrahim Kanouche				Hashes:         make(tokenizer.Hash),
47*46c4c49dSIbrahim Kanouche				Checksums:      nil,
48*46c4c49dSIbrahim Kanouche				ChecksumRanges: nil,
49*46c4c49dSIbrahim Kanouche			},
50*46c4c49dSIbrahim Kanouche		},
51*46c4c49dSIbrahim Kanouche		{
52*46c4c49dSIbrahim Kanouche			description: "Small string",
53*46c4c49dSIbrahim Kanouche			text:        "Hello world",
54*46c4c49dSIbrahim Kanouche			granularity: 4,
55*46c4c49dSIbrahim Kanouche			want: &SearchSet{
56*46c4c49dSIbrahim Kanouche				Tokens: tokenizer.Tokens{
57*46c4c49dSIbrahim Kanouche					{Text: "Hello", Offset: 0},
58*46c4c49dSIbrahim Kanouche					{Text: "world", Offset: 6},
59*46c4c49dSIbrahim Kanouche				},
60*46c4c49dSIbrahim Kanouche				Hashes:         tokenizer.Hash{2346098258: tokenizer.TokenRanges{{Start: 0, End: 2}}},
61*46c4c49dSIbrahim Kanouche				Checksums:      []uint32{2346098258},
62*46c4c49dSIbrahim Kanouche				ChecksumRanges: tokenizer.TokenRanges{{Start: 0, End: 2}},
63*46c4c49dSIbrahim Kanouche				nodes:          []*node{{2346098258, &tokenizer.TokenRange{Start: 0, End: 2}}},
64*46c4c49dSIbrahim Kanouche			},
65*46c4c49dSIbrahim Kanouche		},
66*46c4c49dSIbrahim Kanouche	}
67*46c4c49dSIbrahim Kanouche
68*46c4c49dSIbrahim Kanouche	for _, tt := range tests {
69*46c4c49dSIbrahim Kanouche		if got := New(tt.text, tt.granularity); !reflect.DeepEqual(got, tt.want) {
70*46c4c49dSIbrahim Kanouche			t.Errorf("New(%q) = %+v, want %+v", tt.description, got, tt.want)
71*46c4c49dSIbrahim Kanouche		}
72*46c4c49dSIbrahim Kanouche	}
73*46c4c49dSIbrahim Kanouche}
74*46c4c49dSIbrahim Kanouche
75*46c4c49dSIbrahim Kanouchefunc TestSearchSet_NodeConstruction(t *testing.T) {
76*46c4c49dSIbrahim Kanouche	s := New(shortPostmodernThesis, DefaultGranularity)
77*46c4c49dSIbrahim Kanouche	want := []string{
78*46c4c49dSIbrahim Kanouche		"[0:3]", "[1:4]", "[2:5]", "[3:6]", "[4:7]", "[5:8]", "[6:9]",
79*46c4c49dSIbrahim Kanouche		"[7:10]", "[8:11]", "[9:12]", "[10:13]", "[11:14]",
80*46c4c49dSIbrahim Kanouche	}
81*46c4c49dSIbrahim Kanouche
82*46c4c49dSIbrahim Kanouche	if len(s.nodes) != len(want) {
83*46c4c49dSIbrahim Kanouche		t.Errorf("Number of nodes %v, want %v", len(s.nodes), len(want))
84*46c4c49dSIbrahim Kanouche		return
85*46c4c49dSIbrahim Kanouche	}
86*46c4c49dSIbrahim Kanouche
87*46c4c49dSIbrahim Kanouche	for i := 0; i < len(s.nodes); i++ {
88*46c4c49dSIbrahim Kanouche		if got := s.nodes[i].String(); got != want[i] {
89*46c4c49dSIbrahim Kanouche			t.Errorf("Nodes = got:\n%s\nwant:\n%s", got, want[i])
90*46c4c49dSIbrahim Kanouche		}
91*46c4c49dSIbrahim Kanouche	}
92*46c4c49dSIbrahim Kanouche}
93*46c4c49dSIbrahim Kanouche
94*46c4c49dSIbrahim Kanouchefunc TestSearchSet_CoalesceTokenRanges(t *testing.T) {
95*46c4c49dSIbrahim Kanouche	tests := []struct {
96*46c4c49dSIbrahim Kanouche		description string
97*46c4c49dSIbrahim Kanouche		mr          MatchRanges
98*46c4c49dSIbrahim Kanouche		want        MatchRanges
99*46c4c49dSIbrahim Kanouche	}{
100*46c4c49dSIbrahim Kanouche		{
101*46c4c49dSIbrahim Kanouche			description: "Non-overlapping Ranges",
102*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
103*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 27, TargetStart: 0, TargetEnd: 27},
104*46c4c49dSIbrahim Kanouche				{SrcStart: 37, SrcEnd: 927, TargetStart: 37, TargetEnd: 927},
105*46c4c49dSIbrahim Kanouche			},
106*46c4c49dSIbrahim Kanouche			want: MatchRanges{
107*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 27, TargetStart: 0, TargetEnd: 27},
108*46c4c49dSIbrahim Kanouche				{SrcStart: 37, SrcEnd: 927, TargetStart: 37, TargetEnd: 927},
109*46c4c49dSIbrahim Kanouche			},
110*46c4c49dSIbrahim Kanouche		},
111*46c4c49dSIbrahim Kanouche		{
112*46c4c49dSIbrahim Kanouche			description: "Identical Ranges",
113*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
114*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 37, TargetStart: 0, TargetEnd: 37},
115*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 37, TargetStart: 0, TargetEnd: 37},
116*46c4c49dSIbrahim Kanouche			},
117*46c4c49dSIbrahim Kanouche			want: MatchRanges{{SrcStart: 0, SrcEnd: 37, TargetStart: 0, TargetEnd: 37}},
118*46c4c49dSIbrahim Kanouche		},
119*46c4c49dSIbrahim Kanouche		{
120*46c4c49dSIbrahim Kanouche			description: "Sequential Ranges",
121*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
122*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 37, TargetStart: 0, TargetEnd: 37},
123*46c4c49dSIbrahim Kanouche				{SrcStart: 37, SrcEnd: 927, TargetStart: 37, TargetEnd: 927},
124*46c4c49dSIbrahim Kanouche			},
125*46c4c49dSIbrahim Kanouche			want: MatchRanges{{SrcStart: 0, SrcEnd: 927, TargetStart: 0, TargetEnd: 927}},
126*46c4c49dSIbrahim Kanouche		},
127*46c4c49dSIbrahim Kanouche		{
128*46c4c49dSIbrahim Kanouche			description: "Overlapping Ranges - Same Start",
129*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
130*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 37, TargetStart: 0, TargetEnd: 37},
131*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 927, TargetStart: 0, TargetEnd: 927},
132*46c4c49dSIbrahim Kanouche			},
133*46c4c49dSIbrahim Kanouche			want: MatchRanges{{SrcStart: 0, SrcEnd: 927, TargetStart: 0, TargetEnd: 927}},
134*46c4c49dSIbrahim Kanouche		},
135*46c4c49dSIbrahim Kanouche		{
136*46c4c49dSIbrahim Kanouche			description: "Overlapping Ranges - Different Start",
137*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
138*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 37, TargetStart: 0, TargetEnd: 37},
139*46c4c49dSIbrahim Kanouche				{SrcStart: 27, SrcEnd: 927, TargetStart: 27, TargetEnd: 927},
140*46c4c49dSIbrahim Kanouche			},
141*46c4c49dSIbrahim Kanouche			want: MatchRanges{{SrcStart: 0, SrcEnd: 927, TargetStart: 0, TargetEnd: 927}},
142*46c4c49dSIbrahim Kanouche		},
143*46c4c49dSIbrahim Kanouche		{
144*46c4c49dSIbrahim Kanouche			description: "Overlapping Ranges - Same End",
145*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
146*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 37, TargetStart: 0, TargetEnd: 37},
147*46c4c49dSIbrahim Kanouche				{SrcStart: 27, SrcEnd: 37, TargetStart: 27, TargetEnd: 37},
148*46c4c49dSIbrahim Kanouche			},
149*46c4c49dSIbrahim Kanouche			want: MatchRanges{{SrcStart: 0, SrcEnd: 37, TargetStart: 0, TargetEnd: 37}},
150*46c4c49dSIbrahim Kanouche		},
151*46c4c49dSIbrahim Kanouche		{
152*46c4c49dSIbrahim Kanouche			description: "Completely Overlapping Ranges",
153*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
154*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 42, TargetStart: 0, TargetEnd: 42},
155*46c4c49dSIbrahim Kanouche				{SrcStart: 27, SrcEnd: 37, TargetStart: 27, TargetEnd: 37},
156*46c4c49dSIbrahim Kanouche			},
157*46c4c49dSIbrahim Kanouche			want: MatchRanges{{SrcStart: 0, SrcEnd: 42, TargetStart: 0, TargetEnd: 42}},
158*46c4c49dSIbrahim Kanouche		},
159*46c4c49dSIbrahim Kanouche	}
160*46c4c49dSIbrahim Kanouche
161*46c4c49dSIbrahim Kanouche	for _, tt := range tests {
162*46c4c49dSIbrahim Kanouche		got := coalesceMatchRanges(tt.mr)
163*46c4c49dSIbrahim Kanouche		if !reflect.DeepEqual(got, tt.want) {
164*46c4c49dSIbrahim Kanouche			t.Errorf("CoalesceTokenRanges(%q) = %+v, want %+v", tt.description, got, tt.want)
165*46c4c49dSIbrahim Kanouche		}
166*46c4c49dSIbrahim Kanouche	}
167*46c4c49dSIbrahim Kanouche}
168*46c4c49dSIbrahim Kanouche
169*46c4c49dSIbrahim Kanouchefunc TestSearchSet_FindPotentialMatches(t *testing.T) {
170*46c4c49dSIbrahim Kanouche	known := New(postmodernThesis, DefaultGranularity)
171*46c4c49dSIbrahim Kanouche
172*46c4c49dSIbrahim Kanouche	size := len(postmodernThesis)
173*46c4c49dSIbrahim Kanouche	modified := "hello world "
174*46c4c49dSIbrahim Kanouche	modified += postmodernThesis[:size/3] + " hello world "
175*46c4c49dSIbrahim Kanouche	modified += postmodernThesis[size/3 : 2*size/3-4]
176*46c4c49dSIbrahim Kanouche	modified += postmodernThesis[2*size/3+7:]
177*46c4c49dSIbrahim Kanouche	unknown := New(modified, DefaultGranularity)
178*46c4c49dSIbrahim Kanouche
179*46c4c49dSIbrahim Kanouche	want := []MatchRanges{{
180*46c4c49dSIbrahim Kanouche		{SrcStart: 0, SrcEnd: 15, TargetStart: 2, TargetEnd: 17},
181*46c4c49dSIbrahim Kanouche		{SrcStart: 16, SrcEnd: 28, TargetStart: 21, TargetEnd: 33},
182*46c4c49dSIbrahim Kanouche		{SrcStart: 31, SrcEnd: 46, TargetStart: 34, TargetEnd: 49},
183*46c4c49dSIbrahim Kanouche	}}
184*46c4c49dSIbrahim Kanouche
185*46c4c49dSIbrahim Kanouche	got := FindPotentialMatches(known, unknown)
186*46c4c49dSIbrahim Kanouche	if len(got) != len(want) {
187*46c4c49dSIbrahim Kanouche		t.Errorf("Number of matches %v, want %v", len(got), len(want))
188*46c4c49dSIbrahim Kanouche	}
189*46c4c49dSIbrahim Kanouche	if !reflect.DeepEqual(got, want) {
190*46c4c49dSIbrahim Kanouche		t.Errorf("Offsets = %+v, want %+v", got, want)
191*46c4c49dSIbrahim Kanouche	}
192*46c4c49dSIbrahim Kanouche
193*46c4c49dSIbrahim Kanouche	known = New(`again in Ulysses, although in a more neomodern sense.
194*46c4c49dSIbrahim Kanoucheculture. The without/within distinction intrinsic to Finnegan's Wake emerges
195*46c4c49dSIbrahim Kanouche`, DefaultGranularity)
196*46c4c49dSIbrahim Kanouche
197*46c4c49dSIbrahim Kanouche	want = []MatchRanges{
198*46c4c49dSIbrahim Kanouche		{
199*46c4c49dSIbrahim Kanouche			{SrcStart: 11, SrcEnd: 18, TargetStart: 26, TargetEnd: 33},
200*46c4c49dSIbrahim Kanouche			{SrcStart: 21, SrcEnd: 25, TargetStart: 34, TargetEnd: 38},
201*46c4c49dSIbrahim Kanouche		},
202*46c4c49dSIbrahim Kanouche		{{SrcStart: 0, SrcEnd: 11, TargetStart: 38, TargetEnd: 49}},
203*46c4c49dSIbrahim Kanouche	}
204*46c4c49dSIbrahim Kanouche
205*46c4c49dSIbrahim Kanouche	got = FindPotentialMatches(known, unknown)
206*46c4c49dSIbrahim Kanouche	if len(got) != len(want) {
207*46c4c49dSIbrahim Kanouche		t.Errorf("Number of matches %v, want %v", len(got), len(want))
208*46c4c49dSIbrahim Kanouche	}
209*46c4c49dSIbrahim Kanouche	if !reflect.DeepEqual(got, want) {
210*46c4c49dSIbrahim Kanouche		t.Errorf("Offsets = %+v, want %+v", got, want)
211*46c4c49dSIbrahim Kanouche	}
212*46c4c49dSIbrahim Kanouche}
213*46c4c49dSIbrahim Kanouche
214*46c4c49dSIbrahim Kanouchefunc TestSearchSet_GetMatchedRanges(t *testing.T) {
215*46c4c49dSIbrahim Kanouche	const (
216*46c4c49dSIbrahim Kanouche		source = "a b c d e f g c d e h i j"
217*46c4c49dSIbrahim Kanouche		target = "a b c _ _ c d e _ f g h _ c d  e _ h i j"
218*46c4c49dSIbrahim Kanouche	)
219*46c4c49dSIbrahim Kanouche
220*46c4c49dSIbrahim Kanouche	src := New(source, DefaultGranularity)
221*46c4c49dSIbrahim Kanouche	tar := New(target, DefaultGranularity)
222*46c4c49dSIbrahim Kanouche
223*46c4c49dSIbrahim Kanouche	want := []MatchRanges{
224*46c4c49dSIbrahim Kanouche		{
225*46c4c49dSIbrahim Kanouche			{SrcStart: 0, SrcEnd: 3, TargetStart: 0, TargetEnd: 3},
226*46c4c49dSIbrahim Kanouche			{SrcStart: 2, SrcEnd: 5, TargetStart: 5, TargetEnd: 8},
227*46c4c49dSIbrahim Kanouche			{SrcStart: 7, SrcEnd: 10, TargetStart: 13, TargetEnd: 16},
228*46c4c49dSIbrahim Kanouche			{SrcStart: 10, SrcEnd: 13, TargetStart: 17, TargetEnd: 20},
229*46c4c49dSIbrahim Kanouche		},
230*46c4c49dSIbrahim Kanouche	}
231*46c4c49dSIbrahim Kanouche
232*46c4c49dSIbrahim Kanouche	got := getMatchedRanges(src, tar)
233*46c4c49dSIbrahim Kanouche	if len(got) != len(want) {
234*46c4c49dSIbrahim Kanouche		t.Errorf("Number of matches %v, want %v", len(got), len(want))
235*46c4c49dSIbrahim Kanouche	}
236*46c4c49dSIbrahim Kanouche	if !reflect.DeepEqual(got, want) {
237*46c4c49dSIbrahim Kanouche		t.Errorf("Match Ranges = %+v, want %+v", got, want)
238*46c4c49dSIbrahim Kanouche	}
239*46c4c49dSIbrahim Kanouche}
240*46c4c49dSIbrahim Kanouche
241*46c4c49dSIbrahim Kanouchefunc TestSearchSet_TargetMatchedRanges(t *testing.T) {
242*46c4c49dSIbrahim Kanouche	const (
243*46c4c49dSIbrahim Kanouche		source = "a b c d e f g c d e h i j"
244*46c4c49dSIbrahim Kanouche		target = "a b c d e _ _ c d e _ f g h _ c d  e _ h i j"
245*46c4c49dSIbrahim Kanouche	)
246*46c4c49dSIbrahim Kanouche
247*46c4c49dSIbrahim Kanouche	src := New(source, DefaultGranularity)
248*46c4c49dSIbrahim Kanouche	tar := New(target, DefaultGranularity)
249*46c4c49dSIbrahim Kanouche
250*46c4c49dSIbrahim Kanouche	want := MatchRanges{
251*46c4c49dSIbrahim Kanouche		{SrcStart: 0, SrcEnd: 3, TargetStart: 0, TargetEnd: 3},
252*46c4c49dSIbrahim Kanouche		{SrcStart: 1, SrcEnd: 4, TargetStart: 1, TargetEnd: 4},
253*46c4c49dSIbrahim Kanouche		{SrcStart: 2, SrcEnd: 5, TargetStart: 2, TargetEnd: 5},
254*46c4c49dSIbrahim Kanouche		{SrcStart: 7, SrcEnd: 10, TargetStart: 2, TargetEnd: 5},
255*46c4c49dSIbrahim Kanouche		{SrcStart: 2, SrcEnd: 5, TargetStart: 7, TargetEnd: 10},
256*46c4c49dSIbrahim Kanouche		{SrcStart: 7, SrcEnd: 10, TargetStart: 7, TargetEnd: 10},
257*46c4c49dSIbrahim Kanouche		{SrcStart: 2, SrcEnd: 5, TargetStart: 15, TargetEnd: 18},
258*46c4c49dSIbrahim Kanouche		{SrcStart: 7, SrcEnd: 10, TargetStart: 15, TargetEnd: 18},
259*46c4c49dSIbrahim Kanouche		{SrcStart: 10, SrcEnd: 13, TargetStart: 19, TargetEnd: 22},
260*46c4c49dSIbrahim Kanouche	}
261*46c4c49dSIbrahim Kanouche
262*46c4c49dSIbrahim Kanouche	got := targetMatchedRanges(src, tar)
263*46c4c49dSIbrahim Kanouche	if len(got) != len(want) {
264*46c4c49dSIbrahim Kanouche		t.Errorf("Number of matches %v, want %v", len(got), len(want))
265*46c4c49dSIbrahim Kanouche	}
266*46c4c49dSIbrahim Kanouche	if !reflect.DeepEqual(got, want) {
267*46c4c49dSIbrahim Kanouche		t.Errorf("Match Range = %+v, want %+v", got, want)
268*46c4c49dSIbrahim Kanouche	}
269*46c4c49dSIbrahim Kanouche}
270*46c4c49dSIbrahim Kanouche
271*46c4c49dSIbrahim Kanouchefunc TestSearchSet_UntangleSourceRanges(t *testing.T) {
272*46c4c49dSIbrahim Kanouche	tests := []struct {
273*46c4c49dSIbrahim Kanouche		description string
274*46c4c49dSIbrahim Kanouche		mr          MatchRanges
275*46c4c49dSIbrahim Kanouche		want        MatchRanges
276*46c4c49dSIbrahim Kanouche	}{
277*46c4c49dSIbrahim Kanouche		{
278*46c4c49dSIbrahim Kanouche			description: "Single Match - In Order",
279*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
280*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 10, TargetEnd: 13},
281*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 14, TargetEnd: 19},
282*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 15, TargetEnd: 20},
283*46c4c49dSIbrahim Kanouche			},
284*46c4c49dSIbrahim Kanouche			want: MatchRanges{
285*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 10, TargetEnd: 13},
286*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 14, TargetEnd: 19},
287*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 15, TargetEnd: 20},
288*46c4c49dSIbrahim Kanouche			},
289*46c4c49dSIbrahim Kanouche		},
290*46c4c49dSIbrahim Kanouche		{
291*46c4c49dSIbrahim Kanouche			description: "Single Match - Out of Order",
292*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
293*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 10, TargetEnd: 13},
294*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 14, TargetEnd: 19},
295*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 14, TargetEnd: 19},
296*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 15, TargetEnd: 20},
297*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 24, TargetEnd: 19},
298*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 24, TargetEnd: 19},
299*46c4c49dSIbrahim Kanouche				{SrcStart: 23, SrcEnd: 29, TargetStart: 30, TargetEnd: 37},
300*46c4c49dSIbrahim Kanouche			},
301*46c4c49dSIbrahim Kanouche			want: MatchRanges{
302*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 10, TargetEnd: 13},
303*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 14, TargetEnd: 19},
304*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 15, TargetEnd: 20},
305*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 24, TargetEnd: 19},
306*46c4c49dSIbrahim Kanouche				{SrcStart: 23, SrcEnd: 29, TargetStart: 30, TargetEnd: 37},
307*46c4c49dSIbrahim Kanouche			},
308*46c4c49dSIbrahim Kanouche		},
309*46c4c49dSIbrahim Kanouche		{
310*46c4c49dSIbrahim Kanouche			description: "Multiple Match - In Order",
311*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
312*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 10, TargetEnd: 13},
313*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 14, TargetEnd: 19},
314*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 15, TargetEnd: 20},
315*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 110, TargetEnd: 113},
316*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 114, TargetEnd: 119},
317*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 115, TargetEnd: 120},
318*46c4c49dSIbrahim Kanouche			},
319*46c4c49dSIbrahim Kanouche			want: MatchRanges{
320*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 10, TargetEnd: 13},
321*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 14, TargetEnd: 19},
322*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 15, TargetEnd: 20},
323*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 110, TargetEnd: 113},
324*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 114, TargetEnd: 119},
325*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 115, TargetEnd: 120},
326*46c4c49dSIbrahim Kanouche			},
327*46c4c49dSIbrahim Kanouche		},
328*46c4c49dSIbrahim Kanouche		{
329*46c4c49dSIbrahim Kanouche			description: "Multiple Match - Out of Order",
330*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
331*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 10, TargetEnd: 13},
332*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 14, TargetEnd: 19},
333*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 14, TargetEnd: 19},
334*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 15, TargetEnd: 20},
335*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 24, TargetEnd: 19},
336*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 24, TargetEnd: 19},
337*46c4c49dSIbrahim Kanouche				{SrcStart: 23, SrcEnd: 29, TargetStart: 30, TargetEnd: 37},
338*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 110, TargetEnd: 113},
339*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 114, TargetEnd: 119},
340*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 114, TargetEnd: 119},
341*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 115, TargetEnd: 120},
342*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 124, TargetEnd: 119},
343*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 124, TargetEnd: 119},
344*46c4c49dSIbrahim Kanouche				{SrcStart: 23, SrcEnd: 29, TargetStart: 130, TargetEnd: 137},
345*46c4c49dSIbrahim Kanouche			},
346*46c4c49dSIbrahim Kanouche			want: MatchRanges{
347*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 10, TargetEnd: 13},
348*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 14, TargetEnd: 19},
349*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 15, TargetEnd: 20},
350*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 24, TargetEnd: 19},
351*46c4c49dSIbrahim Kanouche				{SrcStart: 23, SrcEnd: 29, TargetStart: 30, TargetEnd: 37},
352*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 3, TargetStart: 110, TargetEnd: 113},
353*46c4c49dSIbrahim Kanouche				{SrcStart: 5, SrcEnd: 10, TargetStart: 114, TargetEnd: 119},
354*46c4c49dSIbrahim Kanouche				{SrcStart: 6, SrcEnd: 11, TargetStart: 115, TargetEnd: 120},
355*46c4c49dSIbrahim Kanouche				{SrcStart: 15, SrcEnd: 20, TargetStart: 124, TargetEnd: 119},
356*46c4c49dSIbrahim Kanouche				{SrcStart: 23, SrcEnd: 29, TargetStart: 130, TargetEnd: 137},
357*46c4c49dSIbrahim Kanouche			},
358*46c4c49dSIbrahim Kanouche		},
359*46c4c49dSIbrahim Kanouche	}
360*46c4c49dSIbrahim Kanouche
361*46c4c49dSIbrahim Kanouche	for _, tt := range tests {
362*46c4c49dSIbrahim Kanouche		got := untangleSourceRanges(tt.mr)
363*46c4c49dSIbrahim Kanouche		if len(got) != len(tt.want) {
364*46c4c49dSIbrahim Kanouche			t.Errorf("Number of matches %v, want %v", len(got), len(tt.want))
365*46c4c49dSIbrahim Kanouche		}
366*46c4c49dSIbrahim Kanouche		if !reflect.DeepEqual(got, tt.want) {
367*46c4c49dSIbrahim Kanouche			t.Errorf("UntangleSourceRanges(%q) = %v, want %v", tt.description, got, tt.want)
368*46c4c49dSIbrahim Kanouche		}
369*46c4c49dSIbrahim Kanouche	}
370*46c4c49dSIbrahim Kanouche}
371*46c4c49dSIbrahim Kanouche
372*46c4c49dSIbrahim Kanouchefunc TestSearchSet_SplitRanges(t *testing.T) {
373*46c4c49dSIbrahim Kanouche	tests := []struct {
374*46c4c49dSIbrahim Kanouche		description string
375*46c4c49dSIbrahim Kanouche		mr          MatchRanges
376*46c4c49dSIbrahim Kanouche		want        []MatchRanges
377*46c4c49dSIbrahim Kanouche	}{
378*46c4c49dSIbrahim Kanouche		{
379*46c4c49dSIbrahim Kanouche			description: "Single Match Range",
380*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
381*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
382*46c4c49dSIbrahim Kanouche				{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
383*46c4c49dSIbrahim Kanouche			},
384*46c4c49dSIbrahim Kanouche			want: []MatchRanges{
385*46c4c49dSIbrahim Kanouche				{
386*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
387*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
388*46c4c49dSIbrahim Kanouche				},
389*46c4c49dSIbrahim Kanouche			},
390*46c4c49dSIbrahim Kanouche		},
391*46c4c49dSIbrahim Kanouche		{
392*46c4c49dSIbrahim Kanouche			description: "Two Match Ranges",
393*46c4c49dSIbrahim Kanouche			mr: MatchRanges{
394*46c4c49dSIbrahim Kanouche				{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
395*46c4c49dSIbrahim Kanouche				{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
396*46c4c49dSIbrahim Kanouche				{SrcStart: 3, SrcEnd: 10, TargetStart: 108, TargetEnd: 115},
397*46c4c49dSIbrahim Kanouche				{SrcStart: 23, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
398*46c4c49dSIbrahim Kanouche			},
399*46c4c49dSIbrahim Kanouche			want: []MatchRanges{
400*46c4c49dSIbrahim Kanouche				{
401*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
402*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
403*46c4c49dSIbrahim Kanouche				},
404*46c4c49dSIbrahim Kanouche				{
405*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 108, TargetEnd: 115},
406*46c4c49dSIbrahim Kanouche					{SrcStart: 23, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
407*46c4c49dSIbrahim Kanouche				},
408*46c4c49dSIbrahim Kanouche			},
409*46c4c49dSIbrahim Kanouche		},
410*46c4c49dSIbrahim Kanouche	}
411*46c4c49dSIbrahim Kanouche
412*46c4c49dSIbrahim Kanouche	for _, tt := range tests {
413*46c4c49dSIbrahim Kanouche		got := splitRanges(tt.mr)
414*46c4c49dSIbrahim Kanouche		if len(got) != len(tt.want) {
415*46c4c49dSIbrahim Kanouche			t.Errorf("Number of matches %v, want %v", len(got), len(tt.want))
416*46c4c49dSIbrahim Kanouche		}
417*46c4c49dSIbrahim Kanouche		if !reflect.DeepEqual(got, tt.want) {
418*46c4c49dSIbrahim Kanouche			t.Errorf("SplitRanges(%q) = %v, want %v", tt.description, got, tt.want)
419*46c4c49dSIbrahim Kanouche		}
420*46c4c49dSIbrahim Kanouche	}
421*46c4c49dSIbrahim Kanouche}
422*46c4c49dSIbrahim Kanouche
423*46c4c49dSIbrahim Kanouchefunc TestSearchSet_MergeConsecutiveRanges(t *testing.T) {
424*46c4c49dSIbrahim Kanouche	tests := []struct {
425*46c4c49dSIbrahim Kanouche		description string
426*46c4c49dSIbrahim Kanouche		mr          []MatchRanges
427*46c4c49dSIbrahim Kanouche		want        []MatchRanges
428*46c4c49dSIbrahim Kanouche	}{
429*46c4c49dSIbrahim Kanouche		{
430*46c4c49dSIbrahim Kanouche			description: "No Overlap",
431*46c4c49dSIbrahim Kanouche			mr: []MatchRanges{
432*46c4c49dSIbrahim Kanouche				{
433*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
434*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
435*46c4c49dSIbrahim Kanouche				},
436*46c4c49dSIbrahim Kanouche				{
437*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 108, TargetEnd: 115},
438*46c4c49dSIbrahim Kanouche					{SrcStart: 23, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
439*46c4c49dSIbrahim Kanouche				},
440*46c4c49dSIbrahim Kanouche			},
441*46c4c49dSIbrahim Kanouche			want: []MatchRanges{
442*46c4c49dSIbrahim Kanouche				{
443*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
444*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
445*46c4c49dSIbrahim Kanouche				},
446*46c4c49dSIbrahim Kanouche				{
447*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 108, TargetEnd: 115},
448*46c4c49dSIbrahim Kanouche					{SrcStart: 23, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
449*46c4c49dSIbrahim Kanouche				},
450*46c4c49dSIbrahim Kanouche			},
451*46c4c49dSIbrahim Kanouche		},
452*46c4c49dSIbrahim Kanouche		{
453*46c4c49dSIbrahim Kanouche			description: "Consecutive Ranges No Overlap",
454*46c4c49dSIbrahim Kanouche			mr: []MatchRanges{
455*46c4c49dSIbrahim Kanouche				{
456*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
457*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
458*46c4c49dSIbrahim Kanouche				},
459*46c4c49dSIbrahim Kanouche				{
460*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 35, TargetEnd: 41},
461*46c4c49dSIbrahim Kanouche					{SrcStart: 23, SrcEnd: 30, TargetStart: 125, TargetEnd: 135},
462*46c4c49dSIbrahim Kanouche				},
463*46c4c49dSIbrahim Kanouche			},
464*46c4c49dSIbrahim Kanouche			want: []MatchRanges{
465*46c4c49dSIbrahim Kanouche				{
466*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
467*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
468*46c4c49dSIbrahim Kanouche				},
469*46c4c49dSIbrahim Kanouche				{
470*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 35, TargetEnd: 41},
471*46c4c49dSIbrahim Kanouche					{SrcStart: 23, SrcEnd: 30, TargetStart: 125, TargetEnd: 135},
472*46c4c49dSIbrahim Kanouche				},
473*46c4c49dSIbrahim Kanouche			},
474*46c4c49dSIbrahim Kanouche		},
475*46c4c49dSIbrahim Kanouche		{
476*46c4c49dSIbrahim Kanouche			description: "Consecutive Ranges with First Element Overlap",
477*46c4c49dSIbrahim Kanouche			mr: []MatchRanges{
478*46c4c49dSIbrahim Kanouche				{
479*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
480*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
481*46c4c49dSIbrahim Kanouche				},
482*46c4c49dSIbrahim Kanouche				{
483*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 34, TargetEnd: 41},
484*46c4c49dSIbrahim Kanouche					{SrcStart: 33, SrcEnd: 40, TargetStart: 35, TargetEnd: 42},
485*46c4c49dSIbrahim Kanouche				},
486*46c4c49dSIbrahim Kanouche			},
487*46c4c49dSIbrahim Kanouche			want: []MatchRanges{
488*46c4c49dSIbrahim Kanouche				{
489*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
490*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 36, TargetStart: 25, TargetEnd: 41},
491*46c4c49dSIbrahim Kanouche					{SrcStart: 33, SrcEnd: 40, TargetStart: 35, TargetEnd: 42},
492*46c4c49dSIbrahim Kanouche				},
493*46c4c49dSIbrahim Kanouche			},
494*46c4c49dSIbrahim Kanouche		},
495*46c4c49dSIbrahim Kanouche		{
496*46c4c49dSIbrahim Kanouche			description: "Consecutive Ranges with Overlap",
497*46c4c49dSIbrahim Kanouche			mr: []MatchRanges{
498*46c4c49dSIbrahim Kanouche				{
499*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
500*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
501*46c4c49dSIbrahim Kanouche				},
502*46c4c49dSIbrahim Kanouche				{
503*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 34, TargetEnd: 41},
504*46c4c49dSIbrahim Kanouche					{SrcStart: 33, SrcEnd: 40, TargetStart: 45, TargetEnd: 52},
505*46c4c49dSIbrahim Kanouche				},
506*46c4c49dSIbrahim Kanouche			},
507*46c4c49dSIbrahim Kanouche			want: []MatchRanges{
508*46c4c49dSIbrahim Kanouche				{
509*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
510*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 36, TargetStart: 25, TargetEnd: 41},
511*46c4c49dSIbrahim Kanouche					{SrcStart: 33, SrcEnd: 40, TargetStart: 45, TargetEnd: 52},
512*46c4c49dSIbrahim Kanouche				},
513*46c4c49dSIbrahim Kanouche			},
514*46c4c49dSIbrahim Kanouche		},
515*46c4c49dSIbrahim Kanouche		{
516*46c4c49dSIbrahim Kanouche			description: "Consecutive Ranges with Previous Deep Overlap",
517*46c4c49dSIbrahim Kanouche			mr: []MatchRanges{
518*46c4c49dSIbrahim Kanouche				{
519*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
520*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
521*46c4c49dSIbrahim Kanouche					{SrcStart: 120, SrcEnd: 130, TargetStart: 37, TargetEnd: 47},
522*46c4c49dSIbrahim Kanouche					{SrcStart: 122, SrcEnd: 132, TargetStart: 39, TargetEnd: 49},
523*46c4c49dSIbrahim Kanouche				},
524*46c4c49dSIbrahim Kanouche				{
525*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 34, TargetEnd: 41},
526*46c4c49dSIbrahim Kanouche					{SrcStart: 33, SrcEnd: 40, TargetStart: 45, TargetEnd: 52},
527*46c4c49dSIbrahim Kanouche				},
528*46c4c49dSIbrahim Kanouche			},
529*46c4c49dSIbrahim Kanouche			want: []MatchRanges{
530*46c4c49dSIbrahim Kanouche				{
531*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
532*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 36, TargetStart: 25, TargetEnd: 41},
533*46c4c49dSIbrahim Kanouche					{SrcStart: 33, SrcEnd: 40, TargetStart: 45, TargetEnd: 52},
534*46c4c49dSIbrahim Kanouche				},
535*46c4c49dSIbrahim Kanouche			},
536*46c4c49dSIbrahim Kanouche		},
537*46c4c49dSIbrahim Kanouche		{
538*46c4c49dSIbrahim Kanouche			description: "Consecutive Ranges with Deep Overlap",
539*46c4c49dSIbrahim Kanouche			mr: []MatchRanges{
540*46c4c49dSIbrahim Kanouche				{
541*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
542*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
543*46c4c49dSIbrahim Kanouche					{SrcStart: 24, SrcEnd: 34, TargetStart: 29, TargetEnd: 39},
544*46c4c49dSIbrahim Kanouche					{SrcStart: 120, SrcEnd: 130, TargetStart: 37, TargetEnd: 47},
545*46c4c49dSIbrahim Kanouche					{SrcStart: 122, SrcEnd: 132, TargetStart: 39, TargetEnd: 49},
546*46c4c49dSIbrahim Kanouche				},
547*46c4c49dSIbrahim Kanouche				{
548*46c4c49dSIbrahim Kanouche					{SrcStart: 3, SrcEnd: 10, TargetStart: 26, TargetEnd: 33},
549*46c4c49dSIbrahim Kanouche					{SrcStart: 5, SrcEnd: 12, TargetStart: 28, TargetEnd: 35},
550*46c4c49dSIbrahim Kanouche					{SrcStart: 25, SrcEnd: 35, TargetStart: 31, TargetEnd: 41},
551*46c4c49dSIbrahim Kanouche				},
552*46c4c49dSIbrahim Kanouche			},
553*46c4c49dSIbrahim Kanouche			want: []MatchRanges{
554*46c4c49dSIbrahim Kanouche				{
555*46c4c49dSIbrahim Kanouche					{SrcStart: 0, SrcEnd: 10, TargetStart: 5, TargetEnd: 15},
556*46c4c49dSIbrahim Kanouche					{SrcStart: 20, SrcEnd: 30, TargetStart: 25, TargetEnd: 35},
557*46c4c49dSIbrahim Kanouche					{SrcStart: 24, SrcEnd: 34, TargetStart: 29, TargetEnd: 39},
558*46c4c49dSIbrahim Kanouche					{SrcStart: 25, SrcEnd: 35, TargetStart: 31, TargetEnd: 41},
559*46c4c49dSIbrahim Kanouche				},
560*46c4c49dSIbrahim Kanouche			},
561*46c4c49dSIbrahim Kanouche		},
562*46c4c49dSIbrahim Kanouche	}
563*46c4c49dSIbrahim Kanouche
564*46c4c49dSIbrahim Kanouche	for _, tt := range tests {
565*46c4c49dSIbrahim Kanouche		got := mergeConsecutiveRanges(tt.mr)
566*46c4c49dSIbrahim Kanouche		if len(got) != len(tt.want) {
567*46c4c49dSIbrahim Kanouche			t.Errorf("Number of matches %v, want %v", len(got), len(tt.want))
568*46c4c49dSIbrahim Kanouche		}
569*46c4c49dSIbrahim Kanouche		if !reflect.DeepEqual(got, tt.want) {
570*46c4c49dSIbrahim Kanouche			t.Errorf("SplitRanges(%q) = %v, want %v", tt.description, got, tt.want)
571*46c4c49dSIbrahim Kanouche		}
572*46c4c49dSIbrahim Kanouche	}
573*46c4c49dSIbrahim Kanouche}
574