-
Notifications
You must be signed in to change notification settings - Fork 49
Async operations + updated frameworks #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adimosh
wants to merge
7
commits into
CharsetDetector:master
Choose a base branch
from
adimosh:async-operations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cb825b7
Updated framework versions to latest supported.
adimosh ed0ec2c
Added async methods and unit tests. Made changes specific to .NET 6.
adimosh c3ba6ca
Missed AppVeyor YML file update.
adimosh 9a94763
Updated test project due to version typo.
adimosh b37dd4d
Merge branch 'master' into async-operations
adimosh a9c0776
Updated target framework version according to Julian's requirements.
adimosh e3946a4
Deduplicated code in CharsetDetector after async copy/paste.
adimosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,12 @@ | |
// Rudi Pettazzi <[email protected]> | ||
// | ||
|
||
#region | ||
|
||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UtfUnknown.Core; | ||
using NUnit.Framework; | ||
|
||
#endregion | ||
|
||
namespace UtfUnknown.Tests | ||
{ | ||
public class CharsetDetectorTest | ||
|
@@ -34,6 +31,23 @@ public void TestAscii() | |
} | ||
} | ||
|
||
[Test] | ||
public async Task TestAsciiAsync() | ||
{ | ||
const string text = "The Documentation of the libraries is not complete " + | ||
"and your contributions would be greatly appreciated " + | ||
"the documentation you want to contribute to and " + | ||
"click on the [Edit] link to start writing"; | ||
var stream = AsciiToStream(text); | ||
using (stream) | ||
{ | ||
var result = await CharsetDetector.DetectFromStreamAsync(stream); | ||
Assert.AreEqual(CodepageName.ASCII, result.Detected.EncodingName); | ||
Assert.AreEqual(1.0f, result.Detected.Confidence); | ||
Assert.IsFalse(result.Detected.HasBOM); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestAscii_with_HZ_sequence() | ||
{ | ||
|
@@ -47,6 +61,19 @@ public void TestAscii_with_HZ_sequence() | |
} | ||
} | ||
|
||
[Test] | ||
public async Task TestAscii_with_HZ_sequenceAsync() | ||
{ | ||
const string text = "virtual ~{{NETCLASS_NAME}}();"; | ||
var stream = AsciiToStream(text); | ||
using (stream) | ||
{ | ||
var result = await CharsetDetector.DetectFromStreamAsync(stream); | ||
Assert.AreEqual(CodepageName.ASCII, result.Detected.EncodingName); | ||
Assert.AreEqual(1.0f, result.Detected.Confidence); | ||
} | ||
} | ||
|
||
private static MemoryStream AsciiToStream(string s) | ||
{ | ||
return new MemoryStream(Encoding.ASCII.GetBytes(s)); | ||
|
@@ -74,6 +101,28 @@ public void DetectFromStreamMaxBytes(int? maxBytes, int expectedPosition, int st | |
Assert.AreEqual(expectedPosition, stream.Position); | ||
} | ||
|
||
[Test] | ||
[TestCase(1024, 1024)] | ||
[TestCase(2048, 2048)] | ||
[TestCase(20, 20)] | ||
[TestCase(20, 30, 10)] | ||
[TestCase(null, 10000)] | ||
[TestCase(1000000, 10000)] | ||
[TestCase(null, 10000, 10)] | ||
public async Task DetectFromStreamMaxBytesAsync(int? maxBytes, int expectedPosition, int start = 0) | ||
{ | ||
// Arrange | ||
var text = new string('a', 10000); | ||
var stream = AsciiToStream(text); | ||
stream.Position = start; | ||
|
||
// Act | ||
await CharsetDetector.DetectFromStreamAsync(stream, maxBytes); | ||
|
||
// Assert | ||
Assert.AreEqual(expectedPosition, stream.Position); | ||
} | ||
|
||
[Test] | ||
[TestCase(0, 10, CodepageName.ASCII)] | ||
[TestCase(0, 100, CodepageName.UTF8)] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.