Files
sbox-public/engine/Tests/Sandbox.Test.Unit/System/LocalizationTest.cs
Garry Newman d95169d8fa Unit Test Cleanup (#5064)
* Move all unit tests to Engine/Tests
* Fix Margin.EdgeSubtract
* Fix Capsule.Contains
* EnvironmentVariables.Remove if it's null
* Fixed ray trace never returning startedsolid
* Fix HistoryList.Navigate on empty list
* Fix GameObject.WorldPosition accepting NaNs
* Fix flex: initial expanding to the wrong grow/shrink
* Translation.TryConvert shouldn't throw on invalid enum strings
* Skip sound file tests on machines with no audio device
2026-06-12 13:23:50 +01:00

88 lines
2.2 KiB
C#

using Sandbox.Localization;
using System.Collections.Generic;
namespace SystemTests;
[TestClass]
public class LocalizationTest
{
[TestMethod]
public void ParserMultiple()
{
var phrase = new Phrase( "Hello {one} then {two} and the end" );
Assert.AreEqual( "Hello ", phrase.Parts[0] );
Assert.AreEqual( "{one}", phrase.Parts[1] );
Assert.AreEqual( " then ", phrase.Parts[2] );
Assert.AreEqual( "{two}", phrase.Parts[3] );
Assert.AreEqual( " and the end", phrase.Parts[4] );
Assert.AreEqual( phrase.Parts.Length, 5 );
}
[TestMethod]
public void ParserNone()
{
var phrase = new Phrase( "Hello one then two" );
Assert.AreEqual( null, phrase.Parts );
}
[TestMethod]
public void ParserStarting()
{
var phrase = new Phrase( "{one} then" );
Assert.AreEqual( "{one}", phrase.Parts[0] );
Assert.AreEqual( " then", phrase.Parts[1] );
Assert.AreEqual( phrase.Parts.Length, 2 );
}
[TestMethod]
public void ParserEnding()
{
var phrase = new Phrase( "then {two}" );
Assert.AreEqual( "then ", phrase.Parts[0] );
Assert.AreEqual( "{two}", phrase.Parts[1] );
Assert.AreEqual( phrase.Parts.Length, 2 );
}
[TestMethod]
public void ParserStartingEnding()
{
var phrase = new Phrase( "{one} then {two}" );
Assert.AreEqual( "{one}", phrase.Parts[0] );
Assert.AreEqual( " then ", phrase.Parts[1] );
Assert.AreEqual( "{two}", phrase.Parts[2] );
Assert.AreEqual( phrase.Parts.Length, 3 );
}
[TestMethod]
public void BasicTranslation()
{
var lang = new PhraseCollection();
lang.Set( "hello.world", "Hello World!" );
Assert.AreEqual( "Hello World!", lang.GetPhrase( "hello.world" ) );
Assert.AreEqual( "hello", lang.GetPhrase( "hello" ) );
}
[TestMethod]
public void BasicInterpolation()
{
var lang = new PhraseCollection();
lang.Set( "hello.player", "Hello {PlayerName}!" );
var data = new Dictionary<string, object>();
data["PlayerName"] = "Garry";
// With Data
Assert.AreEqual( "Hello Garry!", lang.GetPhrase( "hello.player", data ) );
// With No data
Assert.AreEqual( "Hello {PlayerName}!", lang.GetPhrase( "hello.player" ) );
// With Wrong Data
data.Clear();
Assert.AreEqual( "Hello {PlayerName}!", lang.GetPhrase( "hello.player", data ) );
}
}