Skip to content

Commit

Permalink
Edge case fix for duplicate dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sakari-malkki committed Sep 11, 2024
1 parent 789e28d commit aee96d6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ public void ValidateFindStubOrHeadingCalledWithWithMissingHeadingReturnsWithErro
Assert.AreEqual(ValidationFeedbackRule.MissingStubAndHeading, result.First().Key.Rule);
}

[TestMethod]
public void ValidateFindStubOrHeadingCalledWithDuplicateDimensionsReturnsWithWarning()
{
// Arrange
ValidationStructuredEntry[] entries = ContentValidationFixtures.STRUCTURED_ENTRY_ARRAY_WITH_DUPLICATE_DIMENSION;
ContentValidator validator = new(filename, encoding, entries);
SetValidatorField(validator, "_defaultLanguage", defaultLanguage);
SetValidatorField(validator, "_availableLanguages", availableLanguages);

// Act
ValidationFeedback? result = ContentValidator.ValidateFindStubAndHeading(
entries,
validator
);

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count);
Assert.AreEqual(ValidationFeedbackRule.DuplicateDimension, result.First().Key.Rule);
}

[TestMethod]
public void ValidateFindRecommendedKeysCalledWithMissingDescriptionsReturnsWithWarnings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ internal static class ContentValidationFixtures
5,
Utils.Validation.ValueType.ListOfStrings);

private static readonly ValidationStructuredEntry headingEntryWithBar =
new(filename,
new ValidationStructuredEntryKey("HEADING"),
"\"bar-time\",\"bar\"",
10,
[],
5,
Utils.Validation.ValueType.ListOfStrings);

private static readonly ValidationStructuredEntry headingEnEntry =
new(filename,
new ValidationStructuredEntryKey("HEADING", "en"),
Expand Down Expand Up @@ -485,6 +494,14 @@ internal static class ContentValidationFixtures
stubEntry,
];

internal static ValidationStructuredEntry[] STRUCTURED_ENTRY_ARRAY_WITH_DUPLICATE_DIMENSION =>
[
stubEntry,
stubEnEntry,
headingEntryWithBar,
headingEnEntry
];

internal static ValidationStructuredEntry[] STRUCTURED_ENTRY_ARRAY_WITH_MULTIPLE_DIMENSION_NAMES =>
[
multipleStubNamesEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,25 @@ public sealed partial class ContentValidator
$"{language}")
);

feedbackItems.Add(feedback);
}
// Check if any of the heading names are also in the stub names
else if (validator._stubDimensionNames is not null &&
validator._headingDimensionNames is not null &&
validator._stubDimensionNames.TryGetValue(language, out string[]? stubValue) &&
validator._headingDimensionNames.TryGetValue(language, out string[]? headingValue) &&
stubValue.Intersect(headingValue).Any())
{
string[] duplicates = stubValue.Intersect(headingValue).ToArray();
KeyValuePair<ValidationFeedbackKey, ValidationFeedbackValue> feedback = new(
new(ValidationFeedbackLevel.Warning,
ValidationFeedbackRule.DuplicateDimension),
new(validator._filename,
0,
0,
$"{language}, {string.Join(", ", duplicates)}")
);

feedbackItems.Add(feedback);
}
}
Expand Down
3 changes: 2 additions & 1 deletion Px.Utils/Validation/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public enum ValidationFeedbackRule
AliasFileMissing = 54,
DuplicateFileNames = 55,
StartOfDataSectionNotFound = 56,
DuplicateEntry = 57
DuplicateEntry = 57,
DuplicateDimension = 58
}
}

0 comments on commit aee96d6

Please sign in to comment.