using System.Globalization; using Chronos.App.Import; using Chronos.Core.Localization; using Chronos.Testing; using static Chronos.App.Tests.Import.CardPoolTests; using static Chronos.App.Tests.Import.ImportPlansTests; namespace Chronos.App.Tests.Import; /// /// Import texts in a right-to-left language. They switch the process-wide UI language, so the class is serial: in /// parallel it would race with the English assertions of the classes running beside it. /// [Serial] public sealed class ImportLanguageTests { public ImportLanguageTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en")); [Test] public void PathsAndSerialsStayLeftToRightInARightToLeftLanguage() { try { Loc.SetCulture(CultureInfo.GetCultureInfo("he")); var pool = CardPool.Build([Usb with { Label = string.Empty }, CardA], [], @"D:\Shoots\"); Assert.Equal("\u202AG:\\\u202C", pool[1].Title, "a drive root keeps its separator at its end"); Assert.Equal("\u202AD:\\Shoots\\\u202C", pool[2].Title); Assert.Equal("\u202AD:\\Shoots\\\u202C", pool[2].Subtitle); Assert.Contains("\u202A3F2A-9C11\u202C", pool[0].IdentityText); Assert.Equal("EOS_DIGITAL", pool[0].Title, "a label is left to bidi"); } finally { Loc.SetCulture(CultureInfo.GetCultureInfo("en")); } } [Test] public void ARightToLeftLanguageReadsTheSessionTimesWithItsOwnArrow() { var plan = ThreeSessions(); Assert.Contains("→", ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet())[0].TimeText); try { Loc.SetCulture(CultureInfo.GetCultureInfo("he")); var time = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet())[0].TimeText; Assert.Contains("←", time); Assert.False(time.Contains('→'), "a right-to-left reader would see the arrow point back to the start"); var days = ImportPlans.Sessions(OverEightDays(), ImportDestinationKind.Archive, new HashSet())[0].TimeText; Assert.Contains("←", days); Assert.False(days.Contains('→'), "also between two dates"); } finally { Loc.SetCulture(CultureInfo.GetCultureInfo("en")); } } }