-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a bit more test coverage for subreads.
- Loading branch information
1 parent
c95f722
commit 5fc9512
Showing
2 changed files
with
167 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
using NUnit.Framework; | ||
|
||
namespace schema.binary; | ||
|
||
internal class SubreadLocalSpaceTests { | ||
[Test] | ||
public void TestSubreadWithoutReturn() { | ||
using var br = new SchemaBinaryReader(new byte[100]); | ||
|
||
br.Position = 2; | ||
br.PushLocalSpace(); | ||
|
||
Assert.AreEqual(0, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
|
||
br.Position = 3; | ||
Assert.AreEqual(3, br.Position); | ||
|
||
br.Subread( | ||
50, | ||
sbr => { | ||
Assert.AreEqual(3, sbr.Position); | ||
Assert.AreEqual(53, sbr.Length); | ||
|
||
sbr.Position = 4; | ||
Assert.AreEqual(4, sbr.Position); | ||
Assert.AreEqual(53, sbr.Length); | ||
}); | ||
|
||
Assert.AreEqual(53, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
} | ||
|
||
[Test] | ||
public void TestSubreadWithReturn() { | ||
using var br = new SchemaBinaryReader(new byte[100]); | ||
|
||
br.Position = 2; | ||
br.PushLocalSpace(); | ||
|
||
Assert.AreEqual(0, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
|
||
br.Position = 3; | ||
Assert.AreEqual(3, br.Position); | ||
|
||
var returnValue = br.Subread( | ||
50, | ||
sbr => { | ||
Assert.AreEqual(3, sbr.Position); | ||
Assert.AreEqual(53, sbr.Length); | ||
|
||
sbr.Position = 4; | ||
Assert.AreEqual(4, sbr.Position); | ||
Assert.AreEqual(53, sbr.Length); | ||
|
||
return 123; | ||
}); | ||
Assert.AreEqual(123, returnValue); | ||
|
||
Assert.AreEqual(53, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
} | ||
|
||
[Test] | ||
public void TestSubreadAtWithoutLengthWithoutReturn() { | ||
using var br = new SchemaBinaryReader(new byte[100]); | ||
|
||
br.Position = 2; | ||
br.PushLocalSpace(); | ||
|
||
Assert.AreEqual(0, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
|
||
br.Position = 3; | ||
Assert.AreEqual(3, br.Position); | ||
|
||
br.SubreadAt( | ||
4, | ||
sbr => { | ||
Assert.AreEqual(4, sbr.Position); | ||
Assert.AreEqual(98, sbr.Length); | ||
}); | ||
|
||
Assert.AreEqual(3, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
} | ||
|
||
[Test] | ||
public void TestSubreadAtWithLengthWithoutReturn() { | ||
using var br = new SchemaBinaryReader(new byte[100]); | ||
|
||
br.Position = 2; | ||
br.PushLocalSpace(); | ||
|
||
Assert.AreEqual(0, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
|
||
br.Position = 3; | ||
Assert.AreEqual(3, br.Position); | ||
|
||
br.SubreadAt( | ||
4, | ||
50, | ||
sbr => { | ||
Assert.AreEqual(4, sbr.Position); | ||
Assert.AreEqual(54, sbr.Length); | ||
}); | ||
|
||
Assert.AreEqual(3, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
} | ||
|
||
[Test] | ||
public void TestSubreadAtWithoutLengthWithReturn() { | ||
using var br = new SchemaBinaryReader(new byte[100]); | ||
|
||
br.Position = 2; | ||
br.PushLocalSpace(); | ||
|
||
Assert.AreEqual(0, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
|
||
br.Position = 3; | ||
Assert.AreEqual(3, br.Position); | ||
|
||
var returnValue = br.SubreadAt( | ||
4, | ||
sbr => { | ||
Assert.AreEqual(4, sbr.Position); | ||
Assert.AreEqual(98, sbr.Length); | ||
return 123; | ||
}); | ||
Assert.AreEqual(123, returnValue); | ||
|
||
Assert.AreEqual(3, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
} | ||
|
||
[Test] | ||
public void TestSubreadAtWithLengthWithReturn() { | ||
using var br = new SchemaBinaryReader(new byte[100]); | ||
|
||
br.Position = 2; | ||
br.PushLocalSpace(); | ||
|
||
Assert.AreEqual(0, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
|
||
br.Position = 3; | ||
Assert.AreEqual(3, br.Position); | ||
|
||
var returnValue = br.SubreadAt( | ||
4, | ||
50, | ||
sbr => { | ||
Assert.AreEqual(4, sbr.Position); | ||
Assert.AreEqual(54, sbr.Length); | ||
return 123; | ||
}); | ||
Assert.AreEqual(123, returnValue); | ||
|
||
Assert.AreEqual(3, br.Position); | ||
Assert.AreEqual(98, br.Length); | ||
} | ||
} |
This file contains 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