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 => [ 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); -}