Skip to content

Commit

Permalink
Fix to avoid IDE0305
Browse files Browse the repository at this point in the history
  • Loading branch information
y-iihoshi committed Dec 17, 2023
1 parent 92ba420 commit 56538ae
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 213 deletions.
3 changes: 1 addition & 2 deletions ThScoreFileConverter.Tests/Models/Th06/HeaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Linq;
using ThScoreFileConverter.Models.Th06;
using ThScoreFileConverter.Tests.UnitTesting;

Expand Down Expand Up @@ -64,7 +63,7 @@ public void HeaderTestInvalidSize1()
{
var properties = ValidProperties;
++properties.size1;
properties.data = properties.data.Concat(new byte[] { default }).ToArray();
properties.data = [.. properties.data, .. new byte[] { default }];

var chapter = TestUtils.Create<Chapter>(MakeByteArray(properties));
_ = Assert.ThrowsException<InvalidDataException>(() => new Header(chapter));
Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter.Tests/Models/Th07/HeaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Linq;
using ThScoreFileConverter.Models.Th07;
using ThScoreFileConverter.Tests.UnitTesting;
using Chapter = ThScoreFileConverter.Models.Th06.Chapter;
Expand Down Expand Up @@ -65,7 +64,7 @@ public void HeaderTestInvalidSize1()
{
var properties = ValidProperties;
++properties.size1;
properties.data = properties.data.Concat(new byte[] { default }).ToArray();
properties.data = [.. properties.data, .. new byte[] { default }];

var chapter = TestUtils.Create<Chapter>(MakeByteArray(properties));
_ = Assert.ThrowsException<InvalidDataException>(() => new Header(chapter));
Expand Down
4 changes: 2 additions & 2 deletions ThScoreFileConverter.Tests/Models/Th075/StatusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal struct Properties

public Properties(in Properties properties)
{
this.encodedLastName = properties.encodedLastName.ToArray();
this.encodedLastName = [.. properties.encodedLastName];
this.decodedLastName = properties.decodedLastName;
this.arcadeScores = properties.arcadeScores.ToDictionary();
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public void ReadFromTestShortenedName()
public void ReadFromTestExceededName()
{
var properties = ValidProperties;
properties.encodedLastName = properties.encodedLastName.Concat(new byte[1] { 1 }).ToArray();
properties.encodedLastName = [.. properties.encodedLastName, .. new byte[] { 1 }];

var status = TestUtils.Create<Status>(MakeByteArray(properties));

Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter.Tests/Models/Th08/HeaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Linq;
using ThScoreFileConverter.Models.Th08;
using ThScoreFileConverter.Tests.UnitTesting;
using Chapter = ThScoreFileConverter.Models.Th06.Chapter;
Expand Down Expand Up @@ -65,7 +64,7 @@ public void HeaderTestInvalidSize1()
{
var properties = ValidProperties;
++properties.size1;
properties.data = properties.data.Concat(new byte[] { default }).ToArray();
properties.data = [.. properties.data, .. new byte[] { default }];

var chapter = TestUtils.Create<Chapter>(MakeByteArray(properties));
_ = Assert.ThrowsException<InvalidDataException>(() => new Header(chapter));
Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter.Tests/Models/Th09/HeaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Linq;
using ThScoreFileConverter.Models.Th09;
using ThScoreFileConverter.Tests.UnitTesting;
using Chapter = ThScoreFileConverter.Models.Th06.Chapter;
Expand Down Expand Up @@ -65,7 +64,7 @@ public void HeaderTestInvalidSize1()
{
var properties = ValidProperties;
++properties.size1;
properties.data = properties.data.Concat(new byte[] { default }).ToArray();
properties.data = [.. properties.data, .. new byte[] { default }];

var chapter = TestUtils.Create<Chapter>(MakeByteArray(properties));
_ = Assert.ThrowsException<InvalidDataException>(() => new Header(chapter));
Expand Down
56 changes: 28 additions & 28 deletions ThScoreFileConverter.Tests/Models/Th135/AllScoreDataTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ThScoreFileConverter.Core.Helpers;
Expand Down Expand Up @@ -48,9 +47,10 @@ internal static Properties GetValidProperties()

internal static byte[] MakeByteArray(in Properties properties)
{
return Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table))
.Concat(SquirrelHelper.MakeByteArray(
return
[
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray(
"story_progress", properties.storyProgress,
"story_clear", properties.storyClearFlags.Select(pair => (int)pair.Value).ToArray(),
"ed_count", properties.endingCount,
Expand All @@ -60,9 +60,9 @@ internal static byte[] MakeByteArray(in Properties properties)
"enable_stage_kokoro", properties.isEnabledStageKokoro,
"enable_mamizou", properties.isPlayableMamizou,
"enable_kokoro", properties.isPlayableKokoro,
"enable_bgm", properties.bgmFlags))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray();
"enable_bgm", properties.bgmFlags),
.. TestUtils.MakeByteArray((int)SQOT.Null),
];
}

internal static void Validate(in Properties expected, in AllScoreData actual)
Expand Down Expand Up @@ -136,11 +136,11 @@ public void ReadFromTestNoTables()
{
var storyProgressValue = 1;

var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("story_progress", storyProgressValue))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("story_progress", storyProgressValue),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(storyProgressValue, allScoreData.StoryProgress);
Assert.AreEqual(0, allScoreData.StoryClearFlags.Count);
Expand All @@ -150,11 +150,11 @@ public void ReadFromTestNoTables()
[TestMethod]
public void ReadFromTestInvalidStoryClear()
{
var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("story_clear", 1))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("story_clear", 1),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.StoryClearFlags.Count);
}
Expand All @@ -167,23 +167,23 @@ static float[] GetInvalidStoryClear()
return [123f];
}

var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("story_clear", GetInvalidStoryClear()))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("story_clear", GetInvalidStoryClear()),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.StoryClearFlags.Count);
}

