< Summary

Information
Class: NGql.Core.Variable
Assembly: NGql.Core
File(s): /home/runner/work/NGql/NGql/src/Core/Variable.cs
Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 83
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Name()100%11100%
get_Type()100%11100%
.ctor(...)100%66100%
ToString()100%11100%
CompareTo(...)100%44100%
CompareTo(...)100%22100%
Print(...)100%44100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
op_LessThan(...)100%11100%
op_GreaterThan(...)100%11100%
op_LessThanOrEqual(...)100%11100%
op_GreaterThanOrEqual(...)100%11100%
Equals(...)100%11100%
Equals(...)100%11100%
GetHashCode()100%11100%

File(s)

/home/runner/work/NGql/NGql/src/Core/Variable.cs

#LineLine coverage
 1using System.Text;
 2
 3namespace NGql.Core;
 4
 5/// <summary>
 6///     Represents a variable in GraphQL query.
 7/// </summary>
 8public readonly struct Variable : IComparable, IComparable<Variable>, IEquatable<Variable>
 9{
 10    /// <summary>
 11    /// Name of the variable.
 12    /// </summary>
 181513    public string Name { get; }
 14
 15    /// <summary>
 16    /// Type of the variable.
 17    /// </summary>
 72018    public string Type { get; }
 19
 20    public Variable(string name, string type)
 21    {
 42922        if (string.IsNullOrWhiteSpace(name))
 23        {
 1524            throw new ArgumentException("Variable name cannot be null or whitespace.", nameof(name));
 25        }
 26
 41427        if (!name.StartsWith('$'))
 28        {
 629            throw new ArgumentException("Variable name must start with '$'.", nameof(name));
 30        }
 31
 40832        if (string.IsNullOrWhiteSpace(type))
 33        {
 1534            throw new ArgumentException("Variable type cannot be null or whitespace.", nameof(type));
 35        }
 36
 39337        Name = name;
 39338        Type = type;
 39339    }
 40
 941    public override string ToString() => $"{Name}:{Type}";
 42
 43    public int CompareTo(object? obj)
 44    {
 11445        return obj switch
 11446        {
 347            null => 1,
 10548            Variable variable => CompareTo(variable),
 649            _ => throw new ArgumentException($"Object must be of type {nameof(Variable)}")
 11450        };
 51    }
 52
 53    public int CompareTo(Variable other)
 54    {
 48655        var nameComparison = string.Compare(Name, other.Name, StringComparison.OrdinalIgnoreCase);
 48656        return nameComparison != 0 ? nameComparison : string.Compare(Type, other.Type, StringComparison.OrdinalIgnoreCas
 57    }
 58
 59    internal void Print(StringBuilder builder, string key, bool isRootElement)
 60    {
 19861        builder.Append(isRootElement ? Name : key);
 19862        builder.Append(':');
 19863        builder.Append(isRootElement ? Type : Name);
 19864    }
 65
 2166    public static bool operator ==(Variable left, Variable right) => left.Equals(right);
 2767    public static bool operator !=(Variable left, Variable right) => !left.Equals(right);
 68
 1569    public static bool operator <(Variable left, Variable right) => left.CompareTo(right) < 0;
 1270    public static bool operator >(Variable left, Variable right) => left.CompareTo(right) > 0;
 71
 1272    public static bool operator <=(Variable left, Variable right) => left.CompareTo(right) <= 0;
 1273    public static bool operator >=(Variable left, Variable right) => left.CompareTo(right) >= 0;
 74
 10575    public override bool Equals(object? obj) => CompareTo(obj) == 0;
 76
 6977    public bool Equals(Variable other) => CompareTo(other) == 0;
 78
 79    // Constructor rejects null/whitespace name/type, so neither field is null here.
 1280    public override int GetHashCode() => HashCode.Combine(
 1281        Name.ToUpperInvariant(),
 1282        Type.ToUpperInvariant());
 83}