Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Dec 12, 2024
1 parent 9fb33f4 commit 8a4e842
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

//$Authors = Jiri Cincura ([email protected])

using System;
using System.Linq;
using System.Threading.Tasks;
using FirebirdSql.EntityFrameworkCore.Firebird.FunctionalTests.Helpers;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Xunit;

Expand Down Expand Up @@ -134,6 +137,13 @@ public override Task Where_mathf_radians(bool async)
return base.Where_mathf_radians(async);
}

[NotSupportedOnFirebirdTheory]
[MemberData(nameof(IsAsyncData))]
public override Task String_Join_non_aggregate(bool async)
{
return AssertTranslationFailed(() => base.String_Join_non_aggregate(async));
}

[NotSupportedByProviderTheory]
[MemberData(nameof(IsAsyncData))]
public override Task Regex_IsMatch_MethodCall(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class FbMathTranslator : IMethodCallTranslator
{ typeof(Math).GetRuntimeMethod(nameof(Math.Log10), new[] { typeof(double) }), "LOG10" },

{ typeof(Math).GetRuntimeMethod(nameof(Math.Log), new[] { typeof(double) }), "LN" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Log), new[] { typeof(double), typeof(double) }), "LOG" },

{ typeof(Math).GetRuntimeMethod(nameof(Math.Sqrt), new[] { typeof(double) }), "SQRT" },

Expand All @@ -77,30 +76,6 @@ public class FbMathTranslator : IMethodCallTranslator
{ typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(double) }), "SIGN" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(decimal) }), "SIGN" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(short) }), "SIGN" },

{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(float), typeof(float) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(sbyte), typeof(sbyte) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(ulong), typeof(ulong) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(uint), typeof(uint) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(long), typeof(long) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(ushort), typeof(ushort) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(short), typeof(short) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(double), typeof(double) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(decimal), typeof(decimal) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(byte), typeof(byte) }), "MAXVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(int), typeof(int) }), "MAXVALUE" },

{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(float), typeof(float) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(sbyte), typeof(sbyte) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(ulong), typeof(ulong) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(uint), typeof(uint) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(long), typeof(long) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(ushort), typeof(ushort) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(short), typeof(short) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(double), typeof(double) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(decimal), typeof(decimal) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(byte), typeof(byte) }), "MINVALUE" },
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(int), typeof(int) }), "MINVALUE" },
};

static readonly HashSet<MethodInfo> TruncateMethodInfos = new HashSet<MethodInfo>
Expand All @@ -117,6 +92,8 @@ public class FbMathTranslator : IMethodCallTranslator
typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(double), typeof(int) })
};

static readonly MethodInfo LogNewBaseMethod = typeof(Math).GetRuntimeMethod(nameof(Math.Log), new[] { typeof(double), typeof(double) });

readonly FbSqlExpressionFactory _fbSqlExpressionFactory;

public FbMathTranslator(FbSqlExpressionFactory fbSqlExpressionFactory)
Expand Down Expand Up @@ -154,6 +131,10 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO
nullability,
method.ReturnType));
}
if (LogNewBaseMethod == method)
{
return _fbSqlExpressionFactory.Function("LOG", arguments.Reverse(), true, arguments.Select(_ => true), method.ReturnType);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

//$Authors = Jiri Cincura ([email protected])

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
Expand All @@ -39,4 +42,28 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
}
return base.VisitUnary(unaryExpression);
}

public override SqlExpression GenerateGreatest(IReadOnlyList<SqlExpression> expressions, Type resultType)
{
var resultTypeMapping = ExpressionExtensions.InferTypeMapping(expressions);
return Dependencies.SqlExpressionFactory.Function(
"MAXVALUE",
expressions,
nullable: true,
Enumerable.Repeat(true, expressions.Count),
resultType,
resultTypeMapping);
}

public override SqlExpression GenerateLeast(IReadOnlyList<SqlExpression> expressions, Type resultType)
{
var resultTypeMapping = ExpressionExtensions.InferTypeMapping(expressions);
return Dependencies.SqlExpressionFactory.Function(
"MINVALUE",
expressions,
nullable: true,
Enumerable.Repeat(true, expressions.Count),
resultType,
resultTypeMapping);
}
}

0 comments on commit 8a4e842

Please sign in to comment.