• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LBreedlove / Queuebal.Expressions / 15909841425

26 Jun 2025 06:38PM UTC coverage: 90.379% (+0.6%) from 89.828%
15909841425

Pull #12

github

web-flow
Merge cb4c14c95 into 3fa62aa5d
Pull Request #12: Add (Length)Greater/LessThan conditions

355 of 376 branches covered (94.41%)

Branch coverage included in aggregate %.

156 of 160 new or added lines in 8 files covered. (97.5%)

2125 of 2368 relevant lines covered (89.74%)

495.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/Queuebal.Expressions.Conditions/LengthIsLessThanCondition.cs
1
using Queuebal.Json;
2

3
namespace Queuebal.Expressions.Conditions;
4

5
/// <summary>
6
/// A condition that checks if the input value's length is less than the comparer value,
7
/// or the length of the comparer value.
8
/// </summary>
9
public class LengthIsLessThanCondition : BinaryCondition
10
{
11
    private static HashSet<JSONFieldType> _validInputTypes => new()
4✔
12
    {
4✔
13
        JSONFieldType.String,
4✔
14
        JSONFieldType.List,
4✔
15
        JSONFieldType.Dictionary,
4✔
16
    };
4✔
17

18
    /// <summary>
19
    /// Gets the name of the condition type.
20
    /// </summary>
21
    public static string ConditionType { get; } = "LengthIsLessThan";
9✔
22

23
    /// <summary>
24
    /// Evaluates the condition by checking if the input value's length is less than the specified value.
25
    /// </summary>
26
    /// <param name="context">The context the condition is running in.</param>
27
    /// <param name="inputValue">The value to compare against.</param>
28
    /// <returns>true if the input value's length is less than the specified value, otherwise false.</returns>
29
    protected override bool EvaluateCondition(ExpressionContext context, JSONValue inputValue, JSONValue comparerValue)
30
    {
5✔
31
        if (inputValue.IsNull)
5✔
32
        {
1✔
33
            return false;
1✔
34
        }
35

36
        if (!_validInputTypes.Contains(inputValue.FieldType))
4✔
37
        {
1✔
38
            throw new InvalidOperationException("IsLengthGreaterThan inputValue must be a string, list, or dictionary");
1✔
39
        }
40

41
        int length = GetLength(inputValue);
3✔
42
        if (comparerValue.IsInteger)
3✔
43
        {
1✔
44
            return length < comparerValue.IntValue;
1✔
45
        }
46

47
        return length < GetLength(comparerValue);
2✔
48
    }
4✔
49

50
    /// <summary>
51
    /// Gets the length of the given JSONValue, if the value is a string, list, or dictionary.
52
    /// </summary>
53
    /// <param name="value">The value to get the length of.</param>
54
    /// <returns>The length of the value.</returns>
55
    /// <exception cref="InvalidOperationException">Thrown when the value is not a string, list, or dictionary.</exception>
56
    private static int GetLength(JSONValue value) => value.FieldType switch
5✔
57
    {
5✔
58
        JSONFieldType.String => value.StringValue.Length,
1✔
59
        JSONFieldType.List => value.ListValue.Count,
2✔
60
        JSONFieldType.Dictionary => value.DictValue.Count,
2✔
NEW
61
        _ => throw new InvalidOperationException("IsLengthGreater than can only accept a string, list, or dictionary")
×
62
    };
5✔
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc