Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/MethodCheck.Test/BinaryProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,46 @@ class BinaryProcessorTest
[Test]
public void ParseEmpty()
{
var blob = BinaryProcessor.Parse(string.Empty.AsSpan());
var blob = BinaryProcessor.Parse([]);
Assert.That(blob, Is.Empty);
}

[Test]
public void Parse()
{
var blob = BinaryProcessor.Parse("42 51 0A\r\n\r\n54".AsSpan());
Assert.That(blob, Is.EqualTo(new byte[] { 0x42, 0x51, 0x0A, 0x54 }));
Assert.That(blob, Is.EqualTo([0x42, 0x51, 0x0A, 0x54]));
}

[Test]
public void ParseHalfByte()
{
var blob = BinaryProcessor.Parse("4".AsSpan());
Assert.That(blob, Is.EqualTo(new byte[] { 0x40 }));
Assert.That(blob, Is.EqualTo([0x40]));
}

[Test]
public void ParseComments()
{
var blob = BinaryProcessor.Parse("42 51 0A // 05\r\n\r\n54".AsSpan());
Assert.That(blob, Is.EqualTo(new byte[] { 0x42, 0x51, 0x0A, 0x54 }));
Assert.That(blob, Is.EqualTo([0x42, 0x51, 0x0A, 0x54]));
}

[Test]
public void FormatEmpty()
{
Assert.That(BinaryProcessor.Format(Array.Empty<byte>()), Is.EqualTo(string.Empty));
Assert.That(BinaryProcessor.Format([]), Is.EqualTo(string.Empty));
}

