Path: redb/redb.Tests.Integration/Tests/Unit/NarrowElementLeafTests.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Unit/NarrowElementLeafTests.cs
----
using redb.Core.Pro.Query;
using redb.Core.Query.Models;
using redb.Core.Query.QueryExpressions;
namespace redb.Tests.Integration.Tests.Unit;
///
/// The leaf of a Contains over an array of simple values, read through the capped probe on PostgreSQL: an equality on the
/// element rows of that array. Only a top-level conjunct, only an array of simple values; the scalar driving leaf and the
/// narrow-conjunct check are not changed by it.
///
public class NarrowElementLeafTests
{
private const long Array = 503;
private const long Scalar = 502;
private static readonly Dictionary Fields = new()
{
["Skills"] = new FieldInfo(Array, "String", "_string", "Skills", IsArray: true),
["Age"] = new FieldInfo(Scalar, "Long", "_long", "Age"),
};
private static ComparisonExpression Has(string value)
=> new(new PropertyInfo("Skills", typeof(string[])), ComparisonOperator.ArrayContains, value);
[Fact]
public void Contains_IsAnEqualityOnTheElementRows()
{
var leaf = PvtPrefilterPlanner.NarrowElementLeaf(Has("C#"), Fields)!;
leaf.StructureId.Should().Be(Array);
leaf.Predicates.Should().ContainSingle().Which.Op.Should().Be(ComparisonOperator.Equal);
}
[Fact]
public void Contains_InTheTopLevelAnd_IsFound_ButNotUnderAnOr()
{
var age = new ComparisonExpression(new PropertyInfo("Age", typeof(long)), ComparisonOperator.GreaterThan, 30L);
PvtPrefilterPlanner.NarrowElementLeaf(new LogicalExpression(LogicalOperator.And, [age, Has("C#")]), Fields)
.Should().NotBeNull();
PvtPrefilterPlanner.NarrowElementLeaf(new LogicalExpression(LogicalOperator.Or, [age, Has("C#")]), Fields)
.Should().BeNull("an OR is no superset a leaf can read");
}
[Fact]
public void Contains_DoesNotBecomeADrivingLeafOrANarrowConjunct()
{
PvtPrefilterPlanner.DrivingLeaf(Has("C#"), Fields).Should().BeNull("it is only read through the probe");
PvtPrefilterPlanner.HasNarrowConjunct(Has("C#"), Fields).Should().BeFalse("the forms of the other providers stay");
}
}