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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
using System;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
using NUnit.Framework;
namespace Mono.Cecil.Tests {
[TestFixture]
public class VariableTests : BaseTestFixture {
[Test]
public void AddVariableIndex ()
{
var object_ref = new TypeReference ("System", "Object", null, null, false);
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref);
var body = new MethodBody (method);
var x = new VariableDefinition (object_ref);
var y = new VariableDefinition (object_ref);
body.Variables.Add (x);
body.Variables.Add (y);
Assert.AreEqual (0, x.Index);
Assert.AreEqual (1, y.Index);
}
[Test]
public void RemoveAtVariableIndex ()
{
var object_ref = new TypeReference ("System", "Object", null, null, false);
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref);
var body = new MethodBody (method);
var x = new VariableDefinition (object_ref);
var y = new VariableDefinition (object_ref);
var z = new VariableDefinition (object_ref);
body.Variables.Add (x);
body.Variables.Add (y);
body.Variables.Add (z);
Assert.AreEqual (0, x.Index);
Assert.AreEqual (1, y.Index);
Assert.AreEqual (2, z.Index);
body.Variables.RemoveAt (1);
Assert.AreEqual (0, x.Index);
Assert.AreEqual (-1, y.Index);
Assert.AreEqual (1, z.Index);
}
[Test]
public void RemoveVariableIndex ()
{
var object_ref = new TypeReference ("System", "Object", null, null, false);
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref);
var body = new MethodBody (method);
var x = new VariableDefinition (object_ref);
var y = new VariableDefinition (object_ref);
var z = new VariableDefinition (object_ref);
body.Variables.Add (x);
body.Variables.Add (y);
body.Variables.Add (z);
Assert.AreEqual (0, x.Index);
Assert.AreEqual (1, y.Index);
Assert.AreEqual (2, z.Index);
body.Variables.Remove (y);
Assert.AreEqual (0, x.Index);
Assert.AreEqual (-1, y.Index);
Assert.AreEqual (1, z.Index);
}
[Test]
public void InsertVariableIndex ()
{
var object_ref = new TypeReference ("System", "Object", null, null, false);
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref);
var body = new MethodBody (method);
var x = new VariableDefinition (object_ref);
var y = new VariableDefinition (object_ref);
var z = new VariableDefinition (object_ref);
body.Variables.Add (x);
body.Variables.Add (z);
Assert.AreEqual (0, x.Index);
Assert.AreEqual (-1, y.Index);
Assert.AreEqual (1, z.Index);
body.Variables.Insert (1, y);
Assert.AreEqual (0, x.Index);
Assert.AreEqual (1, y.Index);
Assert.AreEqual (2, z.Index);
}
}
}
|