< Summary

Information
Class: IceRpc.Internal.IceIdentity
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/IceIdentity.cs
Tag: 1321_24790053727
Line coverage
96%
Covered lines: 28
Uncovered lines: 1
Coverable lines: 29
Total lines: 59
Line coverage: 96.5%
Branch coverage
92%
Covered branches: 13
Total branches: 14
Branch coverage: 92.8%
Method coverage
66%
Covered methods: 2
Fully covered methods: 2
Total methods: 3
Method coverage: 66.6%
Full method coverage: 66.6%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToString()100%210%
Parse(...)80%101085%
ToPath()100%44100%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace IceRpc.Internal;
 4
 5internal readonly partial record struct IceIdentity
 6{
 7    /// <summary>Converts this identity into a path string.</summary>
 8    /// <returns>The identity converted into a path string.</returns>
 09    public override readonly string ToString() => ToPath();
 10
 11    /// <summary>Parses a path into an identity, including the null/empty identity.</summary>
 12    /// <param name="path">The path (percent escaped).</param>
 13    /// <returns>The corresponding identity.</returns>
 14    internal static IceIdentity Parse(string path)
 147515    {
 147516        if (path.Length == 0 || path[0] != '/')
 217        {
 218            throw new ArgumentException("path must start with a /", nameof(path));
 19        }
 20
 147321        string workingPath = path[1..]; // removes leading /.
 22
 147323        int firstSlash = workingPath.IndexOf('/', StringComparison.Ordinal);
 24
 25        string name;
 147326        string category = "";
 27
 147328        if (firstSlash == -1)
 146129        {
 30            // Name only
 146131            name = Uri.UnescapeDataString(workingPath);
 146132        }
 33        else
 1234        {
 1235            if (firstSlash != workingPath.LastIndexOf('/'))
 136            {
 137                throw new FormatException($"Too many slashes in path '{path}'.");
 38            }
 39
 1140            name = Uri.UnescapeDataString(workingPath[(firstSlash + 1)..]);
 1141            category = Uri.UnescapeDataString(workingPath[0..firstSlash]);
 1142        }
 43
 147244        return name.Length == 0 ? new("", "") : new(name, category);
 147245    }
 46
 47    /// <summary>Converts this identity into a path.</summary>
 48    internal readonly string ToPath()
 146349    {
 146350        if (Name.Length == 0)
 133551        {
 133552            return "/";
 53        }
 54
 12855        return Category.Length > 0 ?
 12856            $"/{Uri.EscapeDataString(Category)}/{Uri.EscapeDataString(Name)}" :
 12857            $"/{Uri.EscapeDataString(Name)}";
 146358    }
 59}