Skip to content

Commit

Permalink
- Also allow fallback for table
Browse files Browse the repository at this point in the history
- Add CheckParents and checkParents everywhere
- Change tests for new behavior
- Add suppor for another format + test
  • Loading branch information
KoalaBear84 committed Sep 12, 2021
1 parent c9f58d6 commit 20c2a54
Show file tree
Hide file tree
Showing 8 changed files with 907 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ public async Task TestDirectoryListing40aAsync()
[Fact]
public async Task TestDirectoryListing40bAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());
WebDirectory webDirectory = await ParseHtml(GetSample(), "http://www.funreading.com.hk/primary/computer/download/");

Assert.Equal("ROOT", webDirectory.Name);
Assert.Equal("download", webDirectory.Name);
Assert.Empty(webDirectory.Subdirectories);
Assert.Empty(webDirectory.Files);
}
Expand Down Expand Up @@ -686,7 +686,7 @@ public async Task TestDirectoryListing47bAsync()
[Fact]
public async Task TestDirectoryListing48aAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());
WebDirectory webDirectory = await ParseHtml(GetSample(), checkParents: false);

Assert.Equal("ROOT", webDirectory.Name);
Assert.Single(webDirectory.Subdirectories);
Expand All @@ -702,7 +702,7 @@ public async Task TestDirectoryListing48aAsync()
[Fact]
public async Task TestDirectoryListing48bAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());
WebDirectory webDirectory = await ParseHtml(GetSample(), checkParents: false);

Assert.Equal("ROOT", webDirectory.Name);
Assert.Empty(webDirectory.Subdirectories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public async Task TestDirectoryListing71bAsync()
[Fact]
public async Task TestDirectoryListing72aAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());
WebDirectory webDirectory = await ParseHtml(GetSample(), checkParents: false);

Assert.Equal("ROOT", webDirectory.Name);
Assert.Equal(9, webDirectory.Subdirectories.Count);
Expand All @@ -653,7 +653,7 @@ public async Task TestDirectoryListing72aAsync()
[Fact]
public async Task TestDirectoryListing72bAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());
WebDirectory webDirectory = await ParseHtml(GetSample(), checkParents: false);

Assert.Equal("ROOT", webDirectory.Name);
Assert.Single(webDirectory.Subdirectories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task TestDirectoryListing75bAsync()
[Fact]
public async Task TestDirectoryListing76aAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());
WebDirectory webDirectory = await ParseHtml(GetSample(), checkParents: false);

Assert.Equal("ROOT", webDirectory.Name);
Assert.Empty(webDirectory.Subdirectories);
Expand All @@ -60,7 +60,7 @@ public async Task TestDirectoryListing76aAsync()
[Fact]
public async Task TestDirectoryListing77aAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());
WebDirectory webDirectory = await ParseHtml(GetSample(), checkParents: false);

Assert.Equal("ROOT", webDirectory.Name);
Assert.Empty(webDirectory.Subdirectories);
Expand Down Expand Up @@ -214,7 +214,7 @@ public async Task TestDirectoryListing82bAsync()
[Fact]
public async Task TestDirectoryListing83aAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());
WebDirectory webDirectory = await ParseHtml(GetSample(), checkParents: false);

Assert.Equal("ROOT", webDirectory.Name);
Assert.Empty(webDirectory.Subdirectories);
Expand Down Expand Up @@ -411,7 +411,7 @@ public async Task TestDirectoryListing89cAsync()
WebDirectory webDirectory = await ParseHtml(GetSample());

Assert.Equal("ROOT", webDirectory.Name);
Assert.Equal(4, webDirectory.Subdirectories.Count);
Assert.Equal(3, webDirectory.Subdirectories.Count);
Assert.Equal("本子", webDirectory.Subdirectories[0].Name);
Assert.Empty(webDirectory.Files);
}
Expand Down
15 changes: 15 additions & 0 deletions src/OpenDirectoryDownloader.Tests/DirectoryParser101_125Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,20 @@ public async Task TestDirectoryListing122bAsync()
Assert.Equal("acjp_hayden01.ram", webDirectory.Files[0].FileName);
Assert.Equal(Constants.NoFileSize, webDirectory.Files[0].FileSize);
}

/// <summary>
/// Url: http://www.diggerhistory.info/images/uniforms4/
/// </summary>
[Fact]
public async Task TestDirectoryListing123aAsync()
{
WebDirectory webDirectory = await ParseHtml(GetSample());

Assert.Equal("ROOT", webDirectory.Name);
Assert.Empty(webDirectory.Subdirectories);
Assert.Equal(588, webDirectory.Files.Count);
Assert.Equal("101-engr.jpg", webDirectory.Files[0].FileName);
Assert.Equal(Constants.NoFileSize, webDirectory.Files[0].FileSize);
}
}
}
4 changes: 2 additions & 2 deletions src/OpenDirectoryDownloader.Tests/DirectoryParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public static void CleanWebDirectory(WebDirectory webDirectory, Uri testedUri)
}).ToList().ForEach(wd => webDirectory.Files.Remove(wd));
}

public static async Task<WebDirectory> ParseHtml(string html, string url = "http://localhost/")
public static async Task<WebDirectory> ParseHtml(string html, string url = "http://localhost/", bool checkParents = true)
{
return await DirectoryParser.ParseHtml(new WebDirectory(null) { Url = url }, html);
return await DirectoryParser.ParseHtml(new WebDirectory(null) { Url = url }, html, checkParents: checkParents);
}
}
}
Loading

0 comments on commit 20c2a54

Please sign in to comment.