Files
Terminal.Gui/Tests/UnitTests/Resources/ResourceManagerTests.cs
Tig 39d4c7dd3d Fixes #3691 - Adds ViewArrangement.Popover (#3852)
* Added Applicaton.Popover.
Refactored FindDeepestView

* Popover prototype

* Testing highlight

* Fixed click outside issue

* Fixed DialogTests

* Fixed click outside issue (agbain)

* Enabled mouse wheel in Bar

* Enabled mouse wheel in Bar

* Progress. Broke arrangement

* Added popover tests.
Fixed a bunch more CM issues related ot unreliable unit tests.
Updated config.json to include Glyphs.

* Can't set ForceDriver to empty in Resources/config.json.

* added BUGBUG

* Made Position/ScreenPosition clear

* Added View.IsInHierarchy tests

* Added Contextmenuv2 scenario.

* Implemented CM2 in TextView

* Removed unneeded CM stuff from testhelpers

* Shortcut API docs

* Fixed keybinding unit tests

* Fixed mouse handling

* Fighting with CM related unit test failures

* Unit tests pass. I think.

* Shortcut code cleanup

* TextView uses new CM2

* Starting on OnSelect etc...

* Starting on OnSelect etc...

* Fixed ContextMenuv2

* ContextMenu is working again.

* Ugh. ANd fixed button api docs

* Fixed DrawHorizontalShadowTransparent (vertical was already fixed).

* Made Scenarios compatible with #nullable enable

* Undid some keybinding stuff

* Fixed stuff

* Sped up unit tests

* Sped up unit tests 2

* Sped up unit tests 3

* Messing with menus

* merged latest v2_develop

* Added more Popover unit tests

* Added more Popover unit tests2

* Fixed positioning bug

* Fixed mouse bug

* Fixed Bar draw issue

* WIP

* merge v2_develop

* CM2 sorta works

* Enabled Bar subclasses to have IDesignable

* Added ViewportSettings.Transparent

* Region -> nullable enable

* Added ViewportSettigs Editor

* merged v2_develop part 2

* merged v2_develop part 3

* WIP: GetViewsUnderMouse

* WIP: More GetViewsUnderMouse work

* Bars works again

* Added unit tests

* CM now works

* MenuItemv2 POC

* SubMenu POC

* CommandNotBound

* More POC

* Optimize Margin to not defer draw if there's no shadow

* Logger cleanup

* Reverted Generic

* Cascading mostly working

* fixed layout bug

* API docs

* API docs

* Fixed cascade

* Events basically work

* code cleanup

* Fixed IsDefault bug;

* Enabled hotkey support

* Made context-menu-like

* Improved usability

* Refactored ApplicationPopover again

* Cleanup

* Menuv2 POC basically complete

* Code Cleanup

* Made menu API simpler

* Fixed Strings bugs

* Got old ContextMenu scenario mostly working

* ContextMenu scenario now works

* ContextMenu fixes

* ContextMenu fixes

* Tons of menu cleanup

* ContextMenu works in TextView

* Fixed unit tes

* Added unit tests

* Fixed tests

* code cleanup

* More code cleanup

* Deep dive

* scenario

* typos

* Demo colorpicker in a Menu

* Added Region tests proving Region is broken in some Union cases

* fixed v2win/net
2025-03-29 11:30:52 -06:00

130 lines
4.7 KiB
C#

