Skip to content

Commit

Permalink
Reformat some code
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMoolenaar committed Mar 10, 2024
1 parent 56b847b commit 02851e8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
38 changes: 19 additions & 19 deletions MatroskaLib/MatroskaLib.Test/ByteHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace MatroskaLib.Test;
public class ByteHelperTest
{
public static TheoryData<ulong, List<byte>> TestData1 = new() {
{ 2UL, new () { 0x2 } },
{ 909UL, new () { 0x3, 0x8D } },
{ 1_800_70UL, new () { 0x2, 0xBF, 0x66 } },
{ 2UL, [0x2] },
{ 909UL, [0x3, 0x8D] },
{ 1_800_70UL, [0x2, 0xBF, 0x66] },
};
[Theory, MemberData(nameof(TestData1))]
public void ToBytesTest(ulong value, List<byte> lsBytesExpected)
Expand All @@ -19,10 +19,10 @@ public void ToBytesTest(ulong value, List<byte> lsBytesExpected)
}

public static TheoryData<List<byte>, List<byte>> TestData2 = new() {
{ new() {0x0, 0x0, 0x0, 0x96}, new () { 0x96 } },
{ new() {0x0, 0x0, 0x5, 0x0, 0x9}, new () { 0x5, 0x0, 0x9 } },
{ new() {0x9}, new () { 0x9 } },
{ new() {}, new () { } }
{ [0x0, 0x0, 0x0, 0x96], [0x96] },
{ [0x0, 0x0, 0x5, 0x0, 0x9], [0x5, 0x0, 0x9] },
{ [0x9], [0x9] },
{ [], [] }
};
[Theory, MemberData(nameof(TestData2))]
public void RemoveLeftZeroesTest(List<byte> lsBytes, List<byte> lsBytesExpected)
Expand All @@ -34,34 +34,34 @@ public void RemoveLeftZeroesTest(List<byte> lsBytes, List<byte> lsBytesExpected)

public static IEnumerable<object[]> Data()
{
yield return new object[]
{
yield return
[
new List<byte>{ 0x6B, 0x2D, 0xAE, 0xBB, 0xD7, 0x81, 0x02 },
new List<byte>{ 0x6B, 0x2D, 0xAE, 0xBE, 0xD7, 0x81, 0x02 },
4,
3
};
yield return new object[]
{
];
yield return
[
new List<byte>{ 0x81, 0x02, 0xAE, 0x42, 0x83, 0xD7, 0x81, 0x03 },
new List<byte>{ 0x81, 0x02, 0xAE, 0x42, 0x87, 0xD7, 0x81, 0x03 },
5,
4
};
yield return new object[]
{
];
yield return
[
new List<byte>{ 0x81, 0x02, 0xAE, 0x42, 0x83, 0xD7, 0x81, 0x03 },
new List<byte>{ 0x81, 0x02, 0xAE, 0x42, 0x87, 0xD7, 0x81, 0x03 },
5,
4
};
yield return new object[]
{
];
yield return
[
new List<byte>{ 0x00, 0x00, 0xAE, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x3A, 0xD7, 81 },
new List<byte>{ 0x00, 0x00, 0xAE, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x3D, 0xD7, 81 },
11,
3
};
];
}
[Theory, MemberData(nameof(Data))]

Expand Down
2 changes: 2 additions & 0 deletions MatroskaLib/MatroskaLib.Test/Helpers/MkvValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class MkvValidator
private const string OutputRemoveRegex = @"(^At least one output file must be specified)|(^\[(.*)\] )";
public static void Validate(string filePath)
{
// Validate with ffmpeg
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
Expand All @@ -26,6 +27,7 @@ public static void Validate(string filePath)
throw new Exception("ffmpeg's mkv validation produced errors:" + Environment.NewLine + output);
}

