-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL parentheses work #27177
SQL parentheses work #27177
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.EntityFrameworkCore.TestModels.Northwind; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
public abstract class NorthwindOperatorsQueryTestBase<TFixture> : QueryTestBase<TFixture> | ||
where TFixture : NorthwindQueryFixtureBase<NoopModelCustomizer>, new() | ||
{ | ||
protected NorthwindOperatorsQueryTestBase(TFixture fixture) | ||
: base(fixture) | ||
{ | ||
} | ||
|
||
protected static ExpressionType[] BinaryArithmeticOperators { get; } = | ||
{ | ||
ExpressionType.Add, | ||
ExpressionType.Subtract, | ||
ExpressionType.Multiply, | ||
ExpressionType.Divide, | ||
// TODO Complete... | ||
}; | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(Get_binary_arithmetic_data))] | ||
public virtual async Task Binary_arithmetic_operators(ExpressionType outer, ExpressionType inner) | ||
{ | ||
var parameter = Expression.Parameter(typeof(Order), "o"); | ||
var predicate = | ||
Expression.Lambda<Func<Order, int>>( | ||
Expression.MakeBinary( | ||
outer, | ||
Expression.MakeBinary( | ||
inner, | ||
Expression.Property(parameter, nameof(Order.OrderID)), | ||
Expression.Constant(8)), | ||
Expression.Constant(9)), | ||
parameter); | ||
|
||
await AssertQueryScalar( | ||
async: true, | ||
ss => ss.Set<Order>().Where(o => o.OrderID == 10248).Select(predicate)); | ||
} | ||
|
||
public static IEnumerable<object[]> Get_binary_arithmetic_data() | ||
=> from op1 in BinaryArithmeticOperators from op2 in BinaryArithmeticOperators select new object[] { op1, op2 }; | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public virtual Task Double_negate_on_column(bool async) | ||
=> AssertQuery( | ||
async, | ||
ss => ss.Set<Order>().Where(o => -(-o.OrderID) == o.OrderID), | ||
entryCount: 830); | ||
|
||
// TODO: Test associativity (no parentheses on consecutive e.g. add operations) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few specific cases I'd like to add, but it's probably better to do it after the rest of this test suite is done (for the data etc.) |
||
// TODO: Test non-associativity of arithmetic operators on floating points aren't associative (because of rounding errors) | ||
|
||
// TODO: Move operator/precedence related here, e.g. NullSemanticsQueryTestBase.Bool_not_equal_nullable_int_HasValue, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to concentrate all operator precedence tests in this new test suite (they're kind of spread around at the moment). I've identified a couple here, I can do this after you're done with the rest (or if you feel like it...) |
||
// GearsOfWarTestBase.Negate_on_binary_expression... | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maumar here's a theory which takes care of all arithmetic operator combinations (the easy case...). The general idea would be to extend coverage for other operator types as possible.