diff --git a/.editorconfig b/.editorconfig
index 8f0e28eec6..b0d0662bf8 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -79,6 +79,7 @@ dotnet_naming_rule.private_and_internal_fields_should_be_camel_case.symbols = pr
dotnet_naming_rule.public_and_protected_declarations_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.public_and_protected_declarations_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.public_and_protected_declarations_should_be_pascal_case.symbols = public_and_protected_declarations
+dotnet_naming_symbols.public_and_protected_declarations.applicable_kinds = method, field, event, property
dotnet_naming_rule.static_readonly_declarations_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.static_readonly_declarations_should_be_pascal_case.style = pascal_case
@@ -322,11 +323,11 @@ csharp_space_between_square_brackets = false
# suggest conditional delegate calls,
# suggest deconstructed variable declarations,
# generate expression-bodied accessors,
-# don't generate expression-bodied constructors,
+# generate expression-bodied constructors,
# generate expression-bodied indexers,
# generate expression-bodied lambdas,
-# don't generate expression-bodied methods,
-# don't generate expression-bodied operators,
+# generate expression-bodied methods,
+# generate expression-bodied operators,
# generate expression-bodied properties,
# suggest inlined variable declarations,
# suggest local over anonymous functions,
@@ -348,11 +349,11 @@ csharp_style_conditional_delegate_call = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_expression_bodied_accessors = true:silent
-csharp_style_expression_bodied_constructors = false:silent
+csharp_style_expression_bodied_constructors = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:silent
-csharp_style_expression_bodied_methods = false:silent
-csharp_style_expression_bodied_operators = false:silent
+csharp_style_expression_bodied_methods = true:silent
+csharp_style_expression_bodied_operators = true:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_inlined_variable_declaration = true:suggestion
diff --git a/.gitmodules b/.gitmodules
index 37ef701cdf..55389121f2 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -2,6 +2,6 @@
path = tests/Images/External
url = https://github.com/SixLabors/Imagesharp.Tests.Images.git
branch = master
-[submodule "standards"]
- path = standards
- url = https://github.com/SixLabors/Standards
+[submodule "shared-infrastructure"]
+ path = shared-infrastructure
+ url = https://github.com/SixLabors/SharedInfrastructure
diff --git a/Directory.Build.props b/Directory.Build.props
index bf004921ea..efe4cc9665 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -52,7 +52,7 @@
- $(MSBuildThisFileDirectory)standards/SixLabors.snk
+ $(MSBuildThisFileDirectory)shared-infrastructure/SixLabors.snk
Copyright © Six Labors and Contributors
strict;IOperation
true
diff --git a/Directory.Build.targets b/Directory.Build.targets
index d1183e5d46..1551a29d8c 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -28,10 +28,10 @@
-
-
-
-
+
+
+
+
diff --git a/ImageSharp.sln b/ImageSharp.sln
index 1fd5e2d8b4..d4a0419eed 100644
--- a/ImageSharp.sln
+++ b/ImageSharp.sln
@@ -21,7 +21,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
LICENSE = LICENSE
README.md = README.md
run-tests.ps1 = run-tests.ps1
- stylecop.json = stylecop.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{1799C43E-5C54-4A8F-8D64-B1475241DB0D}"
diff --git a/shared-infrastructure b/shared-infrastructure
new file mode 160000
index 0000000000..faf84e44ec
--- /dev/null
+++ b/shared-infrastructure
@@ -0,0 +1 @@
+Subproject commit faf84e44ec90e8a42a7271bcd04fea76279efb08
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index cd3d5e8cb3..6fbbb7c916 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -18,12 +18,12 @@
- $(MSBuildThisFileDirectory)..\standards\SixLabors.ruleset
+ $(MSBuildThisFileDirectory)..\shared-infrastructure\SixLabors.ruleset
true
-
+
diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
index a092e3604b..5a53d3e78b 100644
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
+++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
@@ -1,4 +1,4 @@
-
+
@@ -11,6 +11,15 @@
netcoreapp2.1;netstandard1.3;netstandard2.0
+
+
+ $(DefineConstants);SUPPORTS_MATHF
+
+
+
+ $(DefineConstants);SUPPORTS_HASHCODE
+
+
diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs
index 43eebeac87..356dd419b5 100644
--- a/src/ImageSharp/Common/Helpers/DebugGuard.cs
+++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs
@@ -1,168 +1,17 @@
-// Copyright (c) Six Labors and contributors.
+// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Diagnostics;
// TODO: These should just call the guard equivalents
-namespace SixLabors.ImageSharp
+namespace SixLabors
{
///
/// Provides methods to protect against invalid parameters for a DEBUG build.
///
- [DebuggerStepThrough]
- internal static class DebugGuard
+ internal static partial class DebugGuard
{
- ///
- /// 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.
- /// is null
- [Conditional("DEBUG")]
- public static void NotNull(T value, string parameterName)
- where T : class
- {
- if (value is null)
- {
- throw new ArgumentNullException(parameterName);
- }
- }
-
- ///
- /// Verifies that the specified value is less than a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is greater than the maximum value.
- ///
- [Conditional("DEBUG")]
- public static void MustBeLessThan(TValue value, TValue max, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(max) >= 0)
- {
- throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than {max}.");
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is greater than the maximum value.
- ///
- [Conditional("DEBUG")]
- public static void MustBeLessThanOrEqualTo(TValue value, TValue max, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(max) > 0)
- {
- throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than or equal to {max}.");
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is less than the minimum value.
- ///
- [Conditional("DEBUG")]
- public static void MustBeGreaterThan(TValue value, TValue min, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(min) <= 0)
- {
- throw new ArgumentOutOfRangeException(
- parameterName,
- $"Value must be greater than {min}.");
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is less than the minimum value.
- ///
- [Conditional("DEBUG")]
- public static void MustBeGreaterThanOrEqualTo(TValue value, TValue min, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(min) < 0)
- {
- throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min}.");
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [Conditional("DEBUG")]
- public static void MustBeBetweenOrEqualTo(TValue value, TValue min, TValue max, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0)
- {
- throw new ArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min} and less than or equal to {max}.");
- }
- }
-
- ///
- /// 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 whether a specific condition is met, throwing an exception if it's false.
///
@@ -177,25 +26,6 @@ public static void IsTrue(bool target, string message)
}
}
- ///
- /// 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 span is of same size than the 'other' span.
///
@@ -236,4 +66,4 @@ public static void MustBeSizedAtLeast(Span target, Span minSpan, string
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs
deleted file mode 100644
index 7dc683c37f..0000000000
--- a/src/ImageSharp/Common/Helpers/Guard.cs
+++ /dev/null
@@ -1,294 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace SixLabors.ImageSharp
-{
- ///
- /// Provides methods to protect against invalid parameters.
- ///
- [DebuggerStepThrough]
- internal static class Guard
- {
- ///
- /// Ensures that the value is not null.
- ///
- /// The target object, which cannot be null.
- /// The name of the parameter that is to be checked.
- /// is null
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void NotNull(T value, string parameterName)
- where T : class
- {
- if (value is null)
- {
- ThrowArgumentNullException(parameterName);
- }
- }
-
- ///
- /// Ensures that the target value is not null, empty, or whitespace.
- ///
- /// The target string, which should be checked against being null or empty.
- /// Name of the parameter.
- /// is null.
- /// is empty or contains only blanks.
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void NotNullOrWhiteSpace(string value, string parameterName)
- {
- if (value is null)
- {
- ThrowArgumentNullException(parameterName);
- }
-
- if (string.IsNullOrWhiteSpace(value))
- {
- ThrowArgumentException("Must not be empty or whitespace.", parameterName);
- }
- }
-
- ///
- /// Ensures that the specified value is less than a maximum value.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void MustBeLessThan(TValue value, TValue max, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(max) >= 0)
- {
- ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be less than {max}.");
- }
- }
-
- ///
- /// Verifies that the specified value is less than or equal to a maximum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is greater than the maximum value.
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void MustBeLessThanOrEqualTo(TValue value, TValue max, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(max) > 0)
- {
- ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be less than or equal to {max}.");
- }
- }
-
- ///
- /// Verifies that the specified value is greater than a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void MustBeGreaterThan(TValue value, TValue min, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(min) <= 0)
- {
- ThrowArgumentOutOfRangeException(
- parameterName,
- $"Value {value} must be greater than {min}.");
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value
- /// and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is less than the minimum value.
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void MustBeGreaterThanOrEqualTo(TValue value, TValue min, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(min) < 0)
- {
- ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min}.");
- }
- }
-
- ///
- /// Verifies that the specified value is greater than or equal to a minimum value and less than
- /// or equal to a maximum value and throws an exception if it is not.
- ///
- /// The target value, which should be validated.
- /// The minimum value.
- /// The maximum value.
- /// The name of the parameter that is to be checked.
- /// The type of the value.
- ///
- /// is less than the minimum value of greater than the maximum value.
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void MustBeBetweenOrEqualTo(TValue value, TValue min, TValue max, string parameterName)
- where TValue : IComparable
- {
- if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0)
- {
- ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min} and less than or equal to {max}.");
- }
- }
-
- ///
- /// 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
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void IsTrue(bool target, string parameterName, string message)
- {
- if (!target)
- {
- ThrowArgumentException(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
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void IsFalse(bool target, string parameterName, string message)
- {
- if (target)
- {
- ThrowArgumentException(message, parameterName);
- }
- }
-
- ///
- /// Verifies, that the `source` span has the length of 'minLength', or longer.
- ///
- /// The element type of the spans
- /// The source span.
- /// The minimum length.
- /// The name of the parameter that is to be checked.
- ///
- /// has less than items
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void MustBeSizedAtLeast(ReadOnlySpan source, int minLength, string parameterName)
- {
- if (source.Length < minLength)
- {
- ThrowArgumentException($"Span-s must be at least of length {minLength}!", parameterName);
- }
- }
-
- ///
- /// Verifies that the 'destination' span is not shorter than 'source'.
- ///
- /// The source element type
- /// The destination element type
- /// The source span
- /// The destination span
- /// The name of the argument for 'destination'
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void DestinationShouldNotBeTooShort(
- ReadOnlySpan source,
- Span destination,
- string destinationParamName)
- {
- if (destination.Length < source.Length)
- {
- ThrowArgumentException("Destination span is too short!", destinationParamName);
- }
- }
-
- ///
- /// Verifies that the 'destination' span is not shorter than 'source'.
- ///
- /// The source element type
- /// The destination element type
- /// The source span
- /// The destination span
- /// The name of the argument for 'destination'
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void DestinationShouldNotBeTooShort(
- Span source,
- Span destination,
- string destinationParamName)
- {
- if (destination.Length < source.Length)
- {
- ThrowArgumentException("Destination span is too short!", destinationParamName);
- }
- }
-
- ///
- /// Verifies, that the `source` 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.
- ///
- /// has less than items
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static void MustBeSizedAtLeast(Span source, int minLength, string parameterName)
- {
- if (source.Length < minLength)
- {
- ThrowArgumentException($"Span-s must be at least of length {minLength}!", parameterName);
- }
- }
-
- [MethodImpl(InliningOptions.ColdPath)]
- private static void ThrowArgumentException(string message, string parameterName)
- {
- throw new ArgumentException(message, parameterName);
- }
-
- [MethodImpl(InliningOptions.ColdPath)]
- private static void ThrowArgumentOutOfRangeException(string parameterName, string message)
- {
- throw new ArgumentOutOfRangeException(parameterName, message);
- }
-
- [MethodImpl(InliningOptions.ColdPath)]
- private static void ThrowArgumentNullException(string parameterName)
- {
- throw new ArgumentNullException(parameterName);
- }
- }
-}
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index 8dff3b9779..86b0848663 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -19,6 +19,15 @@
SixLabors.ImageSharp
+
+
+ $(DefineConstants);SUPPORTS_MATHF
+
+
+
+ $(DefineConstants);SUPPORTS_HASHCODE
+
+
$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS
@@ -27,6 +36,10 @@
+
+
+
+
True
diff --git a/src/ImageSharp/Memory/BufferArea{T}.cs b/src/ImageSharp/Memory/BufferArea{T}.cs
index f71a281390..38f0b8129d 100644
--- a/src/ImageSharp/Memory/BufferArea{T}.cs
+++ b/src/ImageSharp/Memory/BufferArea{T}.cs
@@ -23,10 +23,10 @@ internal readonly struct BufferArea
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public BufferArea(Buffer2D destinationBuffer, Rectangle rectangle)
{
- ImageSharp.DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.X, 0, nameof(rectangle));
- ImageSharp.DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.Y, 0, nameof(rectangle));
- ImageSharp.DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, destinationBuffer.Width, nameof(rectangle));
- ImageSharp.DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, destinationBuffer.Height, nameof(rectangle));
+ DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.X, 0, nameof(rectangle));
+ DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.Y, 0, nameof(rectangle));
+ DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, destinationBuffer.Width, nameof(rectangle));
+ DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, destinationBuffer.Height, nameof(rectangle));
this.DestinationBuffer = destinationBuffer;
this.Rectangle = rectangle;
@@ -122,8 +122,8 @@ public BufferArea GetSubArea(int x, int y, int width, int height)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public BufferArea GetSubArea(Rectangle rectangle)
{
- ImageSharp.DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, this.Rectangle.Width, nameof(rectangle));
- ImageSharp.DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, this.Rectangle.Height, nameof(rectangle));
+ DebugGuard.MustBeLessThanOrEqualTo(rectangle.Width, this.Rectangle.Width, nameof(rectangle));
+ DebugGuard.MustBeLessThanOrEqualTo(rectangle.Height, this.Rectangle.Height, nameof(rectangle));
int x = this.Rectangle.X + rectangle.X;
int y = this.Rectangle.Y + rectangle.Y;
@@ -161,4 +161,4 @@ public void Clear()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/standards b/standards
deleted file mode 160000
index 8b085c0ec4..0000000000
--- a/standards
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 8b085c0ec4fb64797b9965741f7138f8f66a6b44
diff --git a/stylecop.json b/stylecop.json
deleted file mode 100644
index 485ab604a5..0000000000
--- a/stylecop.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
- "settings": {
- "orderingRules": {
- "usingDirectivesPlacement": "outsideNamespace",
- "elementOrder": [
- "kind"
- ]
- },
- "documentationRules": {
- "xmlHeader": false,
- "documentInternalElements": false,
- "copyrightText": "Copyright (c) Six Labors and contributors.\nLicensed under the Apache License, Version 2.0."
- }
- }
-}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Helpers/GuardTests.cs b/tests/ImageSharp.Tests/Helpers/GuardTests.cs
deleted file mode 100644
index 6bccea2c3e..0000000000
--- a/tests/ImageSharp.Tests/Helpers/GuardTests.cs
+++ /dev/null
@@ -1,274 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Diagnostics.CodeAnalysis;
-
-using Xunit;
-// ReSharper disable InconsistentNaming
-
-namespace SixLabors.ImageSharp.Tests.Helpers
-{
- ///
- /// Tests the helper.
- ///
- public class GuardTests
- {
- class Test
- {
- }
-
- [Theory]
- [InlineData(0, 0)]
- [InlineData(0, 1)]
- [InlineData(0, 42)]
- [InlineData(1, 1)]
- [InlineData(10, 42)]
- [InlineData(42, 42)]
- public void DestinationShouldNotBeTooShort_WhenOk(int sourceLength, int destLength)
- {
- ReadOnlySpan source = new int[sourceLength];
- Span dest = new float[destLength];
-
- Guard.DestinationShouldNotBeTooShort(source, dest, nameof(dest));
- }
-
- [Theory]
- [InlineData(1, 0)]
- [InlineData(42, 41)]
- public void DestinationShouldNotBeTooShort_WhenThrows(int sourceLength, int destLength)
- {
- Assert.ThrowsAny(
- () =>
- {
- ReadOnlySpan source = new int[sourceLength];
- Span dest = new float[destLength];
- Guard.DestinationShouldNotBeTooShort(source, dest, nameof(dest));
- });
- }
-
- ///
- /// Tests that the method throws when the argument is null.
- ///
- [Fact]
- public void NotNullThrowsWhenArgIsNull()
- {
- Assert.Throws(() => Guard.NotNull((Test)null, "foo"));
- }
-
- ///
- /// Tests that the method throws when the argument name is empty.
- ///
- [Fact]
- public void NotNullThrowsWhenArgNameEmpty()
- {
- Assert.Throws(() => Guard.NotNull((Test)null, string.Empty));
- }
-
- ///
- /// Tests that the method throws when the argument is empty.
- ///
- [Fact]
- [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1122:UseStringEmptyForEmptyStrings", Justification = "Reviewed. Suppression is OK here.")]
- public void NotEmptyOrWhiteSpaceThrowsWhenEmpty()
- {
- Assert.Throws(() => Guard.NotNullOrWhiteSpace("", string.Empty));
- }
-
- ///
- /// Tests that the method throws when the argument is whitespace.
- ///
- [Fact]
- public void NotEmptyOrWhiteSpaceThrowsOnWhitespace()
- {
- Assert.Throws(() => Guard.NotNullOrWhiteSpace(" ", string.Empty));
- }
-
- ///
- /// Tests that the method throws when the argument name is null.
- ///
- [Fact]
- public void NotEmptyOrWhiteSpaceThrowsWhenParameterNameNull()
- {
- Assert.Throws(() => Guard.NotNullOrWhiteSpace(null, null));
- }
-
- ///
- /// Tests that the method throws when the argument is greater.
- ///
- [Fact]
- public void LessThanThrowsWhenArgIsGreater()
- {
- Assert.Throws(() => Guard.MustBeLessThan(1, 0, "foo"));
- }
-
- ///
- /// Tests that the method throws when the argument is equal.
- ///
- [Fact]
- public void LessThanThrowsWhenArgIsEqual()
- {
- Assert.Throws(() => Guard.MustBeLessThan(1, 1, "foo"));
- }
-
- ///
- /// Tests that the method throws when the argument is greater.
- ///
- [Fact]
- public void LessThanOrEqualToThrowsWhenArgIsGreater()
- {
- Assert.Throws(() => Guard.MustBeLessThanOrEqualTo(1, 0, "foo"));
- }
-
- ///
- /// Tests that the method does not throw when the argument
- /// is less.
- ///
- [Fact]
- public void LessThanOrEqualToDoesNotThrowWhenArgIsLess()
- {
- Exception ex = Record.Exception(() => Guard.MustBeLessThanOrEqualTo(0, 1, "foo"));
- Assert.Null(ex);
- }
-
- ///
- /// Tests that the method does not throw when the argument
- /// is equal.
- ///
- [Fact]
- public void LessThanOrEqualToDoesNotThrowWhenArgIsEqual()
- {
- Exception ex = Record.Exception(() => Guard.MustBeLessThanOrEqualTo(1, 1, "foo"));
- Assert.Equal(1, 1);
- Assert.Null(ex);
- }
-
- ///
- /// Tests that the method throws when the argument is greater.
- ///
- [Fact]
- public void GreaterThanThrowsWhenArgIsLess()
- {
- Assert.Throws(() => Guard.MustBeGreaterThan(0, 1, "foo"));
- }
-
- ///
- /// Tests that the method throws when the argument is greater.
- ///
- [Fact]
- public void GreaterThanThrowsWhenArgIsEqual()
- {
- Assert.Throws(() => Guard.MustBeGreaterThan(1, 1, "foo"));
- }
-
- ///
- /// Tests that the method throws when the argument name is greater.
- ///
- [Fact]
- public void GreaterThanOrEqualToThrowsWhenArgIsLess()
- {
- Assert.Throws(() => Guard.MustBeGreaterThanOrEqualTo(0, 1, "foo"));
- }
-
- ///
- /// Tests that the method does not throw when the argument
- /// is less.
- ///
- [Fact]
- public void GreaterThanOrEqualToDoesNotThrowWhenArgIsGreater()
- {
- Exception ex = Record.Exception(() => Guard.MustBeGreaterThanOrEqualTo(1, 0, "foo"));
- Assert.Null(ex);
- }
-
- ///
- /// Tests that the method does not throw when the argument
- /// is equal.
- ///
- [Fact]
- public void GreaterThanOrEqualToDoesNotThrowWhenArgIsEqual()
- {
- Exception ex = Record.Exception(() => Guard.MustBeGreaterThanOrEqualTo(1, 1, "foo"));
- Assert.Equal(1, 1);
- Assert.Null(ex);
- }
-
- ///
- /// Tests that the method throws when the argument is less.
- ///
- [Fact]
- public void BetweenOrEqualToThrowsWhenArgIsLess()
- {
- Assert.Throws(() => Guard.MustBeBetweenOrEqualTo(-2, -1, 1, "foo"));
- }
-
- ///
- /// Tests that the method throws when the argument is greater.
- ///
- [Fact]
- public void BetweenOrEqualToThrowsWhenArgIsGreater()
- {
- Assert.Throws(() => Guard.MustBeBetweenOrEqualTo(2, -1, 1, "foo"));
- }
-
- ///
- /// Tests that the method does not throw when the argument
- /// is equal.
- ///
- [Fact]
- public void BetweenOrEqualToDoesNotThrowWhenArgIsEqual()
- {
- Exception ex = Record.Exception(() => Guard.MustBeBetweenOrEqualTo(1, 1, 1, "foo"));
- Assert.Null(ex);
- }
-
- ///
- /// Tests that the method does not throw when the argument
- /// is equal.
- ///
- [Fact]
- public void BetweenOrEqualToDoesNotThrowWhenArgIsBetween()
- {
- Exception ex = Record.Exception(() => Guard.MustBeBetweenOrEqualTo(0, -1, 1, "foo"));
- Assert.Null(ex);
- }
-
- ///
- /// Tests that the method throws when the argument is false.
- ///
- [Fact]
- public void IsTrueThrowsWhenArgIsFalse()
- {
- Assert.Throws(() => Guard.IsTrue(false, "foo", "message"));
- }
-
- ///
- /// Tests that the method does not throw when the argument is true.
- ///
- [Fact]
- public void IsTrueDoesThrowsWhenArgIsTrue()
- {
- Exception ex = Record.Exception(() => Guard.IsTrue(true, "foo", "message"));
- Assert.Null(ex);
- }
-
- ///
- /// Tests that the method throws when the argument is true.
- ///
- [Fact]
- public void IsFalseThrowsWhenArgIsFalse()
- {
- Assert.Throws(() => Guard.IsFalse(true, "foo", "message"));
- }
-
- ///
- /// Tests that the method does not throw when the argument is false.
- ///
- [Fact]
- public void IsFalseDoesThrowsWhenArgIsTrue()
- {
- Exception ex = Record.Exception(() => Guard.IsFalse(false, "foo", "message"));
- Assert.Null(ex);
- }
- }
-}
\ No newline at end of file