Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
winscripter authored Jul 25, 2024
1 parent 18d38bc commit 87db902
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
59 changes: 30 additions & 29 deletions ILSourceParser.Tests/InstructionTests.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
using ILSourceParser.Syntax;
using Sprache;

namespace ILSourceParser.Tests;

public class InstructionTests
{
/// <summary>
/// A test to validate the IL ldsfld opcode.
/// </summary>
[Fact]
public void OpCodeLdsFldComplex()
{
var parser = new Parser();
var ldsfld = parser.ParseLdsfldInstruction();
var r = ldsfld.Parse(@"ldsfld class [System.Linq.Expressions]System.Runtime.CompilerServices.CallSite`1<class [System.Runtime]System.Func`3<class [System.Linq.Expressions]System.Runtime.CompilerServices.CallSite, object, int32>> C/'<>o__0'::'<>p__1'");

var result = (r.FieldType as GenericTypeReferenceSyntax)!;
Assert.Equal("System.Linq.Expressions", result.AssemblyReference!.AssemblyName);
Assert.Equal("System.Runtime.CompilerServices.CallSite`1", result.ClassName!);
Assert.Single(result.GenericArguments!.Parameters);
Assert.True(result.GenericArguments!.Parameters.All(arg => arg is GenericParameterTypeConstraintSyntax));

Assert.Equal("C/'<>o__0'",
(r.Target.DeclaringTypeReference as NonGenericTypeReferenceSyntax)!.GetNameOfType());

Assert.Equal("<>p__1", r.Target.FieldOrPropertyName);
}
}
using ILSourceParser.Syntax;
using ILSourceParser.Utilities;
using Sprache;

namespace ILSourceParser.Tests;

public class InstructionTests
{
/// <summary>
/// A test to validate the IL ldsfld opcode.
/// </summary>
[Fact]
public void OpCodeLdsFldComplex()
{
var parser = new Parser();
var ldsfld = parser.ParseLdsfldInstruction();
var r = ldsfld.Parse(@"ldsfld class [System.Linq.Expressions]System.Runtime.CompilerServices.CallSite`1<class [System.Runtime]System.Func`3<class [System.Linq.Expressions]System.Runtime.CompilerServices.CallSite, object, int32>> C/'<>o__0'::'<>p__1'");

var result = (r.FieldType as GenericTypeReferenceSyntax)!;
Assert.Equal("System.Linq.Expressions", result.AssemblyReference!.AssemblyName);
Assert.Equal("System.Runtime.CompilerServices.CallSite`1", result.ClassName!);
Assert.Single(result.GenericArguments!.Parameters);
Assert.True(result.GenericArguments!.Parameters.All(arg => arg is GenericParameterTypeConstraintSyntax));

Assert.Equal("C/'<>o__0'",
(r.Target.DeclaringTypeReference as NonGenericTypeReferenceSyntax)!.GetNameOfType());

Check failure on line 26 in ILSourceParser.Tests/InstructionTests.cs

View workflow job for this annotation

GitHub Actions / build

'NonGenericTypeReferenceSyntax' does not contain a definition for 'GetNameOfType' and no accessible extension method 'GetNameOfType' accepting a first argument of type 'NonGenericTypeReferenceSyntax' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 26 in ILSourceParser.Tests/InstructionTests.cs

View workflow job for this annotation

GitHub Actions / build

'NonGenericTypeReferenceSyntax' does not contain a definition for 'GetNameOfType' and no accessible extension method 'GetNameOfType' accepting a first argument of type 'NonGenericTypeReferenceSyntax' could be found (are you missing a using directive or an assembly reference?)

Assert.Equal("<>p__1", r.Target.FieldOrPropertyName);
}
}
36 changes: 18 additions & 18 deletions ILSourceParser.Tests/VerTest.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using Sprache;

namespace ILSourceParser.Tests;

public class VerTest
{
[Fact]
public void Test()
{
const string input = @".ver 1:2:3:4";
var result = new Parser().ParseVerDirective().Parse(input);

Assert.Equal('1', result.Major);
Assert.Equal('2', result.Minor);
Assert.Equal('3', result.Build);
Assert.Equal('4', result.Revision);
}
}
using Sprache;

namespace ILSourceParser.Tests;

public class VerTest
{
[Fact]
public void Test()
{
const string input = @".ver 1:2:3:4";
var result = Parser.ParseVerDirective().Parse(input);

Assert.Equal('1', result.Major);
Assert.Equal('2', result.Minor);
Assert.Equal('3', result.Build);
Assert.Equal('4', result.Revision);
}
}

0 comments on commit 87db902

Please sign in to comment.