From 3dadce9484530370f9e1de64c170ff5a51b4f2bb Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 13 Sep 2017 20:13:57 +0100 Subject: [PATCH] [SL.Core] Remove System.Memory from core --- src/SixLabors.Core/Helpers/DebugGuard.cs | 80 ------------------- src/SixLabors.Core/Helpers/Guard.cs | 18 ----- src/SixLabors.Core/SixLabors.Core.csproj | 3 +- .../Helpers/DebugGuardTests.cs | 76 ------------------ .../Helpers/GuardTests.cs | 40 ---------- 5 files changed, 1 insertion(+), 216 deletions(-) diff --git a/src/SixLabors.Core/Helpers/DebugGuard.cs b/src/SixLabors.Core/Helpers/DebugGuard.cs index 4a2ed9473..c649372ee 100644 --- a/src/SixLabors.Core/Helpers/DebugGuard.cs +++ b/src/SixLabors.Core/Helpers/DebugGuard.cs @@ -158,86 +158,6 @@ namespace SixLabors } } - /// - /// Verifies, that the target span is of same size than the 'other' span. - /// - /// The element type of the spans - /// The target span. - /// The 'other' span to compare 'target' to. - /// The name of the parameter that is to be checked. - /// - /// is true - /// - [Conditional("DEBUG")] - public static void MustBeSameSized(ReadOnlySpan target, ReadOnlySpan other, string parameterName) - where T : struct - { - if (target.Length != other.Length) - { - throw new ArgumentException("Span-s must be the same size.", parameterName); - } - } - - /// - /// Verifies, that the target span is of same size than the 'other' span. - /// - /// The element type of the spans - /// The target span. - /// The 'other' span to compare 'target' to. - /// The name of the parameter that is to be checked. - /// - /// is true - /// - [Conditional("DEBUG")] - public static void MustBeSameSized(Span target, Span other, string parameterName) - where T : struct - { - if (target.Length != other.Length) - { - throw new ArgumentException("Span-s must be the same size.", parameterName); - } - } - - /// - /// Verifies, that the `target` span has the length of 'minSpan', or longer. - /// - /// The element type of the spans - /// The target span. - /// The 'minSpan' span to compare 'target' to. - /// The name of the parameter that is to be checked. - /// - /// is true - /// - [Conditional("DEBUG")] - public static void MustBeSizedAtLeast(ReadOnlySpan target, ReadOnlySpan minSpan, string parameterName) - where T : struct - { - if (target.Length < minSpan.Length) - { - throw new ArgumentException($"Span-s must be at least of length {minSpan.Length}.", parameterName); - } - } - - /// - /// Verifies, that the `target` span has the length of 'minSpan', or longer. - /// - /// The element type of the spans - /// The target span. - /// The 'minSpan' span to compare 'target' to. - /// The name of the parameter that is to be checked. - /// - /// is true - /// - [Conditional("DEBUG")] - public static void MustBeSizedAtLeast(Span target, Span minSpan, string parameterName) - where T : struct - { - if (target.Length < minSpan.Length) - { - throw new ArgumentException($"Span-s must be at least of length {minSpan.Length}.", 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 ea92a85c0..3a38551d8 100644 --- a/src/SixLabors.Core/Helpers/Guard.cs +++ b/src/SixLabors.Core/Helpers/Guard.cs @@ -244,23 +244,5 @@ namespace SixLabors throw new ArgumentException($"The size must be at least {minLength}.", parameterName); } } - - /// - /// Verifies, that the `target` span has the length of 'minLength', or longer. - /// - /// The element type of the spans - /// The target span. - /// The minimum length. - /// The name of the parameter that is to be checked. - /// - /// The length of is less than . - /// - public static void MustBeSizedAtLeast(ReadOnlySpan value, int minLength, string parameterName) - { - if (value.Length < minLength) - { - throw new ArgumentException($"The size must be at least {minLength}.", parameterName); - } - } } } diff --git a/src/SixLabors.Core/SixLabors.Core.csproj b/src/SixLabors.Core/SixLabors.Core.csproj index 37d4b9013..a5a174536 100644 --- a/src/SixLabors.Core/SixLabors.Core.csproj +++ b/src/SixLabors.Core/SixLabors.Core.csproj @@ -43,8 +43,7 @@ All - - + \ No newline at end of file diff --git a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs index 1e651f267..99661dfe0 100644 --- a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs @@ -178,81 +178,5 @@ namespace SixLabors.Helpers.Tests Assert.Equal("myParamName", exception.ParamName); Assert.Contains($"The size must be at least 3.", exception.Message); } - - [Fact] - public void MustBeSizedAtLeast_ReadOnlySpan_LengthIsLess_ThrowsException() - { - var exception = Assert.Throws(() => - { - DebugGuard.MustBeSizedAtLeast(new ReadOnlySpan(new int[2]), new ReadOnlySpan(new int[3]), "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.Contains($"Span-s must be at least of length 3.", exception.Message); - } - - [Fact] - public void MustBeSizedAtLeast_Span_LengthIsLess_ThrowsException() - { - var exception = Assert.Throws(() => - { - DebugGuard.MustBeSizedAtLeast(new Span(new int[2]), new Span(new int[3]), "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.Contains($"Span-s must be at least of length 3.", exception.Message); - } - - [Fact] - public void MustBeSameSized_ReadOnlySpan_LengthIsLess_ThrowsException() - { - var exception = Assert.Throws(() => - { - DebugGuard.MustBeSameSized(new ReadOnlySpan(new int[2]), new ReadOnlySpan(new int[3]), "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.Contains($"Span-s must be the same size.", exception.Message); - } - - [Fact] - public void MustBeSameSized_Span_LengthIsLess_ThrowsException() - { - var exception = Assert.Throws(() => - { - DebugGuard.MustBeSameSized(new Span(new int[2]), new Span(new int[3]), "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.Contains($"Span-s must be the same size.", exception.Message); - } - - [Theory] - [InlineData(2, 2)] - [InlineData(4, 3)] - public void MustBeSizedAtLeast_ReadOnlySpan_LengthIsEqualOrGreater_DoesNotThowException(int leftSize, int rightSize) - { - DebugGuard.MustBeSizedAtLeast(new ReadOnlySpan(new int[leftSize]), new ReadOnlySpan(new int[rightSize]), "myParamName"); - } - - [Theory] - [InlineData(2, 2)] - [InlineData(4, 3)] - public void MustBeSizedAtLeast_Span_LengthIsEqualOrGreater_DoesNotThowException(int leftSize, int rightSize) - { - DebugGuard.MustBeSizedAtLeast(new Span(new int[leftSize]), new Span(new int[rightSize]), "myParamName"); - } - - [Fact] - public void MustBeSameSized_ReadOnlySpan_LengthIsEqual_DoesNotThrowException() - { - DebugGuard.MustBeSameSized(new ReadOnlySpan(new int[2]), new ReadOnlySpan(new int[2]), "myParamName"); - } - - [Fact] - public void MustBeSameSized_Span_LengthIsEqual_DoesNotThrowException() - { - DebugGuard.MustBeSameSized(new Span(new int[2]), new Span(new int[2]), "myParamName"); - } } } diff --git a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs index b7f859f35..95901c774 100644 --- a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs @@ -271,22 +271,6 @@ namespace SixLabors.Helpers.Tests Guard.MustBeSizedAtLeast(new int[valueLength], minLength, "myParamName"); } - [Theory] - [InlineData(2, 1)] - [InlineData(2, 2)] - public void MustBeSizedAtLeast_Span_LengthIsGreaterOrEqual_ThrowsNoException(int valueLength, int minLength) - { - Guard.MustBeSizedAtLeast(new Span(new int[valueLength]), minLength, "myParamName"); - } - - [Theory] - [InlineData(2, 1)] - [InlineData(2, 2)] - public void MustBeSizedAtLeast_ReadOnlySpan_LengthIsGreaterOrEqual_ThrowsNoException(int valueLength, int minLength) - { - Guard.MustBeSizedAtLeast(new ReadOnlySpan(new int[valueLength]), minLength, "myParamName"); - } - [Fact] public void MustBeSizedAtLeast_Array_LengthIsLess_ThrowsException() { @@ -298,29 +282,5 @@ namespace SixLabors.Helpers.Tests Assert.Equal("myParamName", exception.ParamName); Assert.True(exception.Message.Contains($"The size must be at least 3.")); } - - [Fact] - public void MustBeSizedAtLeast_Span_LengthIsLess_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.MustBeSizedAtLeast(new Span(new int[2]), 3, "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"The size must be at least 3.")); - } - - [Fact] - public void MustBeSizedAtLeast_ReadOnlySpan_LengthIsLess_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.MustBeSizedAtLeast(new ReadOnlySpan(new int[2]), 3, "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"The size must be at least 3.")); - } } }