Browse Source

Test demonstrating that a const field of type decimal is not considered constant by the cecil loader.

newNRvisualizers
Erik Källén 13 years ago
parent
commit
9875662562
  1. 16
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs
  2. 24
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

16
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs

@ -342,4 +342,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase @@ -342,4 +342,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase
private void Private() {}
void None() {}
}
public class ConstantFieldTest
{
public const byte Cb = 42;
public const sbyte Csb = 42;
public const char Cc = '\x42';
public const short Cs = 42;
public const ushort Cus = 42;
public const int Ci = 42;
public const uint Cui = 42;
public const long Cl = 42;
public const ulong Cul = 42;
public const double Cd = 42;
public const float Cf = 42;
public const decimal Cm = 42;
}
}

24
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -1228,5 +1228,29 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1228,5 +1228,29 @@ namespace ICSharpCode.NRefactory.TypeSystem
Assert.AreEqual(Accessibility.Private, type.Methods.Single(m => m.Name == "Private").Accessibility);
Assert.AreEqual(Accessibility.Private, type.Methods.Single(m => m.Name == "None").Accessibility);
}
private void AssertConstantField<T>(ITypeDefinition type, string name, T expected) {
var f = type.GetFields().Single(x => x.Name == name);
Assert.IsTrue(f.IsConst);
Assert.AreEqual(expected, f.ConstantValue);
}
[Test]
public void ConstantFields()
{
ITypeDefinition type = GetTypeDefinition(typeof(ConstantFieldTest));
AssertConstantField<byte>(type, "Cb", 42);
AssertConstantField<sbyte>(type, "Csb", 42);
AssertConstantField<char>(type, "Cc", '\x42');
AssertConstantField<short>(type, "Cs", 42);
AssertConstantField<ushort>(type, "Cus", 42);
AssertConstantField<int>(type, "Ci", 42);
AssertConstantField<uint>(type, "Cui", 42);
AssertConstantField<long>(type, "Cl", 42);
AssertConstantField<ulong>(type, "Cul", 42);
AssertConstantField<double>(type, "Cd", 42);
AssertConstantField<float>(type, "Cf", 42);
AssertConstantField<decimal>(type, "Cm", 42);
}
}
}

Loading…
Cancel
Save