private static void TestData(string cultureStr, RuleType type, bool isDecimal, string lower, string?upper, PluralCategory expected) { if (!TryGetCultureInfo(cultureStr, type, out var info)) { return; } // If upper limit exist, we probe the range a bit if (upper != null) { var start = FluentNumber.FromString(lower); var end = FluentNumber.FromString(upper); var midDouble = (end.Value - start.Value) / 2 + start; FluentNumber mid = isDecimal ? midDouble : Convert.ToInt32(Math.Floor(midDouble), CultureInfo.InvariantCulture); var actualStart = GetPluralCategory(info, type, start); Assert.AreEqual(expected, actualStart, $"Failed on start of range: {start}"); var actualEnd = GetPluralCategory(info, type, end); Assert.AreEqual(expected, actualEnd, $"Failed on end of range: {end}"); var actualMid = GetPluralCategory(info, type, mid); Assert.AreEqual(expected, actualMid, $"Failed on middle of range: {mid}"); } else { var value = FluentNumber.FromString(lower); var actual = GetPluralCategory(info, type, value); Assert.AreEqual(expected, actual); } }
public PluralCategory GetPluralForRange(PluralCategory min, PluralCategory max) { if (min == PluralCategory.one && max == PluralCategory.one) { return(PluralCategory.one); } return(PluralCategory.other); }
private void FormatSelect(string value, StringReader reader, StringBuilder output, FormatterParams formatterParams) { if (string.IsNullOrEmpty(value)) { return; } PluralCategory pluralForOrdinal = formatterParams.formatter.pluralRules.GetPluralForOrdinal(int.Parse(value)); int position = reader.position; while (reader.hasNext) { reader.SkipSpaces(); bool num = reader.Read(PluralFormStrings[(int)pluralForOrdinal]); if (!num) { reader.ReadUntil('['); } SubString text = reader.ReadContent('[', ']'); if (num) { Append(text, output, formatterParams, value); return; } } reader.position = position; while (reader.hasNext) { reader.SkipSpaces(); bool num2 = reader.Read("other"); if (!num2) { reader.ReadUntil('['); } SubString text2 = reader.ReadContent('[', ']'); if (num2) { Append(text2, output, formatterParams, value); return; } } throw new TextFormatterException(reader.text, reader.position, "'other' content is not defined"); }
public void TestIndividual(string cultureStr, RuleType type, bool isDecimal, string lower, string?upper, PluralCategory expected) { TestData(cultureStr, type, isDecimal, lower, upper, expected); }
public PluralCategory GetPluralForRange(PluralCategory min, PluralCategory max) { return(PluralCategory.other); }