From ffc69f2c7db4372a1c9dcc1f31f3f0ce21db1a84 Mon Sep 17 00:00:00 2001 From: rameel Date: Mon, 23 Nov 2026 14:31:55 +0500 Subject: [PATCH 1/2] parser: replace the TypeUtils tests with expression tests --- .../Data/Errors.txt | 3 ++ .../Data/Expressions.txt | 24 ++++++++++++ .../TypeUtilsTest.cs | 37 ------------------- 3 files changed, 27 insertions(+), 37 deletions(-) delete mode 100644 tests/Ramstack.ExpressionParser.Tests/TypeUtilsTest.cs diff --git a/tests/Ramstack.ExpressionParser.Tests/Data/Errors.txt b/tests/Ramstack.ExpressionParser.Tests/Data/Errors.txt index d4852ae..1bdffc0 100644 --- a/tests/Ramstack.ExpressionParser.Tests/Data/Errors.txt +++ b/tests/Ramstack.ExpressionParser.Tests/Data/Errors.txt @@ -242,6 +242,9 @@ Operator '==' cannot be applied to operands of type 'System.DayOfWeek' and 'Syst true ? 1.0 : 2m Operator '?:' cannot be applied to operands of type 'System.Double' and 'System.Decimal'. +true ? 1.0f : 2m +Operator '?:' cannot be applied to operands of type 'System.Single' and 'System.Decimal'. + true ? 1 : 1ul Operator '?:' cannot be applied to operands of type 'System.Int32' and 'System.UInt64'. diff --git a/tests/Ramstack.ExpressionParser.Tests/Data/Expressions.txt b/tests/Ramstack.ExpressionParser.Tests/Data/Expressions.txt index af18b65..f10c665 100644 --- a/tests/Ramstack.ExpressionParser.Tests/Data/Expressions.txt +++ b/tests/Ramstack.ExpressionParser.Tests/Data/Expressions.txt @@ -540,6 +540,30 @@ IIF(True, Convert(1, Double), 2) false ? 1 : 2m IIF(False, Convert(1, Decimal), 2) +false ? 'a' : 2m +IIF(False, Convert(a, Decimal), 2) + +false ? 1 :> sbyte : 2m +IIF(False, Convert(Convert(1, SByte), Decimal), 2) + +false ? 1 :> byte : 2m +IIF(False, Convert(Convert(1, Byte), Decimal), 2) + +false ? 1 :> short : 2m +IIF(False, Convert(Convert(1, Int16), Decimal), 2) + +false ? 1 :> ushort : 2m +IIF(False, Convert(Convert(1, UInt16), Decimal), 2) + +false ? 1u : 2m +IIF(False, Convert(1, Decimal), 2) + +false ? 1L : 2m +IIF(False, Convert(1, Decimal), 2) + +false ? 1ul : 2m +IIF(False, Convert(1, Decimal), 2) + true ? 'a' : 1 IIF(True, Convert(a, Int32), 1) diff --git a/tests/Ramstack.ExpressionParser.Tests/TypeUtilsTest.cs b/tests/Ramstack.ExpressionParser.Tests/TypeUtilsTest.cs deleted file mode 100644 index 3a9baca..0000000 --- a/tests/Ramstack.ExpressionParser.Tests/TypeUtilsTest.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Ramstack.Parsing.Internal; - -namespace Ramstack.Parsing; - -[TestFixture] -public class TypeUtilsTest -{ - [TestCase(typeof(char))] - [TestCase(typeof(sbyte))] - [TestCase(typeof(byte))] - [TestCase(typeof(short))] - [TestCase(typeof(ushort))] - [TestCase(typeof(int))] - [TestCase(typeof(uint))] - [TestCase(typeof(long))] - [TestCase(typeof(ulong))] - public void CanConvertPrimitive_IntegerToDecimal_ReturnsTrue(Type source) => - Assert.That(TypeUtils.CanConvertPrimitive(source, typeof(decimal)), Is.True); - - [TestCase(typeof(float), typeof(decimal))] - [TestCase(typeof(double), typeof(decimal))] - [TestCase(typeof(decimal), typeof(float))] - [TestCase(typeof(decimal), typeof(double))] - [TestCase(typeof(decimal), typeof(int))] - public void CanConvertPrimitive_ExplicitDecimalConversion_ReturnsFalse(Type source, Type target) => - Assert.That(TypeUtils.CanConvertPrimitive(source, target), Is.False); - - [Test] - public void CanConvertPrimitive_ByteToChar_ReturnsFalse() => - Assert.That(TypeUtils.CanConvertPrimitive(typeof(byte), typeof(char)), Is.False); - - [TestCase(typeof(int), typeof(DayOfWeek))] - [TestCase(typeof(DayOfWeek), typeof(int))] - [TestCase(typeof(DayOfWeek), typeof(DayOfWeek))] - public void CanConvertPrimitive_Enum_ReturnsFalse(Type source, Type target) => - Assert.That(TypeUtils.CanConvertPrimitive(source, target), Is.False); -} From 237e9c94c83e41f4368bcb3e54d1a28a31ead610 Mon Sep 17 00:00:00 2001 From: rameel Date: Mon, 23 Nov 2026 14:32:40 +0500 Subject: [PATCH 2/2] repo: make TypeUtils internal The type was public only for the tests. It belongs to Ramstack.Parsing.Internal, like the other internal helpers. --- src/Ramstack.ExpressionParser/Internal/TypeUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs b/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs index 8d53112..0762217 100644 --- a/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs +++ b/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs @@ -5,7 +5,7 @@ namespace Ramstack.Parsing.Internal; /// /// Provides type utility methods. /// -public static class TypeUtils +internal static class TypeUtils { private static ReadOnlySpan PrimitiveConversions => [