summaryrefslogtreecommitdiff
path: root/src/SMAPI.Tests/Core/TranslationTests.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-24 13:49:30 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-24 13:49:30 -0500
commita3f21685049cabf2d824c8060dc0b1de47e9449e (patch)
treead9add30e9da2a50e0ea0245f1546b7378f0d282 /src/SMAPI.Tests/Core/TranslationTests.cs
parent6521df7b131924835eb797251c1e956fae0d6e13 (diff)
parent277bf082675b98b95bf6184fe3c7a45b969c7ac2 (diff)
downloadSMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.gz
SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.bz2
SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Tests/Core/TranslationTests.cs')
-rw-r--r--src/SMAPI.Tests/Core/TranslationTests.cs54
1 files changed, 21 insertions, 33 deletions
diff --git a/src/SMAPI.Tests/Core/TranslationTests.cs b/src/SMAPI.Tests/Core/TranslationTests.cs
index 63404a41..457f9fad 100644
--- a/src/SMAPI.Tests/Core/TranslationTests.cs
+++ b/src/SMAPI.Tests/Core/TranslationTests.cs
@@ -2,10 +2,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
+using StardewModdingAPI;
using StardewModdingAPI.Framework.ModHelpers;
using StardewValley;
-namespace StardewModdingAPI.Tests.Core
+namespace SMAPI.Tests.Core
{
/// <summary>Unit tests for <see cref="TranslationHelper"/> and <see cref="Translation"/>.</summary>
[TestFixture]
@@ -31,7 +32,7 @@ namespace StardewModdingAPI.Tests.Core
var data = new Dictionary<string, IDictionary<string, string>>();
// act
- ITranslationHelper helper = new TranslationHelper("ModID", "ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
+ ITranslationHelper helper = new TranslationHelper("ModID", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
Translation translation = helper.Get("key");
Translation[] translationList = helper.GetTranslations()?.ToArray();
@@ -54,7 +55,7 @@ namespace StardewModdingAPI.Tests.Core
// act
var actual = new Dictionary<string, Translation[]>();
- TranslationHelper helper = new TranslationHelper("ModID", "ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
+ TranslationHelper helper = new TranslationHelper("ModID", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
foreach (string locale in expected.Keys)
{
this.AssertSetLocale(helper, locale, LocalizedContentManager.LanguageCode.en);
@@ -78,7 +79,7 @@ namespace StardewModdingAPI.Tests.Core
// act
var actual = new Dictionary<string, Translation[]>();
- TranslationHelper helper = new TranslationHelper("ModID", "ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
+ TranslationHelper helper = new TranslationHelper("ModID", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
foreach (string locale in expected.Keys)
{
this.AssertSetLocale(helper, locale, LocalizedContentManager.LanguageCode.en);
@@ -108,14 +109,14 @@ namespace StardewModdingAPI.Tests.Core
[TestCase(" boop ", ExpectedResult = true)]
public bool Translation_HasValue(string text)
{
- return new Translation("ModName", "pt-BR", "key", text).HasValue();
+ return new Translation("pt-BR", "key", text).HasValue();
}
[Test(Description = "Assert that the translation's ToString method returns the expected text for various inputs.")]
public void Translation_ToString([ValueSource(nameof(TranslationTests.Samples))] string text)
{
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text);
+ Translation translation = new Translation("pt-BR", "key", text);
// assert
if (translation.HasValue())
@@ -128,7 +129,7 @@ namespace StardewModdingAPI.Tests.Core
public void Translation_ImplicitStringConversion([ValueSource(nameof(TranslationTests.Samples))] string text)
{
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text);
+ Translation translation = new Translation("pt-BR", "key", text);
// assert
if (translation.HasValue())
@@ -141,7 +142,7 @@ namespace StardewModdingAPI.Tests.Core
public void Translation_UsePlaceholder([Values(true, false)] bool value, [ValueSource(nameof(TranslationTests.Samples))] string text)
{
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text).UsePlaceholder(value);
+ Translation translation = new Translation("pt-BR", "key", text).UsePlaceholder(value);
// assert
if (translation.HasValue())
@@ -152,24 +153,11 @@ namespace StardewModdingAPI.Tests.Core
Assert.AreEqual(this.GetPlaceholderText("key"), translation.ToString(), "The translation returned an unexpected value given a null or empty input with the placeholder enabled.");
}
- [Test(Description = "Assert that the translation's Assert method throws the expected exception.")]
- public void Translation_Assert([ValueSource(nameof(TranslationTests.Samples))] string text)
- {
- // act
- Translation translation = new Translation("ModName", "pt-BR", "key", text);
-
- // assert
- if (translation.HasValue())
- Assert.That(() => translation.Assert(), Throws.Nothing, "The assert unexpected threw an exception for a valid input.");
- else
- Assert.That(() => translation.Assert(), Throws.Exception.TypeOf<KeyNotFoundException>(), "The assert didn't throw an exception for invalid input.");
- }
-
[Test(Description = "Assert that the translation returns the expected text after setting the default.")]
public void Translation_Default([ValueSource(nameof(TranslationTests.Samples))] string text, [ValueSource(nameof(TranslationTests.Samples))] string @default)
{
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text).Default(@default);
+ Translation translation = new Translation("pt-BR", "key", text).Default(@default);
// assert
if (!string.IsNullOrEmpty(text))
@@ -194,7 +182,7 @@ namespace StardewModdingAPI.Tests.Core
string expected = $"{start} tokens are properly replaced (including {middle} {middle}) {end}";
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", input);
+ Translation translation = new Translation("pt-BR", "key", input);
switch (structure)
{
case "anonymous object":
@@ -235,7 +223,7 @@ namespace StardewModdingAPI.Tests.Core
string value = Guid.NewGuid().ToString("N");
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text).Tokens(new Dictionary<string, object> { [key] = value });
+ Translation translation = new Translation("pt-BR", "key", text).Tokens(new Dictionary<string, object> { [key] = value });
// assert
Assert.AreEqual(value, translation.ToString(), "The translation returned an unexpected value given a valid base text.");
@@ -245,13 +233,13 @@ namespace StardewModdingAPI.Tests.Core
[TestCase("{{value}}", "value")]
[TestCase("{{VaLuE}}", "vAlUe")]
[TestCase("{{VaLuE }}", " vAlUe")]
- public void Translation_Tokens_KeysAreNormalised(string text, string key)
+ public void Translation_Tokens_KeysAreNormalized(string text, string key)
{
// arrange
string value = Guid.NewGuid().ToString("N");
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text).Tokens(new Dictionary<string, object> { [key] = value });
+ Translation translation = new Translation("pt-BR", "key", text).Tokens(new Dictionary<string, object> { [key] = value });
// assert
Assert.AreEqual(value, translation.ToString(), "The translation returned an unexpected value given a valid base text.");
@@ -302,19 +290,19 @@ namespace StardewModdingAPI.Tests.Core
{
["default"] = new[]
{
- new Translation(string.Empty, "default", "key A", "default A"),
- new Translation(string.Empty, "default", "key C", "default C")
+ new Translation("default", "key A", "default A"),
+ new Translation("default", "key C", "default C")
},
["en"] = new[]
{
- new Translation(string.Empty, "en", "key A", "en A"),
- new Translation(string.Empty, "en", "key B", "en B"),
- new Translation(string.Empty, "en", "key C", "default C")
+ new Translation("en", "key A", "en A"),
+ new Translation("en", "key B", "en B"),
+ new Translation("en", "key C", "default C")
},
["zzz"] = new[]
{
- new Translation(string.Empty, "zzz", "key A", "zzz A"),
- new Translation(string.Empty, "zzz", "key C", "default C")
+ new Translation("zzz", "key A", "zzz A"),
+ new Translation("zzz", "key C", "default C")
}
};
expected["en-us"] = expected["en"].ToArray();