@@ -193,18 +193,25 @@ public class TheMatchMethod
193193 [ InlineData ( "" , " x" , - 1 ) ]
194194 [ InlineData ( " x" , "" , - 1 ) ]
195195
196- [ InlineData ( " 1. 2." , " 2. 1." , 1 ) ] // matched full context
197- [ InlineData ( " 1. 2." , " 2. 3." , - 1 ) ] // didn't match full context
198- [ InlineData ( " 2." , " 2. 1." , 0 ) ] // match if we run out of context lines
196+ [ InlineData ( " 1. 2." , " 1. 2." , 1 ) ] // matched full context
197+ [ InlineData ( " 1. 2." , " 3. 2." , - 1 ) ] // didn't match full context
198+ [ InlineData ( " 2." , " 1. 2." , 0 ) ] // match if we run out of context lines
199+
200+ // Tests for https://github.com/github/VisualStudio/issues/1149
201+ // Matching algorithm got confused when there was a partial match.
202+ [ InlineData ( "+a.+x.+x." , "+a.+x." , 1 ) ]
203+ [ InlineData ( "+a.+x.+x." , "+a.+x.+x." , 2 ) ]
204+ [ InlineData ( "+a.+x.+x.+b.+x.+x." , "+a.+x." , 1 ) ]
205+ [ InlineData ( "+a.+x.+x.+b.+x.+x." , "+b.+x." , 4 ) ]
199206 public void MatchLine ( string lines1 , string lines2 , int skip /* -1 for no match */ )
200207 {
201208 var header = "@@ -1 +1 @@" ;
202209 lines1 = lines1 . Replace ( "." , "\r \n " ) ;
203210 lines2 = lines2 . Replace ( "." , "\r \n " ) ;
204211 var chunks1 = DiffUtilities . ParseFragment ( header + "\n " + lines1 ) . ToList ( ) ;
205212 var chunks2 = DiffUtilities . ParseFragment ( header + "\n " + lines2 ) . ToList ( ) ;
206- var expectLine = ( skip != - 1 ) ? chunks1 . First ( ) . Lines . Skip ( skip ) . First ( ) : null ;
207- var targetLines = chunks2 . First ( ) . Lines ;
213+ var expectLine = ( skip != - 1 ) ? chunks1 . First ( ) . Lines [ skip ] : null ;
214+ var targetLines = chunks2 . First ( ) . Lines . Reverse ( ) . ToList ( ) ;
208215
209216 var line = DiffUtilities . Match ( chunks1 , targetLines ) ;
210217
0 commit comments