Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
NotOfficer committed Dec 4, 2024
1 parent 1d95be8 commit 70acda2
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 187 deletions.
144 changes: 72 additions & 72 deletions src/Usmap.NET.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,30 @@ public class UncompressedTests : IUsmapTest
[Fact]
public void ParseFromFile()
{
var usmap = new Usmap(FilePath);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(FilePath);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromStream()
{
var usmap = new Usmap(File.OpenRead(FilePath));
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(File.OpenRead(FilePath));
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromBuffer()
{
var usmap = new Usmap(File.ReadAllBytes(FilePath));
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(File.ReadAllBytes(FilePath));
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}
}
Expand All @@ -111,30 +111,30 @@ public class UncompressedV3Tests : IUsmapTest
[Fact]
public void ParseFromFile()
{
var usmap = new Usmap(FilePath);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(FilePath);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromStream()
{
var usmap = new Usmap(File.OpenRead(FilePath));
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(File.OpenRead(FilePath));
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromBuffer()
{
var usmap = new Usmap(File.ReadAllBytes(FilePath));
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(File.ReadAllBytes(FilePath));
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}
}
Expand All @@ -146,30 +146,30 @@ public class BrotliCompressedTests : IUsmapTest
[Fact]
public void ParseFromFile()
{
var usmap = new Usmap(FilePath);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(FilePath);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromStream()
{
var usmap = new Usmap(File.OpenRead(FilePath));
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(File.OpenRead(FilePath));
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromBuffer()
{
var usmap = new Usmap(File.ReadAllBytes(FilePath));
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(File.ReadAllBytes(FilePath));
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}
}
Expand All @@ -181,30 +181,30 @@ public class BrotliCompressedV3Tests : IUsmapTest
[Fact]
public void ParseFromFile()
{
var usmap = new Usmap(FilePath);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(FilePath);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromStream()
{
var usmap = new Usmap(File.OpenRead(FilePath));
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(File.OpenRead(FilePath));
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromBuffer()
{
var usmap = new Usmap(File.ReadAllBytes(FilePath));
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(File.ReadAllBytes(FilePath));
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}
}
Expand All @@ -227,30 +227,30 @@ public async Task InitializeAsync()
[Fact]
public void ParseFromFile()
{
var usmap = new Usmap(FilePath, _options);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(FilePath, _options);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromStream()
{
var usmap = new Usmap(File.OpenRead(FilePath), _options);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(File.OpenRead(FilePath), _options);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromBuffer()
{
var usmap = new Usmap(File.ReadAllBytes(FilePath), _options);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Length);
var usmap = Usmap.Parse(File.ReadAllBytes(FilePath), _options);
Assert.Equal(Constants.ExpectedSchemas, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnums, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNames, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

Expand Down Expand Up @@ -280,30 +280,30 @@ public async Task InitializeAsync()
[Fact]
public void ParseFromFile()
{
var usmap = new Usmap(FilePath, _options);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(FilePath, _options);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromStream()
{
var usmap = new Usmap(File.OpenRead(FilePath), _options);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(File.OpenRead(FilePath), _options);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

[Fact]
public void ParseFromBuffer()
{
var usmap = new Usmap(File.ReadAllBytes(FilePath), _options);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Length);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Length);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Length);
var usmap = Usmap.Parse(File.ReadAllBytes(FilePath), _options);
Assert.Equal(Constants.ExpectedSchemasV3, usmap.Schemas.Count);
Assert.Equal(Constants.ExpectedEnumsV3, usmap.Enums.Count);
Assert.Equal(Constants.ExpectedNamesV3, usmap.Names.Count);
Assert.All(usmap.Names, x => Assert.False(string.IsNullOrEmpty(x)));
}

Expand Down
9 changes: 9 additions & 0 deletions src/Usmap.NET/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#if NET9_0_OR_GREATER
global using UsmapData = System.Span<byte>;
global using UsmapRoData = System.ReadOnlySpan<byte>;
global using UsmapReader = GenericReader.GenericSpanReader;
#else
global using UsmapData = System.Memory<byte>;
global using UsmapRoData = System.ReadOnlyMemory<byte>;
global using UsmapReader = GenericReader.GenericBufferReader;
#endif
Loading

0 comments on commit 70acda2

Please sign in to comment.