@@ -63,46 +63,20 @@ public void PullRequest(string url, int? expectPullRequest)
6363 Assert . That ( context ? . PullRequest , Is . EqualTo ( expectPullRequest ) ) ;
6464 }
6565
66- [ TestCase ( "https://github.com/github/VisualStudio/blob/master" , null , null , null ) ]
67- [ TestCase ( "https://github.com/github/VisualStudio/blob/master/foo.cs" , "master" , null , "foo.cs" ) ]
68- [ TestCase ( "https://github.com/github/VisualStudio/blob/master/path/foo.cs" , "master" , null , "path/foo.cs" ) ]
69- [ TestCase ( "https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/path/foo.cs" , null , "ee863ce265fc6217f589e66766125fed1b5b8256" , "path/foo.cs" ) ]
70- [ TestCase ( "https://github.com/github/VisualStudio/blob/not_master/foo.cs" , null , null , null , Description = "We currently only match SHA and master" ) ]
71- public void Blob ( string url , string expectBranch , string expectCommitSha , string expectPath )
66+ [ TestCase ( "https://github.com/github/VisualStudio/blob/master" , null , null ) ]
67+ [ TestCase ( "https://github.com/github/VisualStudio/blob/master/foo.cs" , "master" , "foo.cs" ) ]
68+ [ TestCase ( "https://github.com/github/VisualStudio/blob/master/path/foo.cs" , "master/path" , "foo.cs" ) ]
69+ [ TestCase ( "https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/foo.cs" , "ee863ce265fc6217f589e66766125fed1b5b8256" , "foo.cs" ) ]
70+ [ TestCase ( "https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/path/foo.cs" , "ee863ce265fc6217f589e66766125fed1b5b8256/path" , "foo.cs" ) ]
71+ [ TestCase ( "https://github.com/github/VisualStudio/blob/master/bar.cs#stuff" , "master" , "bar.cs" ) ]
72+ public void Blob ( string url , string expectTreeish , string expectBlobName )
7273 {
7374 var target = CreateGitHubContextService ( ) ;
7475
7576 var context = target . FindContextFromUrl ( url ) ;
7677
77- Assert . That ( context . BranchName , Is . EqualTo ( expectBranch ) ) ;
78- Assert . That ( context . CommitSha , Is . EqualTo ( expectCommitSha ) ) ;
79- Assert . That ( context . Path , Is . EqualTo ( expectPath ) ) ;
80- }
81-
82- [ TestCase ( "https://github.com" , null ) ]
83- [ TestCase ( "https://github.com/github" , null ) ]
84- [ TestCase ( "https://github.com/github/VisualStudio" , null ) ]
85- [ TestCase ( "https://github.com/github/VisualStudio/blob/master/README.md" , "README.md" ) ]
86- [ TestCase ( "https://github.com/github/VisualStudio/blob/master/README.md#notices" , "README.md" ) ]
87- [ TestCase ( "https://github.com/github/VisualStudio/blob/0d264d50c57d701fa62d202f481075a6c6dbdce8/src/Code.cs#L86" , "src/Code.cs" ) ]
88- public void Path ( string url , string expectPath )
89- {
90- var target = CreateGitHubContextService ( ) ;
91-
92- var context = target . FindContextFromUrl ( url ) ;
93-
94- Assert . That ( context . Path , Is . EqualTo ( expectPath ) ) ;
95- }
96-
97- // HACK: We're assuming that branches don't contain a '/' (sic)
98- [ TestCase ( "https://github.com/github/VisualStudio/blob/fixes/branch/buggy.cs" , "branch/buggy.cs" ) ]
99- public void ProblemPath ( string url , string expectPath )
100- {
101- var target = CreateGitHubContextService ( ) ;
102-
103- var context = target . FindContextFromUrl ( url ) ;
104-
105- Assert . That ( context . Path , Is . EqualTo ( expectPath ) ) ;
78+ Assert . That ( context . Treeish , Is . EqualTo ( expectTreeish ) ) ;
79+ Assert . That ( context . BlobName , Is . EqualTo ( expectBlobName ) ) ;
10680 }
10781
10882 [ TestCase ( "https://github.com" , null ) ]
@@ -307,16 +281,29 @@ public void Issue(string windowTitle, int expectIssue)
307281 Assert . That ( context . Issue , Is . EqualTo ( expectIssue ) ) ;
308282 }
309283
310- [ TestCase ( "VisualStudio/mark_github.xaml at master · github/VisualStudio - Google Chrome" , "mark_github.xaml" ) ]
311- [ TestCase ( "VisualStudio/src/GitHub.VisualStudio/Resources/icons at master · github/VisualStudio - Google Chrome" , "src/GitHub.VisualStudio/Resources/icons" ) ]
312- [ TestCase ( "VisualStudio/README.md at master · jcansdale/VisualStudio · GitHub - Mozilla Firefox" , "README.md" , Description = "Firefox" ) ]
313- public void Path ( string windowTitle , string expectPath )
284+ [ TestCase ( "VisualStudio/mark_github.xaml at master · github/VisualStudio - Google Chrome" , "mark_github.xaml" , "master" ) ]
285+ [ TestCase ( "VisualStudio/src/GitHub.VisualStudio/Resources/icons at master · github/VisualStudio - Google Chrome" , null , "master" ) ]
286+ [ TestCase ( "VisualStudio/src at master · github/VisualStudio - Google Chrome" , "src" , "master" , Description = "Can't differentiate between single level tree and blob" ) ]
287+ [ TestCase ( "VisualStudio/README.md at master · jcansdale/VisualStudio · GitHub - Mozilla Firefox" , "README.md" , "master" , Description = "Firefox" ) ]
288+ public void Blob ( string windowTitle , string expectBlobName , string expectBranchName )
314289 {
315290 var target = CreateGitHubContextService ( ) ;
316291
317292 var context = target . FindContextFromWindowTitle ( windowTitle ) ;
318293
319- Assert . That ( context ? . Path , Is . EqualTo ( expectPath ) ) ;
294+ Assert . That ( context ? . BlobName , Is . EqualTo ( expectBlobName ) ) ;
295+ Assert . That ( context ? . BranchName , Is . EqualTo ( expectBranchName ) ) ;
296+ }
297+
298+ [ TestCase ( "VisualStudio/src/GitHub.VisualStudio/Resources/icons at master · github/VisualStudio - Google Chrome" , "master/src/GitHub.VisualStudio/Resources/icons" , "master" ) ]
299+ public void Tree ( string windowTitle , string expectTreeish , string expectBranch )
300+ {
301+ var target = CreateGitHubContextService ( ) ;
302+
303+ var context = target . FindContextFromWindowTitle ( windowTitle ) ;
304+
305+ Assert . That ( context ? . Treeish , Is . EqualTo ( expectTreeish ) ) ;
306+ Assert . That ( context ? . BranchName , Is . EqualTo ( expectBranch ) ) ;
320307 }
321308
322309 [ TestCase ( "jcansdale/VisualStudio: GitHub Extension for Visual Studio - Google Chrome" , "jcansdale" , "VisualStudio" , Description = "Chrome" ) ]
@@ -334,6 +321,27 @@ public void RepositoryHome(string windowTitle, string expectOwner, string expect
334321 }
335322 }
336323
324+ public class TheResolvePathMethod
325+ {
326+ [ TestCase ( "https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/foo.cs" , "foo.cs" ) ]
327+ [ TestCase ( "https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/dir/foo.cs" , @"dir\foo.cs" ) ]
328+ [ TestCase ( "https://github.com/github/VisualStudio/blob/ee863ce265fc6217f589e66766125fed1b5b8256/dir/subdir/foo.cs" , @"dir\subdir\foo.cs" ) ]
329+ [ TestCase ( "https://github.com/github/VisualStudio/blob/master/foo.cs" , "foo.cs" ) ]
330+ [ TestCase ( "https://github.com/github/VisualStudio/blob/master/dir/foo.cs" , @"dir\foo.cs" ) ]
331+ [ TestCase ( "https://github.com/github/VisualStudio/blob/master/dir/subdir/foo.cs" , @"dir\subdir\foo.cs" ) ]
332+ [ TestCase ( "https://github.com/github/VisualStudio/blob/unknown-branch/dir/subdir/foo.cs" , null ) ]
333+ [ TestCase ( "https://github.com/github/VisualStudio/blob/unknown/branch/dir/subdir/foo.cs" , null ) ]
334+ public void ResolvePath ( string url , string expectPath )
335+ {
336+ var target = CreateGitHubContextService ( ) ;
337+ var context = target . FindContextFromUrl ( url ) ;
338+
339+ var path = target . ResolvePath ( context ) ;
340+
341+ Assert . That ( path , Is . EqualTo ( expectPath ) ) ;
342+ }
343+ }
344+
337345 static GitHubContextService CreateGitHubContextService ( )
338346 {
339347 var sp = Substitute . For < IServiceProvider > ( ) ;
0 commit comments