// Validate with mkvalidator
p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
Expand Down
26 changes: 13 additions & 13 deletions MatroskaLib/MatroskaLib.Test/MatroskaLibTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MatroskaLibTest
[InlineData("mkv files/TestFile1_MkvToolNix.mkv")]
public void ReadTestFile1(string file)
{
string[] filePaths = { file };
string[] filePaths = [file];

List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(filePaths);
List<Track> lsTracks = lsMkvFiles[0].tracks;
Expand All @@ -43,12 +43,12 @@ public void ReadTestFile1(string file)
public void WriteTestFile1(string file)
{
File.Copy(file, TestFilePath, true);
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
lsMkvFiles[0].tracks[0].flagDefault = false;
lsMkvFiles[0].tracks[2].flagDefault = false;

MatroskaWriter.WriteMkvFile(lsMkvFiles[0]);
lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
List<Track> lsTracks = lsMkvFiles[0].tracks;

lsTracks.Should().HaveCount(3);
Expand All @@ -62,7 +62,7 @@ public void WriteTestFile1(string file)
[InlineData("mkv files/TestFile2_MkvToolNix.mkv")]
public void ReadTestFile2(string file)
{
string[] filePaths = { file };
string[] filePaths = [file];

List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(filePaths);
List<Track> lsTracks = lsMkvFiles[0].tracks;
Expand All @@ -82,12 +82,12 @@ public void ReadTestFile2(string file)
public void WriteTestFile2(string file)
{
File.Copy(file, TestFilePath, true);
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
lsMkvFiles[0].tracks[1].flagDefault = true;
lsMkvFiles[0].tracks[3].flagDefault = true;

MatroskaWriter.WriteMkvFile(lsMkvFiles[0]);
lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
List<Track> lsTracks = lsMkvFiles[0].tracks;

lsTracks.Should().HaveCount(5);
Expand All @@ -103,7 +103,7 @@ public void WriteTestFile2(string file)
[InlineData("mkv files/TestFile3_HandBrake.mkv")]
public void ReadTestFile3(string file)
{
string[] filePaths = { file };
string[] filePaths = [file];

List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(filePaths);
List<Track> lsTracks = lsMkvFiles[0].tracks;
Expand All @@ -122,12 +122,12 @@ public void ReadTestFile3(string file)
public void WriteTestFile3(string file)
{
File.Copy(file, TestFilePath, true);
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
lsMkvFiles[0].tracks[1].flagDefault = true;
lsMkvFiles[0].tracks[3].flagDefault = true;

MatroskaWriter.WriteMkvFile(lsMkvFiles[0]);
lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
List<Track> lsTracks = lsMkvFiles[0].tracks;

lsTracks.Should().HaveCount(4);
Expand All @@ -143,7 +143,7 @@ public void WriteTestFile3(string file)
[InlineData("mkv files/TestFile5_MkvProEdit.mkv")]
public void ReadTestFile4(string file)
{
string[] filePaths = { file };
string[] filePaths = [file];

List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(filePaths);
List<Track> lsTracks = lsMkvFiles[0].tracks;
Expand All @@ -161,12 +161,12 @@ public void ReadTestFile4(string file)
public void WriteTestFile4(string file)
{
File.Copy(file, TestFilePath, true);
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
lsMkvFiles[0].tracks[0].flagDefault = false;
lsMkvFiles[0].tracks[2].flagDefault = false;

MatroskaWriter.WriteMkvFile(lsMkvFiles[0]);
lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
List<Track> lsTracks = lsMkvFiles[0].tracks;

lsTracks.Should().HaveCount(3);
Expand All @@ -180,7 +180,7 @@ public void WriteTestFile4(string file)
public void FileWithSeekHeadSizeOf2ShouldNotThrow()
{
File.Copy("mkv files/TestFile6_SmallSeekHead.mkv", TestFilePath, true);
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles(new[] { TestFilePath });
List<MkvFile> lsMkvFiles = MatroskaReader.ReadMkvFiles([TestFilePath]);
lsMkvFiles[0].tracks[0].flagDefault = false;

MatroskaWriter.WriteMkvFile(lsMkvFiles[0]);
Expand Down
6 changes: 3 additions & 3 deletions MatroskaLib/MatroskaLib/Types/MkvFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public record MkvFile
var trackOther = other.tracks.ElementAtOrDefault(i);

if (trackOther is null)
return $"Track at index {i} does not exist, expected {track.type}{track.language}.";
return $"Track at index {i} does not exist, expected {track.type} with language {track.language}.";
if (track.number != trackOther.number)
return $"Track number {i} does not match. Expected {track.number}, got {trackOther.number}.";
return $"Track number at index {i} does not match. Expected {track.number}, got {trackOther.number}.";
if (track.language != trackOther.language)
return $"Track language {i} does not match. Expected {track.language}, got {trackOther.language}.";
return $"Track language at index {i} does not match. Expected {track.language}, got {trackOther.language}.";
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion MkvReadCrawler/MkvReadCrawler.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 02851e8

Please sign in to comment.