-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCastTests.cs
29 lines (26 loc) · 1.25 KB
/
CastTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Cecilifier.Core.Tests.Tests.Unit.Framework;
using NUnit.Framework;
namespace Cecilifier.Core.Tests.Tests.Unit;
[TestFixture]
public class CastTests : CecilifierUnitTestBase
{
[Test]
public void Unbox()
{
var result = RunCecilifier("int UnboxIt(object o) => (int) o;");
Assert.That(result.GeneratedCode.ReadToEnd(), Does.Match("""
(il_unboxIt_\d+\.Emit\(OpCodes\.)Ldarg_0\);
\s+\1Unbox_Any, assembly.MainModule.TypeSystem.Int32\);
"""));
}
[TestCase("i", TestName = "Implicit boxing")]
[TestCase("(object) i", TestName = "Explicit boxing")]
public void Box(string expression)
{
var result = RunCecilifier($"object BoxIt(int i) => {expression};");
Assert.That(result.GeneratedCode.ReadToEnd(), Does.Match("""
(il_boxIt_\d+\.Emit\(OpCodes\.)Ldarg_0\);
\s+\1Box, assembly.MainModule.TypeSystem.Int32\);
"""));
}
}