Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Rename Contract.Assert to Debug.Assert (#8600)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas authored Dec 12, 2016
1 parent ec17ff6 commit b638af3
Show file tree
Hide file tree
Showing 260 changed files with 2,121 additions and 1,910 deletions.
5 changes: 3 additions & 2 deletions src/mscorlib/corefx/System/Globalization/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Globalization;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.Serialization;

Expand Down Expand Up @@ -212,7 +213,7 @@ internal virtual int CurrentEraValue
// The following code assumes that the current era value can not be -1.
if (_currentEraValue == -1)
{
Contract.Assert(BaseCalendarID != CalendarId.UNINITIALIZED_VALUE, "[Calendar.CurrentEraValue] Expected a real calendar ID");
Debug.Assert(BaseCalendarID != CalendarId.UNINITIALIZED_VALUE, "[Calendar.CurrentEraValue] Expected a real calendar ID");
_currentEraValue = CalendarData.GetCalendarData(BaseCalendarID).iCurrentEra;
}
return (_currentEraValue);
Expand Down Expand Up @@ -527,7 +528,7 @@ internal int GetFirstDayWeekOfYear(DateTime time, int firstDayOfWeek)
// this value can be less than 0. It's fine since we are making it positive again in calculating offset.
int dayForJan1 = (int)GetDayOfWeek(time) - (dayOfYear % 7);
int offset = (dayForJan1 - firstDayOfWeek + 14) % 7;
Contract.Assert(offset >= 0, "Calendar.GetFirstDayWeekOfYear(): offset >= 0");
Debug.Assert(offset >= 0, "Calendar.GetFirstDayWeekOfYear(): offset >= 0");
return ((dayOfYear + offset) / 7 + 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Security;
Expand Down Expand Up @@ -200,7 +201,7 @@ private static string NormalizeDatePattern(string input)
break;
default:
const string unsupportedDateFieldSymbols = "YuUrQqwWDFg";
Contract.Assert(unsupportedDateFieldSymbols.IndexOf(input[index]) == -1,
Debug.Assert(unsupportedDateFieldSymbols.IndexOf(input[index]) == -1,
string.Format(CultureInfo.InvariantCulture,
"Encountered an unexpected date field symbol '{0}' from ICU which has no known corresponding .NET equivalent.",
input[index]));
Expand Down
3 changes: 2 additions & 1 deletion src/mscorlib/corefx/System/Globalization/CalendarData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Collections.Generic;

Expand Down Expand Up @@ -108,7 +109,7 @@ internal CalendarData(String localeName, CalendarId calendarId, bool bUseUserOve

if (!LoadCalendarDataFromSystem(localeName, calendarId))
{
Contract.Assert(false, "[CalendarData] LoadCalendarDataFromSystem call isn't expected to fail for calendar " + calendarId + " locale " + localeName);
Debug.Assert(false, "[CalendarData] LoadCalendarDataFromSystem call isn't expected to fail for calendar " + calendarId + " locale " + localeName);

// Something failed, try invariant for missing parts
// This is really not good, but we don't want the callers to crash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace System.Globalization
Expand Down Expand Up @@ -153,7 +154,7 @@ private static double CenturiesFrom1900(int gregorianYear)
// the following formulas defines a polynomial function which gives us the amount that the earth is slowing down for specific year ranges
private static double DefaultEphemerisCorrection(int gregorianYear)
{
Contract.Assert(gregorianYear < 1620 || 2020 <= gregorianYear);
Debug.Assert(gregorianYear < 1620 || 2020 <= gregorianYear);
long january1stOfYear = GetNumberOfDays(new DateTime(gregorianYear, 1, 1));
double daysSinceStartOf1810 = january1stOfYear - StartOf1810;
double x = TwelveHours + daysSinceStartOf1810;
Expand All @@ -162,34 +163,34 @@ private static double DefaultEphemerisCorrection(int gregorianYear)

private static double EphemerisCorrection1988to2019(int gregorianYear)
{
Contract.Assert(1988 <= gregorianYear && gregorianYear <= 2019);
Debug.Assert(1988 <= gregorianYear && gregorianYear <= 2019);
return (double)(gregorianYear - 1933) / SecondsPerDay;
}

private static double EphemerisCorrection1900to1987(int gregorianYear)
{
Contract.Assert(1900 <= gregorianYear && gregorianYear <= 1987);
Debug.Assert(1900 <= gregorianYear && gregorianYear <= 1987);
double centuriesFrom1900 = CenturiesFrom1900(gregorianYear);
return PolynomialSum(s_coefficients1900to1987, centuriesFrom1900);
}

private static double EphemerisCorrection1800to1899(int gregorianYear)
{
Contract.Assert(1800 <= gregorianYear && gregorianYear <= 1899);
Debug.Assert(1800 <= gregorianYear && gregorianYear <= 1899);
double centuriesFrom1900 = CenturiesFrom1900(gregorianYear);
return PolynomialSum(s_coefficients1800to1899, centuriesFrom1900);
}

private static double EphemerisCorrection1700to1799(int gregorianYear)
{
Contract.Assert(1700 <= gregorianYear && gregorianYear <= 1799);
Debug.Assert(1700 <= gregorianYear && gregorianYear <= 1799);
double yearsSince1700 = gregorianYear - 1700;
return PolynomialSum(s_coefficients1700to1799, yearsSince1700) / SecondsPerDay;
}

private static double EphemerisCorrection1620to1699(int gregorianYear)
{
Contract.Assert(1620 <= gregorianYear && gregorianYear <= 1699);
Debug.Assert(1620 <= gregorianYear && gregorianYear <= 1699);
double yearsSince1600 = gregorianYear - 1600;
return PolynomialSum(s_coefficients1620to1699, yearsSince1600) / SecondsPerDay;
}
Expand All @@ -216,7 +217,7 @@ private static double EphemerisCorrection(double time)
}
}

Contract.Assert(false, "Not expected to come here");
Debug.Assert(false, "Not expected to come here");
return DefaultEphemerisCorrection(year);
}

Expand Down Expand Up @@ -405,7 +406,7 @@ internal static long PersianNewYearOnOrBefore(long numberOfDays)
break;
}
}
Contract.Assert(day != upperBoundNewYearDay);
Debug.Assert(day != upperBoundNewYearDay);

return day - 1;
}
Expand Down
35 changes: 18 additions & 17 deletions src/mscorlib/corefx/System/Globalization/CharUnicodeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Security;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace System.Globalization
Expand Down Expand Up @@ -59,8 +60,8 @@ public static partial class CharUnicodeInfo

