From 3841ea0a8d258facb4bf48635c185ea652421f04 Mon Sep 17 00:00:00 2001 From: Adam Simon Date: Wed, 25 Oct 2023 19:59:42 +0200 Subject: [PATCH] Fix typos & minor improvements --- .../Evaluation/EvaluateLogHelper.cs | 21 ++++-------- .../Evaluation/RolloutEvaluator.cs | 32 +++++++++---------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs b/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs index 30a90c8c..584cad75 100644 --- a/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs +++ b/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs @@ -203,11 +203,10 @@ private static IndentedTextBuilder AppendPercentageOptions(this IndentedTextBuil private static IndentedTextBuilder AppendTargetingRuleThenPart(this IndentedTextBuilder builder, TargetingRule targetingRule, bool newLine, bool appendPercentageOptions = false, string? percentageOptionsAttribute = null) { - var percentageOptions = targetingRule.PercentageOptions; - (newLine ? builder.NewLine() : builder.Append(" ")) .Append("THEN"); + var percentageOptions = targetingRule.PercentageOptions; if (percentageOptions is not { Length: > 0 }) { return builder.Append($" '{targetingRule.SimpleValue?.Value ?? default}'"); @@ -304,22 +303,16 @@ public static string ToDisplayText(this UserComparator comparator) { return comparator switch { - UserComparator.IsOneOf or UserComparator.SensitiveIsOneOf => "IS ONE OF", - UserComparator.IsNotOneOf or UserComparator.SensitiveIsNotOneOf => "IS NOT ONE OF", + UserComparator.IsOneOf or UserComparator.SensitiveIsOneOf or UserComparator.SemVerIsOneOf => "IS ONE OF", + UserComparator.IsNotOneOf or UserComparator.SensitiveIsNotOneOf or UserComparator.SemVerIsNotOneOf => "IS NOT ONE OF", UserComparator.ContainsAnyOf => "CONTAINS ANY OF", UserComparator.NotContainsAnyOf => "NOT CONTAINS ANY OF", - UserComparator.SemVerIsOneOf => "IS ONE OF", - UserComparator.SemVerIsNotOneOf => "IS NOT ONE OF", - UserComparator.SemVerLess => "<", - UserComparator.SemVerLessOrEquals => "<=", - UserComparator.SemVerGreater => ">", - UserComparator.SemVerGreaterOrEquals => ">=", + UserComparator.SemVerLess or UserComparator.NumberLess => "<", + UserComparator.SemVerLessOrEquals or UserComparator.NumberLessOrEquals => "<=", + UserComparator.SemVerGreater or UserComparator.NumberGreater => ">", + UserComparator.SemVerGreaterOrEquals or UserComparator.NumberGreaterOrEquals => ">=", UserComparator.NumberEquals => "=", UserComparator.NumberNotEquals => "!=", - UserComparator.NumberLess => "<", - UserComparator.NumberLessOrEquals => "<=", - UserComparator.NumberGreater => ">", - UserComparator.NumberGreaterOrEquals => ">=", UserComparator.DateTimeBefore => "BEFORE", UserComparator.DateTimeAfter => "AFTER", UserComparator.TextEquals or UserComparator.SensitiveTextEquals => "EQUALS", diff --git a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs index 7dcb62de..60e0d233 100644 --- a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs +++ b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs @@ -62,7 +62,7 @@ public EvaluateResult Evaluate(T defaultValue, ref EvaluateContext context, [ if (context.Setting.SettingType != Setting.UnknownType && context.Setting.SettingType != expectedSettingType) { throw new InvalidOperationException( - "The type of a setting must match the type of the specified default value " + "The type of a setting must match the type of the specified default value. " + $"Setting's type was {context.Setting.SettingType} but the default value's type was {typeof(T)}. " + $"Please use a default value which corresponds to the setting type {context.Setting.SettingType}."); } @@ -159,13 +159,10 @@ private bool TryEvaluateTargetingRules(TargetingRule[] targetingRules, ref Evalu logBuilder?.DecreaseIndent(); return true; } - else - { - logBuilder? - .NewLine(TargetingRuleIgnoredMessage) - .DecreaseIndent(); - continue; - } + + logBuilder? + .NewLine(TargetingRuleIgnoredMessage) + .DecreaseIndent(); } result = default; @@ -237,14 +234,14 @@ private bool TryEvaluatePercentageOptions(PercentageOption[] percentageOptions, continue; } - var percentageOptionValue = percentageOption.Value.GetValue(context.Setting.SettingType, throwIfInvalid: false); + var percentageOptionValue = percentageOption.Value.GetValue(throwIfInvalid: false); logBuilder?.NewLine().Append($"- Hash value {hashValue} selects % option {i + 1} ({percentageOption.Percentage}%), '{percentageOptionValue ?? EvaluateLogHelper.InvalidValuePlaceholder}'."); result = new EvaluateResult(percentageOption, matchedTargetingRule: targetingRule, matchedPercentageOption: percentageOption); return true; } - throw new InvalidOperationException("Sum of percentage option percentages are less than 100)."); + throw new InvalidOperationException("Sum of percentage option percentages are less than 100."); } private bool EvaluateConditions(TCondition[] conditions, TargetingRule? targetingRule, string contextSalt, ref EvaluateContext context, out string? error) @@ -301,12 +298,15 @@ private bool EvaluateConditions(TCondition[] conditions, TargetingRu throw new InvalidOperationException(); // execution should never get here } - if (targetingRule is null || conditions.Length > 1) + if (logBuilder is not null) { - logBuilder?.AppendConditionConsequence(conditionResult); - } + if (targetingRule is null || conditions.Length > 1) + { + logBuilder.AppendConditionConsequence(conditionResult); + } - logBuilder?.DecreaseIndent(); + logBuilder.DecreaseIndent(); + } if (!conditionResult) { @@ -429,7 +429,7 @@ private bool EvaluateUserCondition(UserCondition condition, string contextSalt, error = HandleInvalidUserAttribute(condition, context.Key, userAttributeName, $"'{userAttributeValue}' is not a valid decimal number"); return false; } - return EvaluateNumberRelation(number, condition.Comparator, condition.DoubleValue); + return EvaluateNumberRelation(number, comparator, condition.DoubleValue); case UserComparator.DateTimeBefore: case UserComparator.DateTimeAfter: @@ -620,7 +620,7 @@ private static bool EvaluateSemVerIsOneOf(SemVersion version, string[]? comparis if (!result && version.PrecedenceMatches(version2)) { // NOTE: Previous versions of the evaluation algorithm require that - // all the comparison values are empty or valid, that is, we can't stop when finding a match. + // none of the comparison values are empty or invalid, that is, we can't stop when finding a match. // We keep this behavior for backward compatibility. result = true; }