Path: redb/redb.Tests.Integration/Tests/Unit/RedbIndexComparerTests.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/RedbIndexComparerTests.cs ---- using redb.Core.Models; namespace redb.Tests.Integration.Tests.Unit; /// The comparison of expected indexes with the catalog (RedbIndexComparer), and the one-line form of a statement. public class RedbIndexComparerTests { private static RedbExpectedIndex Expected(string name, string[] key, string[]? include = null, bool unique = false) => new(name, "_values", unique, key, include ?? [], $"CREATE INDEX {name}"); private static RedbIndexShape Actual(string name, string[] key, string[]? include = null, bool unique = false, bool valid = true) => new() { Name = name, Table = "_values", KeyColumns = key, IncludedColumns = include ?? [], IsUnique = unique, IsValid = valid }; [Fact] public void Reports_Missing_Invalid_Differs_AndNothingForTheRest() { var expected = new[] { Expected("IX_a", ["_id_structure", "_array_index"]), Expected("IX_b", ["_id_object"]), Expected("IX_c", ["_id_structure", "_id_object"], ["_long", "_double"]), Expected("IX_d", ["_id_structure", "_id_object"]), Expected("IX_e", ["_id_object"], unique: true), }; var actual = new[] { Actual("ix_b", ["_ID_OBJECT"]), // same, by name and columns, any case Actual("IX_c", ["_id_structure", "_id_object"], ["_double", "_long"]), // INCLUDE is a set Actual("IX_d", ["_id_object", "_id_structure"]), // key order differs Actual("IX_e", ["_id_object"], valid: false), // INVALID Actual("IX_mine", ["_note"]), // an index of the operator: not reported }; var report = RedbIndexComparer.Compare(expected, actual); report.ExpectedCount.Should().Be(5); report.Findings.Select(f => (f.Name, f.State)).Should().BeEquivalentTo(new[] { ("IX_a", RedbIndexState.Missing), ("IX_d", RedbIndexState.Differs), ("IX_e", RedbIndexState.Invalid), }); report.Repairable.Select(f => f.Name).Should().BeEquivalentTo(["IX_a", "IX_e"]); } [Fact] public void Uniqueness_IsPartOfTheShape() { var report = RedbIndexComparer.Compare([Expected("IX_u", ["_id"], unique: true)], [Actual("IX_u", ["_id"])]); report.Findings.Single().State.Should().Be(RedbIndexState.Differs); } [Fact] public void Finding_SaysWhatTheIndexServes() { var report = RedbIndexComparer.Compare([Expected("IX__values__array_key", ["_id_structure", "_array_index"])], []); report.Findings.Single().ToString().Should().Contain("Missing").And.Contain("dictionary key"); RedbIndexPurpose.Of("IX__values__structure_long_object").Should().Contain("long"); } [Fact] public void OneLine_CollapsesWhitespace_OutsideQuotedText() { RedbExpectedIndex.OneLine("CREATE INDEX \"IX a\"\r\n ON _values (_id)\n WHERE _s = 'a b'") .Should().Be("CREATE INDEX \"IX a\" ON _values (_id) WHERE _s = 'a b'"); RedbExpectedIndex.OneLine("CREATE INDEX [IX b] ON [dbo].[_values] ([_id])") .Should().Be("CREATE INDEX [IX b] ON [dbo].[_values] ([_id])"); } [Fact] public void RepairResult_TheFourParameterConstructorOf480_StillBuilds_WithNoDuplicates() => new RedbIndexRepairResult([], [], [], null).Duplicates.Should().BeEmpty(); }