internal static int InternalConvertToUtf32(String s, int index)
{
Contract.Assert(s != null, "s != null");
Contract.Assert(index >= 0 && index < s.Length, "index < s.Length");
Debug.Assert(s != null, "s != null");
Debug.Assert(index >= 0 && index < s.Length, "index < s.Length");
if (index < s.Length - 1)
{
int temp1 = (int)s[index] - HIGH_SURROGATE_START;
Expand Down Expand Up @@ -100,9 +101,9 @@ internal static int InternalConvertToUtf32(String s, int index)

internal static int InternalConvertToUtf32(String s, int index, out int charLength)
{
Contract.Assert(s != null, "s != null");
Contract.Assert(s.Length > 0, "s.Length > 0");
Contract.Assert(index >= 0 && index < s.Length, "index >= 0 && index < s.Length");
Debug.Assert(s != null, "s != null");
Debug.Assert(s.Length > 0, "s.Length > 0");
Debug.Assert(index >= 0 && index < s.Length, "index >= 0 && index < s.Length");
charLength = 1;
if (index < s.Length - 1)
{
Expand Down Expand Up @@ -131,8 +132,8 @@ internal static int InternalConvertToUtf32(String s, int index, out int charLeng

internal static bool IsWhiteSpace(String s, int index)
{
Contract.Assert(s != null, "s!=null");
Contract.Assert(index >= 0 && index < s.Length, "index >= 0 && index < s.Length");
Debug.Assert(s != null, "s!=null");
Debug.Assert(index >= 0 && index < s.Length, "index >= 0 && index < s.Length");

UnicodeCategory uc = GetUnicodeCategory(s, index);
// In Unicode 3.0, U+2028 is the only character which is under the category "LineSeparator".
Expand Down Expand Up @@ -172,7 +173,7 @@ internal static bool IsWhiteSpace(char c)
//
internal unsafe static double InternalGetNumericValue(int ch)
{
Contract.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
Debug.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
// Get the level 2 item from the highest 12 bit (8 - 19) of ch.
ushort index = s_pNumericLevel1Index[ch >> 8];
// Get the level 2 WORD offset from the 4 - 7 bit of ch. This provides the base offset of the level 3 table.
Expand All @@ -193,7 +194,7 @@ internal unsafe static double InternalGetNumericValue(int ch)

internal unsafe static ushort InternalGetDigitValues(int ch)
{
Contract.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
Debug.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
// Get the level 2 item from the highest 12 bit (8 - 19) of ch.
ushort index = s_pNumericLevel1Index[ch >> 8];
// Get the level 2 WORD offset from the 4 - 7 bit of ch. This provides the base offset of the level 3 table.
Expand Down Expand Up @@ -324,7 +325,7 @@ internal unsafe static UnicodeCategory InternalGetUnicodeCategory(int ch)

internal unsafe static byte InternalGetCategoryValue(int ch, int offset)
{
Contract.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
Debug.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
// Get the level 2 item from the highest 12 bit (8 - 19) of ch.
ushort index = s_pCategoryLevel1Index[ch >> 8];
// Get the level 2 WORD offset from the 4 - 7 bit of ch. This provides the base offset of the level 3 table.
Expand All @@ -341,7 +342,7 @@ internal unsafe static byte InternalGetCategoryValue(int ch, int offset)
// Make sure that OtherNotAssigned is the last category in UnicodeCategory.
// If that changes, change the following assertion as well.
//
//Contract.Assert(uc >= 0 && uc <= UnicodeCategory.OtherNotAssigned, "Table returns incorrect Unicode category");
//Debug.Assert(uc >= 0 && uc <= UnicodeCategory.OtherNotAssigned, "Table returns incorrect Unicode category");
return (uc);
}
}
Expand All @@ -361,8 +362,8 @@ internal unsafe static byte InternalGetCategoryValue(int ch, int offset)

internal static UnicodeCategory InternalGetUnicodeCategory(String value, int index)
{
Contract.Assert(value != null, "value can not be null");
Contract.Assert(index < value.Length, "index < value.Length");
Debug.Assert(value != null, "value can not be null");
Debug.Assert(index < value.Length, "index < value.Length");

return (InternalGetUnicodeCategory(InternalConvertToUtf32(value, index)));
}
Expand All @@ -376,16 +377,16 @@ internal static UnicodeCategory InternalGetUnicodeCategory(String value, int ind

internal static UnicodeCategory InternalGetUnicodeCategory(String str, int index, out int charLength)
{
Contract.Assert(str != null, "str can not be null");
Contract.Assert(str.Length > 0, "str.Length > 0"); ;
Contract.Assert(index >= 0 && index < str.Length, "index >= 0 && index < str.Length");
Debug.Assert(str != null, "str can not be null");
Debug.Assert(str.Length > 0, "str.Length > 0"); ;
Debug.Assert(index >= 0 && index < str.Length, "index >= 0 && index < str.Length");

return (InternalGetUnicodeCategory(InternalConvertToUtf32(str, index, out charLength)));
}

internal static bool IsCombiningCategory(UnicodeCategory uc)
{
Contract.Assert(uc >= 0, "uc >= 0");
Debug.Assert(uc >= 0, "uc >= 0");
return (
uc == UnicodeCategory.NonSpacingMark ||
uc == UnicodeCategory.SpacingCombiningMark ||
Expand Down
49 changes: 25 additions & 24 deletions src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -41,8 +42,8 @@ private void InitSort(CultureInfo culture)

internal static unsafe int IndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
{
Contract.Assert(source != null);
Contract.Assert(value != null);
Debug.Assert(source != null);
Debug.Assert(value != null);

if (value.Length == 0)
{
Expand Down Expand Up @@ -85,8 +86,8 @@ internal static unsafe int IndexOfOrdinal(string source, string value, int start

internal static unsafe int LastIndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
{
Contract.Assert(source != null);
Contract.Assert(value != null);
Debug.Assert(source != null);
Debug.Assert(value != null);

if (value.Length == 0)
{
Expand Down Expand Up @@ -132,8 +133,8 @@ internal static unsafe int LastIndexOfOrdinal(string source, string value, int s

private int GetHashCodeOfStringCore(string source, CompareOptions options)
{
Contract.Assert(source != null);
Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
Debug.Assert(source != null);
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);

return GetHashCodeOfStringCore(source, options, forceRandomizedHashing: false, additionalEntropy: 0);
}
Expand All @@ -145,9 +146,9 @@ private static unsafe int CompareStringOrdinalIgnoreCase(char* string1, int coun

private unsafe int CompareString(string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options)
{
Contract.Assert(string1 != null);
Contract.Assert(string2 != null);
Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
Debug.Assert(string1 != null);
Debug.Assert(string2 != null);
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);

fixed (char* pString1 = string1)
{
Expand All @@ -160,9 +161,9 @@ private unsafe int CompareString(string string1, int offset1, int length1, strin

private unsafe int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
{
Contract.Assert(!string.IsNullOrEmpty(source));
Contract.Assert(target != null);
Contract.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
Debug.Assert(!string.IsNullOrEmpty(source));
Debug.Assert(target != null);
Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);

if (target.Length == 0)
{
Expand All @@ -189,9 +190,9 @@ private unsafe int IndexOfCore(string source, string target, int startIndex, int

private unsafe int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
{
Contract.Assert(!string.IsNullOrEmpty(source));
Contract.Assert(target != null);
Contract.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
Debug.Assert(!string.IsNullOrEmpty(source));
Debug.Assert(target != null);
Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);

if (target.Length == 0)
{
Expand Down Expand Up @@ -222,9 +223,9 @@ private unsafe int LastIndexOfCore(string source, string target, int startIndex,

private bool StartsWith(string source, string prefix, CompareOptions options)
{
Contract.Assert(!string.IsNullOrEmpty(source));
Contract.Assert(!string.IsNullOrEmpty(prefix));
Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
Debug.Assert(!string.IsNullOrEmpty(source));
Debug.Assert(!string.IsNullOrEmpty(prefix));
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);

if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options) && source.IsFastSort() && prefix.IsFastSort())
{
Expand All @@ -236,9 +237,9 @@ private bool StartsWith(string source, string prefix, CompareOptions options)

private bool EndsWith(string source, string suffix, CompareOptions options)
{
Contract.Assert(!string.IsNullOrEmpty(source));
Contract.Assert(!string.IsNullOrEmpty(suffix));
Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
Debug.Assert(!string.IsNullOrEmpty(source));
Debug.Assert(!string.IsNullOrEmpty(suffix));
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);

if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options) && source.IsFastSort() && suffix.IsFastSort())
{
Expand Down Expand Up @@ -320,8 +321,8 @@ private unsafe static bool IsSortable(char *text, int length)

internal unsafe int GetHashCodeOfStringCore(string source, CompareOptions options, bool forceRandomizedHashing, long additionalEntropy)
{
Contract.Assert(source != null);
Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
Debug.Assert(source != null);
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);

if (source.Length == 0)
{
Expand Down Expand Up @@ -378,7 +379,7 @@ private static byte[] GetNullTerminatedUtf8String(string s)

int bytesWritten = System.Text.Encoding.UTF8.GetBytes(s, 0, s.Length, buffer, 0);

Contract.Assert(bytesWritten == byteLen);
Debug.Assert(bytesWritten == byteLen);

return buffer;
}
Expand Down
Loading

0 comments on commit b638af3

Please sign in to comment.