#nullable enable
using System.Collections;
using System.Globalization;
using System.Resources;
using Terminal.Gui.Resources;
namespace Terminal.Gui.ResourcesTests;
public class ResourceManagerTests
{
private const string EXISTENT_CULTURE = "pt-PT";
private const string NO_EXISTENT_CULTURE = "de-DE";
private const string NO_EXISTENT_KEY = "blabla";
private const string NO_TRANSLATED_KEY = "fdDeleteTitle";
private const string NO_TRANSLATED_VALUE = "Delete {0}";
private const string TRANSLATED_KEY = "ctxSelectAll";
private const string TRANSLATED_VALUE = "_Selecionar Tudo";
private static readonly string _stringsNoTranslatedKey = Strings.fdDeleteTitle;
private static readonly string _stringsTranslatedKey = Strings.ctxSelectAll;
private static readonly CultureInfo _savedCulture = CultureInfo.CurrentCulture;
private static readonly CultureInfo _savedUICulture = CultureInfo.CurrentUICulture;
[Fact]
public void GetObject_Does_Not_Overflows_If_Key_Does_Not_Exist () { Assert.Null (GlobalResources.GetObject (NO_EXISTENT_KEY, CultureInfo.CurrentCulture)); }
[Fact]
public void GetObject_FallBack_To_Default_For_No_Existent_Culture_File ()
{
CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE);
CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE);
Assert.Equal (NO_TRANSLATED_VALUE, GlobalResources.GetObject (NO_TRANSLATED_KEY, CultureInfo.CurrentCulture));
RestoreCurrentCultures ();
}
[Fact]
public void GetObject_FallBack_To_Default_For_Not_Translated_Existent_Culture_File ()
{
CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE);
CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE);
Assert.Equal (NO_TRANSLATED_VALUE, GlobalResources.GetObject (NO_TRANSLATED_KEY, CultureInfo.CurrentCulture));
RestoreCurrentCultures ();
}
[Fact]
public void GetResourceSet_With_Filter_Does_Not_Overflows_If_Key_Does_Not_Exist ()
{
ResourceSet value = GlobalResources.GetResourceSet (CultureInfo.CurrentCulture, true, true, d => (string)d.Key == NO_EXISTENT_KEY)!;
Assert.NotNull (value);
Assert.Empty (value.Cast<DictionaryEntry> ());
}
[Fact]
public void GetResourceSet_Without_Filter_Does_Not_Overflows_If_Key_Does_Not_Exist ()
{
ResourceSet value = GlobalResources.GetResourceSet (CultureInfo.CurrentCulture, true, true)!;
Assert.NotNull (value);
Assert.NotEmpty (value.Cast<DictionaryEntry> ());
}
[Fact]
public void GetString_Does_Not_Overflows_If_Key_Does_Not_Exist ()
{
Assert.Null (GlobalResources.GetString (NO_EXISTENT_KEY, CultureInfo.CurrentCulture));
}
[Fact]
public void GetString_FallBack_To_Default_For_No_Existent_Culture_File ()
{
CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE);
CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE);
Assert.Equal (NO_TRANSLATED_VALUE, GlobalResources.GetString (NO_TRANSLATED_KEY, CultureInfo.CurrentCulture));
RestoreCurrentCultures ();
}
[Fact]
public void GetString_FallBack_To_Default_For_Not_Translated_Existent_Culture_File ()
{
CultureInfo.CurrentCulture = new (EXISTENT_CULTURE);
CultureInfo.CurrentUICulture = new (EXISTENT_CULTURE);
// This is really already translated
Assert.Equal (TRANSLATED_VALUE, GlobalResources.GetString (TRANSLATED_KEY, CultureInfo.CurrentCulture));
// These aren't already translated
// Calling Strings.fdDeleteBody return always the invariant culture
Assert.Equal (NO_TRANSLATED_VALUE, GlobalResources.GetString (NO_TRANSLATED_KEY, CultureInfo.CurrentCulture));
RestoreCurrentCultures ();
}
[Fact]
public void Strings_Always_FallBack_To_Default_For_No_Existent_Culture_File ()
{
CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE);
CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE);
Assert.Equal (NO_TRANSLATED_VALUE, _stringsNoTranslatedKey);
RestoreCurrentCultures ();
}
[Fact]
public void Strings_Always_FallBack_To_Default_For_Not_Translated_Existent_Culture_File ()
{
CultureInfo.CurrentCulture = new (EXISTENT_CULTURE);
CultureInfo.CurrentUICulture = new (EXISTENT_CULTURE);
// This is really already translated
Assert.Equal (TRANSLATED_VALUE, _stringsTranslatedKey);
// This isn't already translated
Assert.Equal (NO_TRANSLATED_VALUE, _stringsNoTranslatedKey);
RestoreCurrentCultures ();
}
private void RestoreCurrentCultures ()
{
CultureInfo.CurrentCulture = _savedCulture;
CultureInfo.CurrentUICulture = _savedUICulture;
}
}