From d79e517665897e5e850395c6edb622c01c762b67 Mon Sep 17 00:00:00 2001 From: IIHOSHI Yoshinori Date: Sun, 17 Dec 2023 18:50:06 +0900 Subject: [PATCH] Fix to avoid IDE0300 --- .../Models/BitReaderTests.cs | 14 ++++---------- ThScoreFileConverter.Tests/Models/LzssTests.cs | 6 +++--- .../Models/Th06/ChapterTests.cs | 2 +- .../Models/Th06/HeaderTests.cs | 2 +- .../Models/Th07/HeaderTests.cs | 2 +- .../Models/Th075/StatusTests.cs | 2 +- .../Models/Th08/HeaderTests.cs | 2 +- .../Models/Th09/HeaderTests.cs | 2 +- .../Models/Th095/ChapterTests.cs | 2 +- .../Models/Th10/ChapterTests.cs | 2 +- .../Models/Th175/AllScoreDataTests.cs | 2 +- .../Models/ThCryptTests.cs | 17 +++-------------- .../Models/Th125/ShotExReplacer.cs | 6 +++--- .../Models/Th165/HashtagFields.cs | 2 +- 14 files changed, 23 insertions(+), 40 deletions(-) diff --git a/ThScoreFileConverter.Tests/Models/BitReaderTests.cs b/ThScoreFileConverter.Tests/Models/BitReaderTests.cs index 1765e5dac..e79d87e05 100644 --- a/ThScoreFileConverter.Tests/Models/BitReaderTests.cs +++ b/ThScoreFileConverter.Tests/Models/BitReaderTests.cs @@ -36,9 +36,7 @@ public void BitReaderTestUnreadable() [TestMethod] public void ReadBitsTestOneBit() { -#pragma warning disable IDE0230 // Use UTF-8 string literal - using var stream = new MemoryStream(new byte[] { 0b_0101_0011 }); -#pragma warning restore IDE0230 // Use UTF-8 string literal + using var stream = new MemoryStream([0b_0101_0011]); var reader = new BitReader(stream); @@ -56,7 +54,7 @@ public void ReadBitsTestOneBit() [TestMethod] public void ReadBitsTestZeroBit() { - using var stream = new MemoryStream(new byte[] { 0xFF }); + using var stream = new MemoryStream([0xFF]); var reader = new BitReader(stream); Assert.AreEqual(0, reader.ReadBits(0)); @@ -101,9 +99,7 @@ public void ReadBitsTestMultiBytes() [TestMethod] public void ReadBitsTestNegativeNumBits() { -#pragma warning disable IDE0230 // Use UTF-8 string literal - using var stream = new MemoryStream(new byte[] { 0x53 }); -#pragma warning restore IDE0230 // Use UTF-8 string literal + using var stream = new MemoryStream([0x53]); var reader = new BitReader(stream); @@ -133,9 +129,7 @@ public void ReadBitsTestExceededNumBits() [TestMethod] public void ReadBitsTestEndOfStream() { -#pragma warning disable IDE0230 // Use UTF-8 string literal - using var stream = new MemoryStream(new byte[] { 0x53 }); -#pragma warning restore IDE0230 // Use UTF-8 string literal + using var stream = new MemoryStream([0x53]); var reader = new BitReader(stream); diff --git a/ThScoreFileConverter.Tests/Models/LzssTests.cs b/ThScoreFileConverter.Tests/Models/LzssTests.cs index 99fbf6a32..5bd59c6e1 100644 --- a/ThScoreFileConverter.Tests/Models/LzssTests.cs +++ b/ThScoreFileConverter.Tests/Models/LzssTests.cs @@ -17,8 +17,8 @@ public class LzssTests // f <--- offset ---> len> // 0 0_0000_0000_0001 0000 // 0 0_0000_0000_0000 - private readonly byte[] compressed = new byte[] - { + private readonly byte[] compressed = + [ 0b_1010_0000, 0b_1101_1000, 0b_1010_1100, @@ -27,7 +27,7 @@ public class LzssTests 0b_1000_0000, 0b_0000_0000, 0b_0000_0000, - }; + ]; [TestMethod] public void CompressTest() diff --git a/ThScoreFileConverter.Tests/Models/Th06/ChapterTests.cs b/ThScoreFileConverter.Tests/Models/Th06/ChapterTests.cs index 1b1b63091..13cdce098 100644 --- a/ThScoreFileConverter.Tests/Models/Th06/ChapterTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th06/ChapterTests.cs @@ -32,7 +32,7 @@ internal struct Properties signature = "ABCD", size1 = 12, size2 = 34, - data = new byte[] { 0x56, 0x78, 0x9A, 0xBC }, + data = [0x56, 0x78, 0x9A, 0xBC], }; internal static byte[] MakeByteArray(in Properties properties) diff --git a/ThScoreFileConverter.Tests/Models/Th06/HeaderTests.cs b/ThScoreFileConverter.Tests/Models/Th06/HeaderTests.cs index 69fa3f326..a97dfb9fe 100644 --- a/ThScoreFileConverter.Tests/Models/Th06/HeaderTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th06/HeaderTests.cs @@ -21,7 +21,7 @@ internal struct Properties signature = "TH6K", size1 = 12, size2 = 12, - data = new byte[] { 0x10, 0x00, 0x00, 0x00 }, + data = [0x10, 0x00, 0x00, 0x00], }; internal static byte[] MakeByteArray(in Properties properties) diff --git a/ThScoreFileConverter.Tests/Models/Th07/HeaderTests.cs b/ThScoreFileConverter.Tests/Models/Th07/HeaderTests.cs index 95016982d..7583f6b89 100644 --- a/ThScoreFileConverter.Tests/Models/Th07/HeaderTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th07/HeaderTests.cs @@ -22,7 +22,7 @@ internal struct Properties signature = "TH7K", size1 = 12, size2 = 12, - data = new byte[] { 0x10, 0x00, 0x00, 0x00 }, + data = [0x10, 0x00, 0x00, 0x00], }; internal static byte[] MakeByteArray(in Properties properties) diff --git a/ThScoreFileConverter.Tests/Models/Th075/StatusTests.cs b/ThScoreFileConverter.Tests/Models/Th075/StatusTests.cs index 330933962..2a8353043 100644 --- a/ThScoreFileConverter.Tests/Models/Th075/StatusTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th075/StatusTests.cs @@ -29,7 +29,7 @@ public Properties(in Properties properties) internal static Properties ValidProperties { get; } = new Properties() { - encodedLastName = new byte[] { 15, 37, 26, 50, 30, 43, 53, 103 }, + encodedLastName = [15, 37, 26, 50, 30, 43, 53, 103], decodedLastName = "Player1 ", arcadeScores = EnumHelper.Cartesian() .ToDictionary(pair => pair, pair => ((int)pair.First * 100) + (int)pair.Second), diff --git a/ThScoreFileConverter.Tests/Models/Th08/HeaderTests.cs b/ThScoreFileConverter.Tests/Models/Th08/HeaderTests.cs index 794d3ff80..59e3ed785 100644 --- a/ThScoreFileConverter.Tests/Models/Th08/HeaderTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th08/HeaderTests.cs @@ -22,7 +22,7 @@ internal struct Properties signature = "TH8K", size1 = 12, size2 = 12, - data = new byte[] { 0x10, 0x00, 0x00, 0x00 }, + data = [0x10, 0x00, 0x00, 0x00], }; internal static byte[] MakeByteArray(in Properties properties) diff --git a/ThScoreFileConverter.Tests/Models/Th09/HeaderTests.cs b/ThScoreFileConverter.Tests/Models/Th09/HeaderTests.cs index b98b8177c..07a64f5c7 100644 --- a/ThScoreFileConverter.Tests/Models/Th09/HeaderTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th09/HeaderTests.cs @@ -22,7 +22,7 @@ internal struct Properties signature = "TH9K", size1 = 12, size2 = 12, - data = new byte[] { 0x10, 0x00, 0x00, 0x00 }, + data = [0x10, 0x00, 0x00, 0x00], }; internal static byte[] MakeByteArray(in Properties properties) diff --git a/ThScoreFileConverter.Tests/Models/Th095/ChapterTests.cs b/ThScoreFileConverter.Tests/Models/Th095/ChapterTests.cs index 49c48bac3..129d15ffc 100644 --- a/ThScoreFileConverter.Tests/Models/Th095/ChapterTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th095/ChapterTests.cs @@ -35,7 +35,7 @@ internal struct Properties version = 1234, size = 16, checksum = 0xC16CBAA7u, - data = new byte[] { 0x56, 0x78, 0x9A, 0xBC }, + data = [0x56, 0x78, 0x9A, 0xBC], }; internal static byte[] MakeByteArray(in Properties properties) diff --git a/ThScoreFileConverter.Tests/Models/Th10/ChapterTests.cs b/ThScoreFileConverter.Tests/Models/Th10/ChapterTests.cs index 580576a4e..a6ddc8dfb 100644 --- a/ThScoreFileConverter.Tests/Models/Th10/ChapterTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th10/ChapterTests.cs @@ -36,7 +36,7 @@ internal struct Properties version = 1234, checksum = 0xE0u, size = 16, - data = new byte[] { 0x01, 0x23, 0x45, 0x67 }, + data = [0x01, 0x23, 0x45, 0x67], }; internal static byte[] MakeByteArray(in Properties properties) diff --git a/ThScoreFileConverter.Tests/Models/Th175/AllScoreDataTests.cs b/ThScoreFileConverter.Tests/Models/Th175/AllScoreDataTests.cs index ab47f0976..8db321ac9 100644 --- a/ThScoreFileConverter.Tests/Models/Th175/AllScoreDataTests.cs +++ b/ThScoreFileConverter.Tests/Models/Th175/AllScoreDataTests.cs @@ -12,7 +12,7 @@ namespace ThScoreFileConverter.Tests.Models.Th175; [TestClass] public class AllScoreDataTests { - private static readonly byte[] NullChar = new byte[] { 0 }; + private static readonly byte[] NullChar = [0]; private static readonly BindingFlags BindingAttribute = BindingFlags.NonPublic | BindingFlags.Static; private static readonly MethodInfo FromArrayMethodInfo = typeof(AllScoreDataTests).GetMethod(nameof(MakeByteArrayFromArray), BindingAttribute)!; diff --git a/ThScoreFileConverter.Tests/Models/ThCryptTests.cs b/ThScoreFileConverter.Tests/Models/ThCryptTests.cs index d576c7313..58cb6fd5b 100644 --- a/ThScoreFileConverter.Tests/Models/ThCryptTests.cs +++ b/ThScoreFileConverter.Tests/Models/ThCryptTests.cs @@ -8,20 +8,9 @@ namespace ThScoreFileConverter.Tests.Models; [TestClass] public class ThCryptTests { - private readonly byte[] decrypted = new byte[] - { - 0x01, 0x04, 0x09, 0x10, 0x19, 0x24, 0x31, 0x40, - }; - - private readonly byte[] encryptedBySmallBlock = new byte[] - { - 0x02, 0x42, 0x73, 0xAF, 0xA2, 0x32, 0x7B, 0x67, - }; - - private readonly byte[] encryptedByLargeBlock = new byte[] - { - 0x52, 0x62, 0x6A, 0xAA, 0xD3, 0x0F, 0x43, 0x7F, - }; + private readonly byte[] decrypted = [0x01, 0x04, 0x09, 0x10, 0x19, 0x24, 0x31, 0x40]; + private readonly byte[] encryptedBySmallBlock = [0x02, 0x42, 0x73, 0xAF, 0xA2, 0x32, 0x7B, 0x67]; + private readonly byte[] encryptedByLargeBlock = [0x52, 0x62, 0x6A, 0xAA, 0xD3, 0x0F, 0x43, 0x7F]; private const int KEY = 0x12; private const int STEP = 0x34; diff --git a/ThScoreFileConverter/Models/Th125/ShotExReplacer.cs b/ThScoreFileConverter/Models/Th125/ShotExReplacer.cs index 1ddd39cc5..89dee74db 100644 --- a/ThScoreFileConverter/Models/Th125/ShotExReplacer.cs +++ b/ThScoreFileConverter/Models/Th125/ShotExReplacer.cs @@ -84,8 +84,8 @@ private static Detail[] MakeDetailList(IBestShotHeader header, INumberFormatter { Func str = formatter.FormatNumber; - return new Detail[] - { + return + [ new(true, "Base Point {0,9}", str(header.BasePoint)), new(header.Fields.ClearShot, "Clear Shot! {0,9}", StringHelper.Create($"+ {header.ClearShot}")), new(header.Fields.SoloShot, "Solo Shot {0,9}", "+ 100"), @@ -111,7 +111,7 @@ private static Detail[] MakeDetailList(IBestShotHeader header, INumberFormatter new(true, "Angle Bonus {0,9}", StringHelper.Create($"* {header.AngleBonus:F2}")), new(true, string.Empty, string.Empty), new(true, "Result Score {0,9}", str(header.ResultScore)), - }; + ]; } private sealed class Detail diff --git a/ThScoreFileConverter/Models/Th165/HashtagFields.cs b/ThScoreFileConverter/Models/Th165/HashtagFields.cs index f8eaabad4..233c02a3f 100644 --- a/ThScoreFileConverter/Models/Th165/HashtagFields.cs +++ b/ThScoreFileConverter/Models/Th165/HashtagFields.cs @@ -33,7 +33,7 @@ static HashtagFields() public HashtagFields(int data1, int data2, int data3) { - this.data = new[] { new BitVector32(data1), new BitVector32(data2), new BitVector32(data3) }; + this.data = [new BitVector32(data1), new BitVector32(data2), new BitVector32(data3)]; } public IEnumerable Data => this.data?.Select(vector => vector.Data) ?? Enumerable.Empty();