< Summary

Line coverage
25%
Covered lines: 4
Uncovered lines: 12
Coverable lines: 16
Total lines: 76
Line coverage: 25%
Branch coverage
25%
Covered branches: 3
Total branches: 12
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
AssertIsHighSurrogateCodePoint(...)0%220%
AssertIsLowSurrogateCodePoint(...)0%220%
AssertIsValidCodePoint(...)0%220%
AssertIsValidScalar(...)50%2266.66%
AssertIsValidSupplementaryPlaneScalar(...)50%4466.66%
ToHexString(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeDebug.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5
 6namespace System.Text
 7{
 8    internal static class UnicodeDebug
 9    {
 10        [Conditional("DEBUG")]
 11        internal static void AssertIsBmpCodePoint(uint codePoint)
 12        {
 13            if (!UnicodeUtility.IsBmpCodePoint(codePoint))
 14            {
 15                Debug.Fail($"The value {ToHexString(codePoint)} is not a valid BMP code point.");
 16            }
 17        }
 18
 19        [Conditional("DEBUG")]
 20        internal static void AssertIsHighSurrogateCodePoint(uint codePoint)
 21        {
 022            if (!UnicodeUtility.IsHighSurrogateCodePoint(codePoint))
 23            {
 024                Debug.Fail($"The value {ToHexString(codePoint)} is not a valid UTF-16 high surrogate code point.");
 25            }
 026        }
 27
 28        [Conditional("DEBUG")]
 29        internal static void AssertIsLowSurrogateCodePoint(uint codePoint)
 30        {
 031            if (!UnicodeUtility.IsLowSurrogateCodePoint(codePoint))
 32            {
 033                Debug.Fail($"The value {ToHexString(codePoint)} is not a valid UTF-16 low surrogate code point.");
 34            }
 035        }
 36
 37        [Conditional("DEBUG")]
 38        internal static void AssertIsValidCodePoint(uint codePoint)
 39        {
 040            if (!UnicodeUtility.IsValidCodePoint(codePoint))
 41            {
 042                Debug.Fail($"The value {ToHexString(codePoint)} is not a valid Unicode code point.");
 43            }
 044        }
 45
 46        [Conditional("DEBUG")]
 47        internal static void AssertIsValidScalar(uint scalarValue)
 48        {
 1468628049            if (!UnicodeUtility.IsValidUnicodeScalar(scalarValue))
 50            {
 051                Debug.Fail($"The value {ToHexString(scalarValue)} is not a valid Unicode scalar value.");
 52            }
 1468628053        }
 54
 55        [Conditional("DEBUG")]
 56        internal static void AssertIsValidSupplementaryPlaneScalar(uint scalarValue)
 57        {
 4084558            if (!UnicodeUtility.IsValidUnicodeScalar(scalarValue) || UnicodeUtility.IsBmpCodePoint(scalarValue))
 59            {
 060                Debug.Fail($"The value {ToHexString(scalarValue)} is not a valid supplementary plane Unicode scalar valu
 61            }
 4084562        }
 63
 64        /// <summary>
 65        /// Formats a code point as the hex string "U+XXXX".
 66        /// </summary>
 67        /// <remarks>
 68        /// The input value doesn't have to be a real code point in the Unicode codespace. It can be any integer.
 69        /// </remarks>
 70        private static string ToHexString(uint codePoint)
 71        {
 072            return FormattableString.Invariant($"U+{codePoint:X4}");
 73        }
 74    }
 75}
 76