diff --git a/src/SixLabors.Core/Helpers/DebugGuard.cs b/src/SixLabors.Core/Helpers/DebugGuard.cs index f41d7eacf..f1fc1c64c 100644 --- a/src/SixLabors.Core/Helpers/DebugGuard.cs +++ b/src/SixLabors.Core/Helpers/DebugGuard.cs @@ -24,7 +24,7 @@ namespace SixLabors public static void NotNull(T target, string parameterName) where T : class { - if (target == null) + if (target is null) { throw new ArgumentNullException(parameterName); } @@ -116,50 +116,6 @@ namespace SixLabors } } - /// - /// Verifies, that the method parameter with specified target value is true - /// and throws an exception if it is found to be so. - /// - /// - /// The target value, which cannot be false. - /// - /// - /// The name of the parameter that is to be checked. - /// - /// - /// The error message, if any to add to the exception. - /// - /// - /// is false - /// - [Conditional("DEBUG")] - public static void IsTrue(bool target, string parameterName, string message) - { - if (!target) - { - throw new ArgumentException(message, parameterName); - } - } - - /// - /// Verifies, that the method parameter with specified target value is false - /// and throws an exception if it is found to be so. - /// - /// The target value, which cannot be true. - /// The name of the parameter that is to be checked. - /// The error message, if any to add to the exception. - /// - /// is true - /// - [Conditional("DEBUG")] - public static void IsFalse(bool target, string parameterName, string message) - { - if (target) - { - throw new ArgumentException(message, parameterName); - } - } - /// /// Verifies, that the `target` array has declared the length or longer. /// diff --git a/src/SixLabors.Core/Helpers/Guard.cs b/src/SixLabors.Core/Helpers/Guard.cs index 41db42fc1..b50cd4ab0 100644 --- a/src/SixLabors.Core/Helpers/Guard.cs +++ b/src/SixLabors.Core/Helpers/Guard.cs @@ -14,78 +14,6 @@ namespace SixLabors [DebuggerStepThrough] internal static class Guard { - /// - /// Verifies, that the method parameter with specified object value is not null - /// and throws an exception if it is found to be so. - /// - /// The target object, which cannot be null. - /// The name of the parameter that is to be checked. - /// The error message, if any to add to the exception. - /// is null - /// The type of the object to verify - public static void NotNull(T target, string parameterName, string message = "") - where T : class - { - if (target == null) - { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentNullException(parameterName, message); - } - - throw new ArgumentNullException(parameterName); - } - } - - /// - /// Verifies, that the string method parameter with specified object value and message - /// is not null, not empty and does not contain only blanks and throws an exception - /// if the object is null. - /// - /// The target string, which should be checked against being null or empty. - /// Name of the parameter. - /// The error message, if any to add to the exception. - /// is null. - /// is empty or contains only blanks. - public static void NotNullOrEmpty(string target, string parameterName, string message = "") - { - NotNull(target, parameterName, message); - - if (string.IsNullOrWhiteSpace(target)) - { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentException(message, parameterName); - } - - throw new ArgumentException("Value cannot be null, empty, or cannot contain only whitespace.", parameterName); - } - } - - /// - /// Verifies, that the enumeration is not null and not empty. - /// - /// The type of objects in the - /// The target enumeration, which should be checked against being null or empty. - /// Name of the parameter. - /// The error message, if any to add to the exception. - /// is null. - /// is empty. - public static void NotNullOrEmpty(IEnumerable target, string parameterName, string message = "") - { - NotNull(target, parameterName, message); - - if (!target.Any()) - { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentException(message, parameterName); - } - - throw new ArgumentException("Value cannot be empty.", parameterName); - } - } - /// /// Verifies that the specified value is less than a maximum value /// and throws an exception if it is not. @@ -98,7 +26,7 @@ namespace SixLabors /// is greater than the maximum value. /// public static void MustBeLessThan(TValue value, TValue max, string parameterName) - where TValue : IComparable + where TValue : IComparable { if (value.CompareTo(max) >= 0) { @@ -118,7 +46,7 @@ namespace SixLabors /// is greater than the maximum value. /// public static void MustBeLessThanOrEqualTo(TValue value, TValue max, string parameterName) - where TValue : IComparable + where TValue : IComparable { if (value.CompareTo(max) > 0) { @@ -187,48 +115,6 @@ namespace SixLabors } } - /// - /// Verifies, that the method parameter with specified target value is true - /// and throws an exception if it is found to be so. - /// - /// - /// The target value, which cannot be false. - /// - /// - /// The name of the parameter that is to be checked. - /// - /// - /// The error message, if any to add to the exception. - /// - /// - /// is false - /// - public static void IsTrue(bool value, string parameterName, string message) - { - if (!value) - { - throw new ArgumentException(message, parameterName); - } - } - - /// - /// Verifies, that the method parameter with specified target value is false - /// and throws an exception if it is found to be so. - /// - /// The target value, which cannot be true. - /// The name of the parameter that is to be checked. - /// The error message, if any to add to the exception. - /// - /// is true - /// - public static void IsFalse(bool value, string parameterName, string message) - { - if (value) - { - throw new ArgumentException(message, parameterName); - } - } - /// /// Verifies, that the `target` span has the length of 'minLength', or longer. /// @@ -247,4 +133,4 @@ namespace SixLabors } } } -} +} \ No newline at end of file diff --git a/src/SixLabors.Core/Helpers/HashHelpers.cs b/src/SixLabors.Core/Helpers/HashHelpers.cs index 40a2b3f96..934384238 100644 --- a/src/SixLabors.Core/Helpers/HashHelpers.cs +++ b/src/SixLabors.Core/Helpers/HashHelpers.cs @@ -1,10 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; + namespace SixLabors { /// - /// Lifted from coreFX repo + /// Provides a set of helpers for combining object hashes. /// internal static class HashHelpers { @@ -13,9 +15,11 @@ namespace SixLabors /// /// Hash code one /// Hash code two - /// Returns a hash code for the two specified has codes. + /// Returns a hash code for the provided hash codes. public static int Combine(int h1, int h2) { + // Lifted from coreFX repo + unchecked { // RyuJIT optimizes this to use the ROL instruction @@ -24,5 +28,38 @@ namespace SixLabors return ((int)rol5 + h1) ^ h2; } } + + /// + /// Combines the three specified hash codes. + /// + /// The first + /// Hash code two + /// Hash code three + /// Returns a hash code for the provided hash codes. + public static int Combine(int h1, int h2, int h3) + { + int hash = Combine(h1, h2); + + hash = Combine(hash, h3); + + return hash; + } + + /// + /// Combines the four specified hash codes. + /// + /// The first + /// Hash code two + /// Hash code three + /// Hash code four + /// Returns a hash code for the provided hash codes. + public static int Combine(int h1, int h2, int h3, int h4) + { + int hash = Combine(h1, h2); + + hash = Combine(hash, h3); + + return Combine(hash, h4); + } } -} +} \ No newline at end of file diff --git a/src/SixLabors.Core/MathF.cs b/src/SixLabors.Core/MathF.cs index 3079c9100..b0d760ade 100644 --- a/src/SixLabors.Core/MathF.cs +++ b/src/SixLabors.Core/MathF.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; -#if NETCOREAPP2_0 +#if SUPPORTS_MATHF [assembly: TypeForwardedTo(typeof(System.MathF))] #else namespace System diff --git a/src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs b/src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs index 31096d3a9..0b0d6c4d4 100644 --- a/src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs +++ b/src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs @@ -51,7 +51,7 @@ namespace SixLabors.Memory /// protected override void Dispose(bool disposing) { - if (!disposing || this.Data == null || this.sourcePoolReference == null) + if (!disposing || this.Data is null || this.sourcePoolReference is null) { return; } @@ -71,7 +71,7 @@ namespace SixLabors.Memory /// /// The implementation of . /// - private class ManagedByteBuffer : Buffer, IManagedByteBuffer + private sealed class ManagedByteBuffer : Buffer, IManagedByteBuffer { public ManagedByteBuffer(byte[] data, int length, ArrayPool sourcePool) : base(data, length, sourcePool) diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index ab12e28ff..de0171796 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/src/SixLabors.Core/Primitives/Point.cs @@ -258,25 +258,20 @@ namespace SixLabors.Primitives public void Offset(Point point) => this.Offset(point.X, point.Y); /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); /// - public override string ToString() - { - return $"Point [ X={this.X}, Y={this.Y} ]"; - } + public override string ToString() => $"Point [ X={this.X}, Y={this.Y} ]"; /// - public override bool Equals(object obj) => obj is Point && this.Equals((Point)obj); + public override bool Equals(object obj) => obj is Point other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Point other) => this.X == other.X && this.Y == other.Y; + public bool Equals(Point other) => this.X.Equals(other.X) && this.Y.Equals(other.Y); private static short HighInt16(int n) => unchecked((short)((n >> 16) & 0xffff)); private static short LowInt16(int n) => unchecked((short)(n & 0xffff)); - - private int GetHashCode(Point point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode()); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/PointF.cs b/src/SixLabors.Core/Primitives/PointF.cs index 7c0431556..c163da7cd 100644 --- a/src/SixLabors.Core/Primitives/PointF.cs +++ b/src/SixLabors.Core/Primitives/PointF.cs @@ -267,30 +267,19 @@ namespace SixLabors.Primitives public void Offset(PointF point) => this.Offset(point.X, point.Y); /// - public override int GetHashCode() => this.GetHashCode(this); - - /// - public override string ToString() + public override int GetHashCode() { - return $"PointF [ X={this.X}, Y={this.Y} ]"; + return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); } + /// + public override string ToString() => $"PointF [ X={this.X}, Y={this.Y} ]"; + /// public override bool Equals(object obj) => obj is PointF && this.Equals((PointF)obj); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(PointF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y); - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private int GetHashCode(PointF point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode()); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/Rectangle.cs b/src/SixLabors.Core/Primitives/Rectangle.cs index 27cba5d15..441c251eb 100644 --- a/src/SixLabors.Core/Primitives/Rectangle.cs +++ b/src/SixLabors.Core/Primitives/Rectangle.cs @@ -117,14 +117,7 @@ namespace SixLabors.Primitives /// /// Gets the y-coordinate of the top edge of this . /// - public int Top - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.Y; - } - } + public int Top => this.Y; /// /// Gets the x-coordinate of the right edge of this . @@ -132,10 +125,7 @@ namespace SixLabors.Primitives public int Right { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return unchecked(this.X + this.Width); - } + get => unchecked(this.X + this.Width); } /// @@ -144,23 +134,14 @@ namespace SixLabors.Primitives public int Bottom { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return unchecked(this.Y + this.Height); - } + get => unchecked(this.Y + this.Height); + } /// /// Gets the x-coordinate of the left edge of this . /// - public int Left - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.X; - } - } + public int Left => this.X; /// /// Creates a with the coordinates of the specified . @@ -443,7 +424,14 @@ namespace SixLabors.Primitives } /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine( + this.X.GetHashCode(), + this.Y.GetHashCode(), + this.Width.GetHashCode(), + this.Height.GetHashCode()); + } /// public override string ToString() @@ -452,19 +440,14 @@ namespace SixLabors.Primitives } /// - public override bool Equals(object obj) => obj is Rectangle && this.Equals((Rectangle)obj); + public override bool Equals(object obj) => obj is Rectangle other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Rectangle other) => this.X == other.X && this.Y == other.Y && this.Width == other.Width && this.Height == other.Height; - - private int GetHashCode(Rectangle rectangle) - { - int hashCode = rectangle.X.GetHashCode(); - hashCode = HashHelpers.Combine(hashCode, rectangle.Y.GetHashCode()); - hashCode = HashHelpers.Combine(hashCode, rectangle.Width.GetHashCode()); - hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode()); - return hashCode; - } + public bool Equals(Rectangle other) => + this.X.Equals(other.X) && + this.Y.Equals(other.Y) && + this.Width.Equals(other.Width) && + this.Height.Equals(other.Height); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/RectangleF.cs b/src/SixLabors.Core/Primitives/RectangleF.cs index d5ee6a61b..535705a28 100644 --- a/src/SixLabors.Core/Primitives/RectangleF.cs +++ b/src/SixLabors.Core/Primitives/RectangleF.cs @@ -117,14 +117,7 @@ namespace SixLabors.Primitives /// /// Gets the y-coordinate of the top edge of this . /// - public float Top - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.Y; - } - } + public float Top => this.Y; /// /// Gets the x-coordinate of the right edge of this . @@ -132,10 +125,7 @@ namespace SixLabors.Primitives public float Right { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.X + this.Width; - } + get => this.X + this.Width; } /// @@ -144,23 +134,13 @@ namespace SixLabors.Primitives public float Bottom { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.Y + this.Height; - } + get => this.Y + this.Height; } /// /// Gets the x-coordinate of the left edge of this . /// - public float Left - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.X; - } - } + public float Left => this.X; /// /// Creates a with the coordinates of the specified by truncating each coordinate. @@ -376,7 +356,14 @@ namespace SixLabors.Primitives } /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine( + this.X.GetHashCode(), + this.Y.GetHashCode(), + this.Width.GetHashCode(), + this.Height.GetHashCode()); + } /// public override string ToString() @@ -385,19 +372,14 @@ namespace SixLabors.Primitives } /// - public override bool Equals(object obj) => obj is RectangleF && this.Equals((RectangleF)obj); + public override bool Equals(object obj) => obj is RectangleF other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(RectangleF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y) && this.Width.Equals(other.Width) && this.Height.Equals(other.Height); - - private int GetHashCode(RectangleF rectangle) - { - int hashCode = rectangle.X.GetHashCode(); - hashCode = HashHelpers.Combine(hashCode, rectangle.Y.GetHashCode()); - hashCode = HashHelpers.Combine(hashCode, rectangle.Width.GetHashCode()); - hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode()); - return hashCode; - } + public bool Equals(RectangleF other) => + this.X.Equals(other.X) && + this.Y.Equals(other.Y) && + this.Width.Equals(other.Width) && + this.Height.Equals(other.Height); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/Size.cs b/src/SixLabors.Core/Primitives/Size.cs index 57884cf5d..86412a137 100644 --- a/src/SixLabors.Core/Primitives/Size.cs +++ b/src/SixLabors.Core/Primitives/Size.cs @@ -252,20 +252,17 @@ namespace SixLabors.Primitives public static Size Truncate(SizeF size) => new Size(unchecked((int)size.Width), unchecked((int)size.Height)); /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() => HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode()); /// - public override string ToString() - { - return $"Size [ Width={this.Width}, Height={this.Height} ]"; - } + public override string ToString() => $"Size [ Width={this.Width}, Height={this.Height} ]"; /// - public override bool Equals(object obj) => obj is Size && this.Equals((Size)obj); + public override bool Equals(object obj) => obj is Size other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Size other) => this.Width == other.Width && this.Height == other.Height; + public bool Equals(Size other) => this.Width.Equals(other.Width) && this.Height.Equals(other.Height); /// /// Multiplies by an producing . @@ -284,16 +281,5 @@ namespace SixLabors.Primitives /// Product of type SizeF. private static SizeF Multiply(Size size, float multiplier) => new SizeF(size.Width * multiplier, size.Height * multiplier); - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private int GetHashCode(Size size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode()); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/SizeF.cs b/src/SixLabors.Core/Primitives/SizeF.cs index 13c6552ac..8dbdd7424 100644 --- a/src/SixLabors.Core/Primitives/SizeF.cs +++ b/src/SixLabors.Core/Primitives/SizeF.cs @@ -200,14 +200,11 @@ namespace SixLabors.Primitives /// public override int GetHashCode() { - return this.GetHashCode(this); + return HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode()); } /// - public override string ToString() - { - return $"SizeF [ Width={this.Width}, Height={this.Height} ]"; - } + public override string ToString() => $"SizeF [ Width={this.Width}, Height={this.Height} ]"; /// public override bool Equals(object obj) => obj is SizeF && this.Equals((SizeF)obj); @@ -224,7 +221,5 @@ namespace SixLabors.Primitives /// Product of type SizeF. private static SizeF Multiply(SizeF size, float multiplier) => new SizeF(size.Width * multiplier, size.Height * multiplier); - - private int GetHashCode(SizeF size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode()); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Properties/AssemblyInfo.cs b/src/SixLabors.Core/Properties/AssemblyInfo.cs index 96a40f6f6..92c683b13 100644 --- a/src/SixLabors.Core/Properties/AssemblyInfo.cs +++ b/src/SixLabors.Core/Properties/AssemblyInfo.cs @@ -1,37 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Reflection; -using System.Resources; using System.Runtime.CompilerServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SixLabors.Core")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Six Labors")] -[assembly: AssemblyProduct("SixLabors.Core")] -[assembly: AssemblyCopyright("Copyright (c) Six Labors and contributors.")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.0")] -[assembly: AssemblyFileVersion("0.1.0")] -[assembly: AssemblyInformationalVersion("0.1.0-alpha02")] - // Ensure the internals can be tested. [assembly: InternalsVisibleTo("SixLabors.Core.Tests")] @@ -41,4 +12,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("SixLabors.ImageSharp")] [assembly: InternalsVisibleTo("SixLabors.ImageSharp.Drawing")] [assembly: InternalsVisibleTo("SixLabors.Shapes")] -[assembly: InternalsVisibleTo("SixLabors.Shapes.Text")] +[assembly: InternalsVisibleTo("SixLabors.Shapes.Text")] \ No newline at end of file diff --git a/src/SixLabors.Core/SixLabors.Core.csproj b/src/SixLabors.Core/SixLabors.Core.csproj index bc37cd2e2..b03eac761 100644 --- a/src/SixLabors.Core/SixLabors.Core.csproj +++ b/src/SixLabors.Core/SixLabors.Core.csproj @@ -5,7 +5,7 @@ $(packageversion) 0.1.0-alpha2 Six Labors - netstandard1.1;netcoreapp2.0; + netstandard1.1;netcoreapp2.0;netcoreapp2.1; true true SixLabors.Core @@ -16,16 +16,7 @@ http://www.apache.org/licenses/LICENSE-2.0 git https://github.com/SixLabors/Core - false - false - false - false - false - false - false - false - false - false + Copyright (c) Six Labors and contributors. full SixLabors @@ -34,19 +25,28 @@ ..\SixLabors.ruleset + + $(DefineConstants);SUPPORTS_MATHF + + + + All + + - + - - All - + + + + - - - + + + \ No newline at end of file diff --git a/tests/CodeCoverage/CodeCoverage.cmd b/tests/CodeCoverage/CodeCoverage.cmd index d5318bf7a..347e0338c 100644 --- a/tests/CodeCoverage/CodeCoverage.cmd +++ b/tests/CodeCoverage/CodeCoverage.cmd @@ -10,7 +10,7 @@ cd .. dotnet restore SixLabors.Core.sln dotnet build SixLabors.Core.sln --no-incremental -c release /p:codecov=true -tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\SixLabors.Core.Tests\SixLabors.Core.Tests.csproj --no-build -c release" -searchdirs:"tests\SixLabors.Core.Tests\bin\Release\netcoreapp1.1" -register:user -output:.\SixLabors.Core.Coverage.xml -hideskipped:All -returntargetcode -oldStyle -filter:"+[SixLabors.*]*" +tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\SixLabors.Core.Tests\SixLabors.Core.Tests.csproj --no-build -c release" -searchdirs:"tests\SixLabors.Core.Tests\bin\Release\netcoreapp2.1" -register:user -output:.\SixLabors.Core.Coverage.xml -hideskipped:All -returntargetcode -oldStyle -filter:"+[SixLabors.*]*" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs index 843b74ded..68416b47d 100644 --- a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs @@ -5,7 +5,6 @@ #define DEBUG using System; -using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; @@ -100,7 +99,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"Value must be greater than {min}.")); + Assert.Contains($"Value must be greater than {min}.", exception.Message); } [Theory] @@ -120,43 +119,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"Value must be greater than or equal to 2.")); - } - - [Fact] - public void IsTrue_IsTrue_ThrowsNoException() - { - DebugGuard.IsTrue(true, "myParamName", "myTestMessage"); - } - - [Fact] - public void IsTrue_IsFalse_ThrowsException() - { - var exception = Assert.Throws(() => - { - DebugGuard.IsTrue(false, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - - [Fact] - public void IsFalse_IsFalse_ThrowsNoException() - { - DebugGuard.IsFalse(false, "myParamName", "myTestMessage"); - } - - [Fact] - public void IsFalse_IsTrue_ThrowsException() - { - var exception = Assert.Throws(() => - { - DebugGuard.IsFalse(true, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); + Assert.Contains($"Value must be greater than or equal to 2.", exception.Message); } [Theory] diff --git a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs index ed2e0b5c7..ecffd79da 100644 --- a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs @@ -2,128 +2,12 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; -using System.Linq; using Xunit; namespace SixLabors.Helpers.Tests { public class GuardTests { - [Fact] - public void NotNull_TargetNotNull_ThrowsNoException() - { - Guard.NotNull("test", "myParamName"); - } - - [Fact] - public void NotNull_TargetNull_ThrowsException() - { - Assert.Throws(() => - { - Guard.NotNull((object)null, "myParamName"); - }); - } - - [Fact] - public void NotNull_TargetNullWithMessage_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNull((object)null, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - - [Fact] - public void NotNullOrEmpty_TargetNotNullOrEmpty_ThrowsNoException() - { - Guard.NotNullOrEmpty("test", "myParamName"); - } - - [Fact] - public void NotNullOrEmpty_TargetNull_ThrowsException() - { - Assert.Throws(() => - { - Guard.NotNullOrEmpty(null, "myParamName"); - }); - } - - [Fact] - public void NotNullOrEmpty_TargetWhitespace_ThrowsException() - { - Assert.Throws(() => - { - Guard.NotNullOrEmpty("\n\n", "myParamName"); - }); - } - - [Fact] - public void NotNullOrEmpty_TargetEmpty_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNullOrEmpty(string.Empty, "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("Value cannot be null, empty, or cannot contain only whitespace.")); - } - - [Fact] - public void NotNullOrEmpty_TargetEmptyWithMessage_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNullOrEmpty(string.Empty, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - - [Fact] - public void NotNullOrEmptyIEnumerable_TargetNotNullOrEmpty_ThrowsNoException() - { - Guard.NotNullOrEmpty(new string[] { "test" }, "myParamName"); - } - - [Fact] - public void NotNullOrEmptyIEnumerable_TargetNull_ThrowsException() - { - Assert.Throws(() => - { - Guard.NotNullOrEmpty((IEnumerable)null, "myParamName"); - }); - } - - [Fact] - public void NotNullOrEmptyIEnumerable_TargetEmpty_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNullOrEmpty(new string[] { }, "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("Value cannot be empty.")); - } - - [Fact] - public void NotNullOrEmptyIEnumerable_TargetEmptyWithMessage_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNullOrEmpty(new string[] { }, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - [Fact] public void MustBeLessThan_IsLess_ThrowsNoException() { @@ -181,7 +65,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"Value must be greater than {min}.")); + Assert.Contains($"Value must be greater than {min}.", exception.Message); } [Theory] @@ -224,43 +108,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"Value must be greater than or equal to {min} and less than or equal to {max}.")); - } - - [Fact] - public void IsTrue_IsTrue_ThrowsNoException() - { - Guard.IsTrue(true, "myParamName", "myTestMessage"); - } - - [Fact] - public void IsTrue_IsFalse_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.IsTrue(false, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - - [Fact] - public void IsFalse_IsFalse_ThrowsNoException() - { - Guard.IsFalse(false, "myParamName", "myTestMessage"); - } - - [Fact] - public void IsFalse_IsTrue_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.IsFalse(true, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); + Assert.Contains($"Value must be greater than or equal to {min} and less than or equal to {max}.", exception.Message); } [Theory] @@ -280,7 +128,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"The size must be at least 3.")); + Assert.Contains("The size must be at least 3.", exception.Message); } } } diff --git a/tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs b/tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs new file mode 100644 index 000000000..7091038ad --- /dev/null +++ b/tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs @@ -0,0 +1,28 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using Xunit; + +namespace SixLabors.Tests.Helpers +{ + public class HashHelpersTests + { + [Fact] + public void CanCombineTwoValues() + { + Assert.Equal(35, HashHelpers.Combine(1, 2)); + } + + [Fact] + public void CanCombineThreeValues() + { + Assert.Equal(1152, HashHelpers.Combine(1, 2, 3)); + } + + [Fact] + public void CanCombineFourValues() + { + Assert.Equal(38020, HashHelpers.Combine(1, 2, 3, 4)); + } + } +} \ No newline at end of file diff --git a/tests/SixLabors.Core.Tests/Helpers/MathFTests.cs b/tests/SixLabors.Core.Tests/Helpers/MathFTests.cs index 477259983..1d9ea1523 100644 --- a/tests/SixLabors.Core.Tests/Helpers/MathFTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/MathFTests.cs @@ -6,6 +6,7 @@ using Xunit; namespace SixLabors.Tests.Helpers { + public class MathFTests { [Fact] diff --git a/tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs index 0068fce91..6e7efebb8 100644 --- a/tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -80,7 +80,6 @@ namespace SixLabors.Memory.Tests Assert.True(this.CheckIsRentingPooledBuffer(size)); } - [Theory] [InlineData(128 * 1024 * 1024)] [InlineData(MaxPooledBufferSizeInBytes + 1)] diff --git a/tests/SixLabors.Core.Tests/Primitives/PointFTests.cs b/tests/SixLabors.Core.Tests/Primitives/PointFTests.cs index 6fdf1bbc3..cdd7410d5 100644 --- a/tests/SixLabors.Core.Tests/Primitives/PointFTests.cs +++ b/tests/SixLabors.Core.Tests/Primitives/PointFTests.cs @@ -5,12 +5,24 @@ using System; using System.Globalization; using System.Numerics; using System.Reflection; +using System.Runtime.CompilerServices; using Xunit; namespace SixLabors.Primitives.Tests { public class PointFTests { + [Fact] + public void CanReinterpretCastFromVector2() + { + var vector = new Vector2(1, 2); + + PointF point = Unsafe.As(ref vector); + + Assert.Equal(vector.X, point.X); + Assert.Equal(vector.Y, point.Y); + } + [Fact] public void DefaultConstructorTest() { diff --git a/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj b/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj index d23fb956a..64545d082 100644 --- a/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj +++ b/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj @@ -2,7 +2,7 @@ 0.0.0 - netcoreapp1.1;netcoreapp2.0; + netcoreapp1.1;netcoreapp2.1; SixLabors.Core.Tests SixLabors.Shapes.Tests true @@ -28,18 +28,14 @@ - - - - + + + + - - - -