@@ -185,38 +185,41 @@ public void InvalidDiffLineChangeChar(string line, string expectMessage)
185185
186186 public class TheMatchMethod
187187 {
188+ /// <param name="diffLines">Target diff chunk with header (with '.' as line separator)</param>
189+ /// <param name="matchLines">Diff lines to match (with '.' as line separator)</param>
190+ /// <param name="expectedDiffLineNumber">The DiffLineNumber that the last line of matchLines falls on</param>
188191 [ Theory ]
189- [ InlineData ( " 1" , " 1" , 0 ) ]
190- [ InlineData ( " 1. 2" , " 2" , 1 ) ]
191- [ InlineData ( " 1. 1" , " 1" , 1 ) ] // match the later line
192+ [ InlineData ( " 1" , " 1" , 1 ) ]
193+ [ InlineData ( " 1. 2" , " 2" , 2 ) ]
194+ [ InlineData ( " 1. 1" , " 1" , 2 ) ] // match the later line
192195 [ InlineData ( "+x" , "-x" , - 1 ) ]
193196 [ InlineData ( "" , " x" , - 1 ) ]
194197 [ InlineData ( " x" , "" , - 1 ) ]
195198
196- [ InlineData ( " 1. 2." , " 1. 2." , 1 ) ] // matched full context
199+ [ InlineData ( " 1. 2." , " 1. 2." , 2 ) ] // matched full context
197200 [ 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
201+ [ InlineData ( " 2." , " 1. 2." , 1 ) ] // match if we run out of context lines
199202
200203 // Tests for https://github.com/github/VisualStudio/issues/1149
201204 // 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 ) ]
205+ [ InlineData ( "+a.+x.+x." , "+a.+x." , 2 ) ]
206+ [ InlineData ( "+a.+x.+x." , "+a.+x.+x." , 3 ) ]
207+ [ InlineData ( "+a.+x.+x.+b.+x.+x." , "+a.+x." , 2 ) ]
208+ [ InlineData ( "+a.+x.+x.+b.+x.+x." , "+b.+x." , 5 ) ]
206209 [ InlineData ( "+a.+b.+x" , "+a.+x." , - 1 ) ] // backtrack when there is a failed match
207- public void MatchLine ( string lines1 , string lines2 , int skip /* -1 for no match */ )
210+ public void MatchLine ( string diffLines , string matchLines , int expectedDiffLineNumber /* -1 for no match */ )
208211 {
209212 var header = "@@ -1 +1 @@" ;
210- lines1 = lines1 . Replace ( "." , "\r \n " ) ;
211- lines2 = lines2 . Replace ( "." , "\r \n " ) ;
212- var chunks1 = DiffUtilities . ParseFragment ( header + "\n " + lines1 ) . ToList ( ) ;
213- var chunks2 = DiffUtilities . ParseFragment ( header + "\n " + lines2 ) . ToList ( ) ;
214- var expectLine = ( skip != - 1 ) ? chunks1 . First ( ) . Lines [ skip ] : null ;
213+ diffLines = diffLines . Replace ( "." , "\r \n " ) ;
214+ matchLines = matchLines . Replace ( "." , "\r \n " ) ;
215+ var chunks1 = DiffUtilities . ParseFragment ( header + "\n " + diffLines ) . ToList ( ) ;
216+ var chunks2 = DiffUtilities . ParseFragment ( header + "\n " + matchLines ) . ToList ( ) ;
215217 var targetLines = chunks2 . First ( ) . Lines . Reverse ( ) . ToList ( ) ;
216218
217219 var line = DiffUtilities . Match ( chunks1 , targetLines ) ;
218220
219- Assert . Equal ( expectLine , line ) ;
221+ var diffLineNumber = ( line != null ) ? line . DiffLineNumber : - 1 ;
222+ Assert . Equal ( expectedDiffLineNumber , diffLineNumber ) ;
220223 }
221224
222225 [ Fact ]
0 commit comments