[Test]
public void Format()
{
const string Expected =
@"00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20";
"""
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20
""";

ReadOnlySpan<byte> blob = new byte[]
{
Expand Down
220 changes: 118 additions & 102 deletions src/MethodCheck.Test/SectionFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class SectionFactoryTest
public void Empty()
{
const string Expected =
@"<il range=""IL_0000 (10)"" />";
"""
<il range="IL_0000 (10)" />
""";

var section = SectionFactory.Create(new ILRange(0, 10), Array.Empty<ExceptionHandler>());

Expand All @@ -28,14 +30,16 @@ public void Empty()
public void Catch()
{
const string Expected =
@"<try range=""IL_0000 (10)"">
<try.block>
<il range=""IL_0000 (6)"" />
</try.block>
<handler type=""Clause"" exception=""02000010"">
<il range=""IL_0006 (4)"" />
</handler>
</try>";
"""
<try range="IL_0000 (10)">
<try.block>
<il range="IL_0000 (6)" />
</try.block>
<handler type="Clause" exception="02000010">
<il range="IL_0006 (4)" />
</handler>
</try>
""";

var handlers = new[]
{
Expand All @@ -51,14 +55,16 @@ public void Catch()
public void Finally()
{
const string Expected =
@"<try range=""IL_0000 (10)"">
<try.block>
<il range=""IL_0000 (6)"" />
</try.block>
<handler type=""Finally"">
<il range=""IL_0006 (4)"" />
</handler>
</try>";
"""
<try range="IL_0000 (10)">
<try.block>
<il range="IL_0000 (6)" />
</try.block>
<handler type="Finally">
<il range="IL_0006 (4)" />
</handler>
</try>
""";

var handlers = new[]
{
Expand All @@ -74,17 +80,19 @@ public void Finally()
public void Filter()
{
const string Expected =
@"<try range=""IL_0000 (12)"">
<try.block>
<il range=""IL_0000 (3)"" />
</try.block>
<handler type=""Filter"">
<filter>
<il range=""IL_0003 (4)"" />
</filter>
<il range=""IL_0007 (5)"" />
</handler>
</try>";
"""
<try range="IL_0000 (12)">
<try.block>
<il range="IL_0000 (3)" />
</try.block>
<handler type="Filter">
<filter>
<il range="IL_0003 (4)" />
</filter>
<il range="IL_0007 (5)" />
</handler>
</try>
""";

var handlers = new[]
{
Expand All @@ -100,17 +108,19 @@ public void Filter()
public void OverlappingTry()
{
const string Expected =
@"<try range=""IL_0000 (10)"">
<try.block>
<il range=""IL_0000 (2)"" />
</try.block>
<handler type=""Clause"" exception=""02000011"">
<il range=""IL_0002 (4)"" />
</handler>
<handler type=""Clause"" exception=""02000012"">
<il range=""IL_0006 (4)"" />
</handler>
</try>";
"""
<try range="IL_0000 (10)">
<try.block>
<il range="IL_0000 (2)" />
</try.block>
<handler type="Clause" exception="02000011">
<il range="IL_0002 (4)" />
</handler>
<handler type="Clause" exception="02000012">
<il range="IL_0006 (4)" />
</handler>
</try>
""";

var handlers = new[]
{
Expand All @@ -127,28 +137,30 @@ public void OverlappingTry()
public void Nested()
{
const string Expected =
@"<try range=""IL_0000 (20)"">
<try.block>
<try range=""IL_0000 (10)"">
<try.block>
<il range=""IL_0000 (5)"" />
</try.block>
<handler type=""Clause"" exception=""02000010"">
<il range=""IL_0005 (5)"" />
</handler>
</try>
</try.block>
<handler type=""Finally"">
<try range=""IL_000A (10)"">
<try.block>
<il range=""IL_000A (5)"" />
</try.block>
<handler type=""Clause"" exception=""02000010"">
<il range=""IL_000F (5)"" />
</handler>
</try>
</handler>
</try>";
"""
<try range="IL_0000 (20)">
<try.block>
<try range="IL_0000 (10)">
<try.block>
<il range="IL_0000 (5)" />
</try.block>
<handler type="Clause" exception="02000010">
<il range="IL_0005 (5)" />
</handler>
</try>
</try.block>
<handler type="Finally">
<try range="IL_000A (10)">
<try.block>
<il range="IL_000A (5)" />
</try.block>
<handler type="Clause" exception="02000010">
<il range="IL_000F (5)" />
</handler>
</try>
</handler>
</try>
""";

var handlers = new[]
{
Expand All @@ -166,27 +178,29 @@ public void Nested()
public void Sequence()
{
const string Expected =
@"<seq range=""IL_0000 (22)"">
<il range=""IL_0000 (2)"" />
<try range=""IL_0002 (8)"">
<try.block>
<il range=""IL_0002 (4)"" />
</try.block>
<handler type=""Clause"" exception=""02000010"">
<il range=""IL_0006 (4)"" />
</handler>
</try>
<il range=""IL_000A (2)"" />
<try range=""IL_000C (8)"">
<try.block>
<il range=""IL_000C (4)"" />
</try.block>
<handler type=""Clause"" exception=""02000010"">
<il range=""IL_0010 (4)"" />
</handler>
</try>
<il range=""IL_0014 (2)"" />
</seq>";
"""
<seq range="IL_0000 (22)">
<il range="IL_0000 (2)" />
<try range="IL_0002 (8)">
<try.block>
<il range="IL_0002 (4)" />
</try.block>
<handler type="Clause" exception="02000010">
<il range="IL_0006 (4)" />
</handler>
</try>
<il range="IL_000A (2)" />
<try range="IL_000C (8)">
<try.block>
<il range="IL_000C (4)" />
</try.block>
<handler type="Clause" exception="02000010">
<il range="IL_0010 (4)" />
</handler>
</try>
<il range="IL_0014 (2)" />
</seq>
""";

var handlers = new[]
{
Expand All @@ -203,25 +217,27 @@ public void Sequence()
public void NestedSequence()
{
const string Expected =
@"<try range=""IL_0000 (10)"">
<try.block>
<seq range=""IL_0000 (8)"">
<il range=""IL_0000 (2)"" />
<try range=""IL_0002 (4)"">
<try.block>
<il range=""IL_0002 (2)"" />
</try.block>
<handler type=""Clause"" exception=""02000010"">
<il range=""IL_0004 (2)"" />
</handler>
</try>
<il range=""IL_0006 (2)"" />
</seq>
</try.block>
<handler type=""Finally"">
<il range=""IL_0008 (2)"" />
</handler>
</try>";
"""
<try range="IL_0000 (10)">
<try.block>
<seq range="IL_0000 (8)">
<il range="IL_0000 (2)" />
<try range="IL_0002 (4)">
<try.block>
<il range="IL_0002 (2)" />
</try.block>
<handler type="Clause" exception="02000010">
<il range="IL_0004 (2)" />
</handler>
</try>
<il range="IL_0006 (2)" />
</seq>
</try.block>
<handler type="Finally">
<il range="IL_0008 (2)" />
</handler>
</try>
""";

var handlers = new[]
{
Expand Down Expand Up @@ -275,7 +291,7 @@ static string Format(BaseSection section)
var settings = new XmlWriterSettings()
{
Indent = true,
IndentChars = " ",
IndentChars = "\t",
OmitXmlDeclaration = true,
};

Expand Down