Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions PCAxis.Core.Tests/PCAxis.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
<None Remove="Test_files\Alias_en.txt" />
</ItemGroup>

<ItemGroup>
<Content Include="Test_files\Alias_en.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
Expand Down
16 changes: 16 additions & 0 deletions PCAxis.Core.Tests/PXFileParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using PCAxis.Paxiom.Parsers;
using System.IO;
using System.Text;

namespace PCAxis.Core.Tests;

Expand All @@ -19,4 +21,18 @@ public void ShouldReturnDescription()
Assert.AreEqual("this is the default plugin which reads a classical pc-axis file", description);

}

[TestMethod]
public void GetEncoding_ShouldReadAliasFile()
{
// Arrange
var fixturePath = Path.Combine(AppContext.BaseDirectory, "Test_files", "Alias_en.txt");

// Act
var encoding = PXFileParser.GetEncoding(fixturePath);

// Assert
Assert.IsNotNull(encoding);
Comment thread
JohannesFinsveen marked this conversation as resolved.
Assert.AreEqual(Encoding.Default, encoding);
}
}
1 change: 1 addition & 0 deletions PCAxis.Core.Tests/Test_files/Alias_en.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Environment
6 changes: 3 additions & 3 deletions PCAxis.Core/Parsers/PXFileParser.vb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Namespace PCAxis.Paxiom.Parsers
Dim encoding As System.Text.Encoding = GetEncodingFromCodePage(GetStream())

If encoding Is Nothing Then
GetEncodingFromUde(GetStream, 16000)
encoding = GetEncodingFromUde(GetStream, 16000)
End If

Return encoding
Expand All @@ -68,7 +68,7 @@ Namespace PCAxis.Paxiom.Parsers
Dim encoding As System.Text.Encoding = GetEncodingFromCodePage(New System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))

If encoding Is Nothing Then
GetEncodingFromUde(New System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read), Convert.ToInt32(New System.IO.FileInfo(path).Length))
encoding = GetEncodingFromUde(New System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read), Convert.ToInt32(New System.IO.FileInfo(path).Length))
End If

Return encoding
Expand All @@ -81,7 +81,7 @@ Namespace PCAxis.Paxiom.Parsers
Dim lineCount = 1
Dim nextLine As String = tr.ReadLine()

While lineCount <= 100 And nextLine IsNot Nothing And Not nextLine.ToUpper().StartsWith("DATA=")
While lineCount <= 100 AndAlso nextLine IsNot Nothing AndAlso Not nextLine.ToUpper().StartsWith("DATA=")
If nextLine.ToUpper().StartsWith("CODEPAGE=") Then
nextLine = nextLine.Substring(nextLine.IndexOf("""") + 1)
nextLine = nextLine.Substring(0, nextLine.LastIndexOf(""""))
Expand Down
Loading