< Summary

Information
Class: IceRpc.Internal.Identity
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/Identity.cs
Tag: 275_13775359185
Line coverage
96%
Covered lines: 29
Uncovered lines: 1
Coverable lines: 30
Total lines: 60
Line coverage: 96.6%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage
75%
Covered methods: 3
Total methods: 4
Method coverage: 75%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Empty()100%11100%
ToString()100%210%
Parse(...)100%1010100%
ToPath()100%44100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/Identity.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace IceRpc.Internal;
 4
 5internal readonly partial record struct Identity
 6{
 7    /// <summary>Gets the null identity.</summary>
 26808    internal static Identity Empty { get; } = new("", "");
 9
 010    public override string ToString() => ToPath();
 11
 12    /// <summary>Parses a path into an identity, including the null/empty identity.</summary>
 13    /// <param name="path">The path (percent escaped).</param>
 14    /// <returns>The corresponding identity.</returns>
 15    internal static Identity Parse(string path)
 279216    {
 279217        if (path.Length == 0 || path[0] != '/')
 218        {
 219            throw new ArgumentException("path must start with a /", nameof(path));
 20        }
 21
 279022        string workingPath = path[1..]; // removes leading /.
 23
 279024        int firstSlash = workingPath.IndexOf('/', StringComparison.Ordinal);
 25
 26        string name;
 279027        string category = "";
 28
 279029        if (firstSlash == -1)
 277830        {
 31            // Name only
 277832            name = Uri.UnescapeDataString(workingPath);
 277833        }
 34        else
 1235        {
 1236            if (firstSlash != workingPath.LastIndexOf('/'))
 137            {
 138                throw new FormatException($"Too many slashes in path '{path}'.");
 39            }
 40
 1141            name = Uri.UnescapeDataString(workingPath[(firstSlash + 1)..]);
 1142            category = Uri.UnescapeDataString(workingPath[0..firstSlash]);
 1143        }
 44
 278945        return name.Length == 0 ? Empty : new(name, category);
 278946    }
 47
 48    /// <summary>Converts this identity into a path.</summary>
 49    internal string ToPath()
 278550    {
 278551        if (Name.Length == 0)
 266352        {
 266353            return "/";
 54        }
 55
 12256        return Category.Length > 0 ?
 12257            $"/{Uri.EscapeDataString(Category)}/{Uri.EscapeDataString(Name)}" :
 12258            $"/{Uri.EscapeDataString(Name)}";
 278559    }
 60}