Skip to content

Commit

Permalink
test basic block nextBlock in if return
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Oct 2, 2024
1 parent 41292ae commit 9eba16f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Neo.Compiler.CSharp.UnitTests/Optimizer/BasicBlockTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Optimizer;
using Neo.SmartContract.Testing;
using System.Collections.Generic;
using System.Linq;

namespace Neo.Compiler.CSharp.UnitTests.Optimizer
{
[TestClass]
public class BasicBlockTests
{
[TestMethod]
public void Test_BasicBlockIfReturn()
{
//public static BigInteger Factorial(BigInteger a)
//{
// ExecutionEngine.Assert(a >= 0, "Minus number not supported");
// if (a >= 2) return a * Factorial(a - 1);
// return 1;
//}
ContractInBasicBlocks contract = new(Contract_Recursion.Nef, Contract_Recursion.Manifest);
List<BasicBlock> blocks = contract.sortedBasicBlocks;
Assert.AreEqual(blocks[0].nextBlock, blocks[1]);
Assert.AreEqual(blocks[0].jumpTargetBlocks.Count, 1);
Assert.AreEqual(blocks[0].jumpTargetBlocks.First(), blocks[3]);
Assert.AreEqual(blocks[0].instructions.Last().OpCode, VM.OpCode.JMPIFNOT);
Assert.AreEqual(blocks[1].instructions.Last().OpCode, VM.OpCode.CALL);
Assert.AreEqual(blocks[2].nextBlock, null);
Assert.AreEqual(blocks[2].instructions.Last().OpCode, VM.OpCode.RET);
}
}
}

0 comments on commit 9eba16f

Please sign in to comment.