mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-10-16 23:49:19 +02:00
Tell UTF-8 from 1250 without throwing, and decode timetables the same way
The strict decode threw on every 1250 file, hundreds of them per load.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Text;
|
||||
using StarterNG.Infrastructure.Adapters;
|
||||
using StarterNG.Tests.Fakes;
|
||||
@@ -22,6 +23,40 @@ public class LegacyDecodingTests
|
||||
Assert.Equal(Polish, LegacyText.Decode(Encoding.UTF8.GetBytes(Polish)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_byte_order_mark_does_not_stick_to_the_text()
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetPreamble().Concat(Encoding.UTF8.GetBytes("$a\n" + Polish)).ToArray();
|
||||
|
||||
Assert.Equal("$a\n" + Polish, LegacyText.Decode(bytes));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Telling_the_two_apart_does_not_throw()
|
||||
{
|
||||
// Decoding used to try strict UTF-8 and catch the failure: a first-chance
|
||||
// exception for every 1250 file, hundreds of them on a load.
|
||||
int thread = Environment.CurrentManagedThreadId;
|
||||
int thrown = 0;
|
||||
EventHandler<FirstChanceExceptionEventArgs> count = (_, e) =>
|
||||
{
|
||||
if (e.Exception is DecoderFallbackException && Environment.CurrentManagedThreadId == thread)
|
||||
thrown++;
|
||||
};
|
||||
|
||||
AppDomain.CurrentDomain.FirstChanceException += count;
|
||||
try
|
||||
{
|
||||
LegacyText.Decode(LegacyText.CodePage1250.GetBytes(Polish));
|
||||
}
|
||||
finally
|
||||
{
|
||||
AppDomain.CurrentDomain.FirstChanceException -= count;
|
||||
}
|
||||
|
||||
Assert.Equal(0, thrown);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Plain_ascii_reads_the_same_either_way()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user