Skip to content

Commit

Permalink
Fix typos & minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Oct 27, 2023
1 parent 834bc4d commit 3841ea0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
21 changes: 7 additions & 14 deletions src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}'");
Expand Down Expand Up @@ -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",
Expand Down
32 changes: 16 additions & 16 deletions src/ConfigCatClient/Evaluation/RolloutEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public EvaluateResult Evaluate<T>(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}.");
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>(TCondition[] conditions, TargetingRule? targetingRule, string contextSalt, ref EvaluateContext context, out string? error)
Expand Down Expand Up @@ -301,12 +298,15 @@ private bool EvaluateConditions<TCondition>(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)
{
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3841ea0

Please sign in to comment.