[TestMethod]
public void ReadFromTestInvalidEnableBgm()
{
var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("enable_bgm", 1))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("enable_bgm", 1),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.BgmFlags.Count);
}
Expand Down
116 changes: 58 additions & 58 deletions ThScoreFileConverter.Tests/Models/Th145/AllScoreDataTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ThScoreFileConverter.Core.Helpers;
Expand Down Expand Up @@ -63,9 +62,10 @@ internal static Properties MakeValidProperties()

internal static byte[] MakeByteArray(in Properties properties)
{
return Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table))
.Concat(SquirrelHelper.MakeByteArray(
return
[
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray(
"story_progress", properties.storyProgress,
"story_clear", properties.storyClearFlags.Select(pair => (int)pair.Value).ToArray(),
"ed_count", properties.endingCount,
Expand All @@ -83,9 +83,9 @@ internal static byte[] MakeByteArray(in Properties properties)
perCharaPair => perCharaPair.Value).ToArray()).ToArray(),
"clear_time", properties.clearTimes.Select(
perLevelPair => perLevelPair.Value.Select(
perCharaPair => perCharaPair.Value).ToArray()).ToArray()))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray();
perCharaPair => perCharaPair.Value).ToArray()).ToArray()),
.. TestUtils.MakeByteArray((int)SQOT.Null),
];
}

internal static void Validate(in Properties expected, in AllScoreData actual)
Expand Down Expand Up @@ -182,11 +182,11 @@ public void ReadFromTestNoTables()
{
var storyProgressValue = 1;

var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("story_progress", storyProgressValue))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("story_progress", storyProgressValue),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(storyProgressValue, allScoreData.StoryProgress);
Assert.AreEqual(0, allScoreData.StoryClearFlags.Count);
Expand All @@ -198,11 +198,11 @@ public void ReadFromTestNoTables()
[TestMethod]
public void ReadFromTestInvalidStoryClear()
{
var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("story_clear", 1))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("story_clear", 1),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.StoryClearFlags.Count);
}
Expand All @@ -215,35 +215,35 @@ static float[] GetInvalidValue()
return [123f];
}

var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("story_clear", GetInvalidValue()))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("story_clear", GetInvalidValue()),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.StoryClearFlags.Count);
}

[TestMethod]
public void ReadFromTestInvalidEnableBgm()
{
var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("enable_bgm", 1))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("enable_bgm", 1),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.BgmFlags.Count);
}

[TestMethod]
public void ReadFromTestInvalidClearRank()
{
var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("clear_rank", 1))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("clear_rank", 1),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.ClearRanks.Count);
}
Expand All @@ -256,11 +256,11 @@ static float[] GetInvalidValue()
return [123f];
}

var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("clear_rank", GetInvalidValue()))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("clear_rank", GetInvalidValue()),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.ClearRanks.Count);
}
Expand All @@ -273,11 +273,11 @@ static float[][] GetInvalidValue()
return [[123f]];
}

var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("clear_rank", GetInvalidValue()))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("clear_rank", GetInvalidValue()),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(1, allScoreData.ClearRanks.Count);
Assert.IsNotNull(allScoreData.ClearRanks.First().Value);
Expand All @@ -287,11 +287,11 @@ static float[][] GetInvalidValue()
[TestMethod]
public void ReadFromTestInvalidClearTime()
{
var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("clear_time", 1))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("clear_time", 1),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.ClearTimes.Count);
}
Expand All @@ -304,11 +304,11 @@ static float[] GetInvalidValue()
return [123f];
}

var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("clear_time", GetInvalidValue()))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("clear_time", GetInvalidValue()),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(0, allScoreData.ClearTimes.Count);
}
Expand All @@ -321,11 +321,11 @@ static float[][] GetInvalidValue()
return [[123f]];
}

var allScoreData = TestUtils.Create<AllScoreData>(Array.Empty<byte>()
// .Concat(TestUtils.MakeByteArray((int)SQOT.Table)
.Concat(SquirrelHelper.MakeByteArray("clear_time", GetInvalidValue()))
.Concat(TestUtils.MakeByteArray((int)SQOT.Null))
.ToArray());
var allScoreData = TestUtils.Create<AllScoreData>([
// .. TestUtils.MakeByteArray((int)SQOT.Table),
.. SquirrelHelper.MakeByteArray("clear_time", GetInvalidValue()),
.. TestUtils.MakeByteArray((int)SQOT.Null),
]);

Assert.AreEqual(1, allScoreData.ClearTimes.Count);
Assert.IsNotNull(allScoreData.ClearTimes.First().Value);
Expand Down
Loading

0 comments on commit 56538ae

Please sign in to comment.