From 9875662562cbe85d1174642222a48dabf20b7ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20K=C3=A4ll=C3=A9n?= Date: Sun, 9 Dec 2012 20:11:15 +0100 Subject: [PATCH] Test demonstrating that a const field of type decimal is not considered constant by the cecil loader. --- .../TypeSystem/TypeSystemTests.TestCase.cs | 16 +++++++++++++ .../TypeSystem/TypeSystemTests.cs | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs index a924905106..7d18043c5a 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs @@ -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; + } } diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs index aa5e474033..c056c25671 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs @@ -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(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(type, "Cb", 42); + AssertConstantField(type, "Csb", 42); + AssertConstantField(type, "Cc", '\x42'); + AssertConstantField(type, "Cs", 42); + AssertConstantField(type, "Cus", 42); + AssertConstantField(type, "Ci", 42); + AssertConstantField(type, "Cui", 42); + AssertConstantField(type, "Cl", 42); + AssertConstantField(type, "Cul", 42); + AssertConstantField(type, "Cd", 42); + AssertConstantField(type, "Cf", 42); + AssertConstantField(type, "Cm", 42); + } } }