Browse Source

[SL.Core] Remove System.Memory from core

pull/1087/head
Scott Williams 9 years ago
parent
commit
3dadce9484
  1. 80
      src/SixLabors.Core/Helpers/DebugGuard.cs
  2. 18
      src/SixLabors.Core/Helpers/Guard.cs
  3. 3
      src/SixLabors.Core/SixLabors.Core.csproj
  4. 76
      tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs
  5. 40
      tests/SixLabors.Core.Tests/Helpers/GuardTests.cs

80
src/SixLabors.Core/Helpers/DebugGuard.cs

@ -158,86 +158,6 @@ namespace SixLabors
}
}
/// <summary>
/// Verifies, that the target span is of same size than the 'other' span.
/// </summary>
/// <typeparam name="T">The element type of the spans</typeparam>
/// <param name="target">The target span.</param>
/// <param name="other">The 'other' span to compare 'target' to.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is true
/// </exception>
[Conditional("DEBUG")]
public static void MustBeSameSized<T>(ReadOnlySpan<T> target, ReadOnlySpan<T> other, string parameterName)
where T : struct
{
if (target.Length != other.Length)
{
throw new ArgumentException("Span-s must be the same size.", parameterName);
}
}
/// <summary>
/// Verifies, that the target span is of same size than the 'other' span.
/// </summary>
/// <typeparam name="T">The element type of the spans</typeparam>
/// <param name="target">The target span.</param>
/// <param name="other">The 'other' span to compare 'target' to.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is true
/// </exception>
[Conditional("DEBUG")]
public static void MustBeSameSized<T>(Span<T> target, Span<T> other, string parameterName)
where T : struct
{
if (target.Length != other.Length)
{
throw new ArgumentException("Span-s must be the same size.", parameterName);
}
}
/// <summary>
/// Verifies, that the `target` span has the length of 'minSpan', or longer.
/// </summary>
/// <typeparam name="T">The element type of the spans</typeparam>
/// <param name="target">The target span.</param>
/// <param name="minSpan">The 'minSpan' span to compare 'target' to.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is true
/// </exception>
[Conditional("DEBUG")]
public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> target, ReadOnlySpan<T> 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);
}
}
/// <summary>
/// Verifies, that the `target` span has the length of 'minSpan', or longer.
/// </summary>
/// <typeparam name="T">The element type of the spans</typeparam>
/// <param name="target">The target span.</param>
/// <param name="minSpan">The 'minSpan' span to compare 'target' to.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is true
/// </exception>
[Conditional("DEBUG")]
public static void MustBeSizedAtLeast<T>(Span<T> target, Span<T> 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);
}
}
/// <summary>
/// Verifies, that the `target` array has declared the length or longer.
/// </summary>

18
src/SixLabors.Core/Helpers/Guard.cs

@ -244,23 +244,5 @@ namespace SixLabors
throw new ArgumentException($"The size must be at least {minLength}.", parameterName);
}
}
/// <summary>
/// Verifies, that the `target` span has the length of 'minLength', or longer.
/// </summary>
/// <typeparam name="T">The element type of the spans</typeparam>
/// <param name="value">The target span.</param>
/// <param name="minLength">The minimum length.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <exception cref="ArgumentException">
/// The length of <paramref name="value"/> is less than <paramref name="minLength"/>.
/// </exception>
public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> value, int minLength, string parameterName)
{
if (value.Length < minLength)
{
throw new ArgumentException($"The size must be at least {minLength}.", parameterName);
}
}
}
}

3
src/SixLabors.Core/SixLabors.Core.csproj

@ -43,8 +43,7 @@
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Numerics.Vectors" Version="4.3.0" />
<PackageReference Include="System.Memory" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="System.Numerics.Vectors" Version="4.4.0" />
</ItemGroup>
</Project>

76
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<ArgumentException>(() =>
{
DebugGuard.MustBeSizedAtLeast(new ReadOnlySpan<int>(new int[2]), new ReadOnlySpan<int>(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<ArgumentException>(() =>
{
DebugGuard.MustBeSizedAtLeast(new Span<int>(new int[2]), new Span<int>(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<ArgumentException>(() =>
{
DebugGuard.MustBeSameSized(new ReadOnlySpan<int>(new int[2]), new ReadOnlySpan<int>(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<ArgumentException>(() =>
{
DebugGuard.MustBeSameSized(new Span<int>(new int[2]), new Span<int>(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<int>(new int[leftSize]), new ReadOnlySpan<int>(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<int>(new int[leftSize]), new Span<int>(new int[rightSize]), "myParamName");
}
[Fact]
public void MustBeSameSized_ReadOnlySpan_LengthIsEqual_DoesNotThrowException()
{
DebugGuard.MustBeSameSized(new ReadOnlySpan<int>(new int[2]), new ReadOnlySpan<int>(new int[2]), "myParamName");
}
[Fact]
public void MustBeSameSized_Span_LengthIsEqual_DoesNotThrowException()
{
DebugGuard.MustBeSameSized(new Span<int>(new int[2]), new Span<int>(new int[2]), "myParamName");
}
}
}

40
tests/SixLabors.Core.Tests/Helpers/GuardTests.cs

@ -271,22 +271,6 @@ namespace SixLabors.Helpers.Tests
Guard.MustBeSizedAtLeast<int>(new int[valueLength], minLength, "myParamName");
}
[Theory]
[InlineData(2, 1)]
[InlineData(2, 2)]
public void MustBeSizedAtLeast_Span_LengthIsGreaterOrEqual_ThrowsNoException(int valueLength, int minLength)
{
Guard.MustBeSizedAtLeast<int>(new Span<int>(new int[valueLength]), minLength, "myParamName");
}
[Theory]
[InlineData(2, 1)]
[InlineData(2, 2)]
public void MustBeSizedAtLeast_ReadOnlySpan_LengthIsGreaterOrEqual_ThrowsNoException(int valueLength, int minLength)
{
Guard.MustBeSizedAtLeast<int>(new ReadOnlySpan<int>(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<ArgumentException>(() =>
{
Guard.MustBeSizedAtLeast<int>(new Span<int>(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<ArgumentException>(() =>
{
Guard.MustBeSizedAtLeast<int>(new ReadOnlySpan<int>(new int[2]), 3, "myParamName");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains($"The size must be at least 3."));
}
}
}

Loading…
Cancel
Save