using System; using System.Globalization; using Tessera.Text; using UnitTestSharp; namespace Tessera.UnitTests.Text { public class PercentNotationTests : TestFixture { public static CultureInfo CultureWithPattern(int pattern, string symbol = "%") { var culture = (CultureInfo)CultureInfo.InvariantCulture.Clone(); culture.NumberFormat.PercentSymbol = symbol; culture.NumberFormat.PercentPositivePattern = pattern; return culture; } public class EnglishTests : TestFixture { public void WritesThePercentSignAfterTheDigitsWithNoGap() { CheckEqual("%", PercentNotation.English.Sign); CheckEqual("", PercentNotation.English.Gap); CheckFalse(PercentNotation.English.SignFirst); } } public class CtorTests : TestFixture { public void KeepsWhatItIsGiven() { var notation = new PercentNotation("pct", "_", signFirst: true); CheckEqual("pct", notation.Sign); CheckEqual("_", notation.Gap); CheckTrue(notation.SignFirst); } public void ANullSign_Throws() { CheckThrow(typeof(ArgumentNullException)); new PercentNotation(null, "", signFirst: false); } public void ANullGap_Throws() { CheckThrow(typeof(ArgumentNullException)); new PercentNotation("%", null, signFirst: false); } } public class FromCultureTests : TestFixture { public void Pattern0_PutsASpaceAfterTheDigits() { PercentNotation notation = PercentNotation.FromCulture(CultureWithPattern(0)); CheckEqual(" ", notation.Gap); CheckFalse(notation.SignFirst); } public void Pattern1_PutsTheSignRightAfterTheDigits() { PercentNotation notation = PercentNotation.FromCulture(CultureWithPattern(1)); CheckEqual("", notation.Gap); CheckFalse(notation.SignFirst); } public void Pattern2_PutsTheSignRightBeforeTheDigits() { PercentNotation notation = PercentNotation.FromCulture(CultureWithPattern(2)); CheckEqual("", notation.Gap); CheckTrue(notation.SignFirst); } public void Pattern3_PutsASpaceBetweenTheSignAndTheDigits() { PercentNotation notation = PercentNotation.FromCulture(CultureWithPattern(3)); CheckEqual(" ", notation.Gap); CheckTrue(notation.SignFirst); } public void TakesTheCulturesSign() { CheckEqual("pct", PercentNotation.FromCulture(CultureWithPattern(1, "pct")).Sign); } public void ACultureOfNoneNamed_IsTheInvariantOne() { PercentNotation notation = PercentNotation.FromCulture(CultureInfo.InvariantCulture); CheckEqual("%", notation.Sign); } public void ANullCulture_Throws() { CheckThrow(typeof(ArgumentNullException)); PercentNotation.FromCulture(null); } } } }