From a7d01dde6bb1c4dbd8c906635b00d6de1e2342bb Mon Sep 17 00:00:00 2001 From: miko Date: Sat, 25 May 2024 18:58:20 +0800 Subject: [PATCH] Fix code style for ranges and slices --- code/Binary.Tests/Features/CollectionTests.cs | 6 ++++-- code/Binary.Tests/Features/ConverterThrowTests.cs | 4 ++-- code/Binary.Tests/SpanLike/AdapterTests.cs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/code/Binary.Tests/Features/CollectionTests.cs b/code/Binary.Tests/Features/CollectionTests.cs index 256942ec..56b8fcc4 100644 --- a/code/Binary.Tests/Features/CollectionTests.cs +++ b/code/Binary.Tests/Features/CollectionTests.cs @@ -43,9 +43,10 @@ public void NativeTypeArrayImplementation(T data) var source = Enumerable.Repeat(data, 16).ToArray(); for (var i = 0; i < source.Length; i++) { - var values = source[0..i]; + var values = source.AsSpan(0, i).ToArray(); var buffer = converter.Encode(values); var result = converter.Decode(buffer); + Assert.Equal(i, result.Length); Assert.Equal(values, result); } } @@ -73,9 +74,10 @@ public void CommonTypeArrayImplementation(T data) var source = Enumerable.Repeat(data, 16).ToArray(); for (var i = 0; i < source.Length; i++) { - var values = source[0..i]; + var values = source.AsSpan(0, i).ToArray(); var buffer = converter.Encode(values); var result = converter.Decode(buffer); + Assert.Equal(i, result.Length); Assert.Equal(values, result); } } diff --git a/code/Binary.Tests/Features/ConverterThrowTests.cs b/code/Binary.Tests/Features/ConverterThrowTests.cs index aa0175b6..fa2b0f92 100644 --- a/code/Binary.Tests/Features/ConverterThrowTests.cs +++ b/code/Binary.Tests/Features/ConverterThrowTests.cs @@ -27,7 +27,7 @@ public void DecodeNotEnoughBytes(T data, int length) var converter = this.generator.GetConverter(); Assert.Equal(ConverterTypeName, converter.GetType().Name); var origin = converter.Encode(data); - var buffer = origin[0..length]; + var buffer = origin.AsSpan(0, length).ToArray(); var alpha = Assert.Throws(() => converter.Decode(buffer)); var bravo = Assert.Throws(() => converter.Decode(new ReadOnlySpan(buffer))); Assert.Null(alpha.ParamName); @@ -46,7 +46,7 @@ public void DecodeAutoNotEnoughBytes(T data, int length) var converter = this.generator.GetConverter(); Assert.Equal(ConverterTypeName, converter.GetType().Name); var origin = converter.Encode(data); - var buffer = origin[0..length]; + var buffer = origin.AsSpan(0, length).ToArray(); var error = Assert.Throws(() => { var span = new ReadOnlySpan(buffer); diff --git a/code/Binary.Tests/SpanLike/AdapterTests.cs b/code/Binary.Tests/SpanLike/AdapterTests.cs index 78c18ac6..22d9c26c 100644 --- a/code/Binary.Tests/SpanLike/AdapterTests.cs +++ b/code/Binary.Tests/SpanLike/AdapterTests.cs @@ -114,7 +114,7 @@ private static void TestAllMethodNullOrEmptyData(T? source) [MemberData(nameof(StringData))] public void ArrayAdapterTest(E[] array, int start, int count) { - TestAllMethod(array.AsSpan().Slice(start, count).ToArray(), count, x => x); + TestAllMethod(array.AsSpan(start, count).ToArray(), count, x => x); } [Theory(DisplayName = "Array Adapter Null Or Empty Test")]