Esempio n. 1
0
        public void Cardinal_Formatting_fr_FR_decimal()
        {
            var formatter = SpellingFormatter.Create(Locale.Create("fr-FR"));
            Assert.AreEqual("moins un", formatter.Format(-1m));
            Assert.AreEqual("zéro", formatter.Format(0m));
            Assert.AreEqual("treize", formatter.Format(13m));
            Assert.AreEqual("dix-neuf", formatter.Format(19m));
            Assert.AreEqual("vingt", formatter.Format(20m));
            Assert.AreEqual("vingt-et-un", formatter.Format(21m));
            Assert.AreEqual("vingt-deux", formatter.Format(22m));
            Assert.AreEqual("soixante-neuf", formatter.Format(69m));
            Assert.AreEqual("soixante-dix-neuf", formatter.Format(79m));
            Assert.AreEqual("quatre-vingt-dix-neuf", formatter.Format(99m));
            Assert.AreEqual("trois cents", formatter.Format(300m));
            Assert.AreEqual("trois cent vingt-et-un", formatter.Format(321m));
            Assert.AreEqual("mille deux cent trente-quatre", formatter.Format(1234m));
            Assert.AreEqual("moins mille deux cent trente-quatre", formatter.Format(-1234m));
            Assert.AreEqual("vingt billiards", formatter.Format(20000000000000000m));

            var sp = Cldr.Instance.CurrentVersion() < new Version(34, 0)
                ? "\u00A0" : "\u202F";
            Assert.AreEqual($"1{sp}000{sp}000{sp}000{sp}000{sp}000{sp}000", formatter.Format(1000000000000000000m));

            Assert.AreEqual("un virgule deux", formatter.Format(1.2m));
            Assert.AreEqual("un virgule zéro deux", formatter.Format(1.02m));
            Assert.AreEqual("un virgule zéro zéro zéro zéro deux", formatter.Format(1.00002m));
        }
Esempio n. 2
0
        public void Cardinal_Formatting_en_NZ_decimal()
        {
            var formatter = SpellingFormatter.Create(Locale.Create("en-NZ"));
            Assert.AreEqual("minus one", formatter.Format(-1m));
            Assert.AreEqual("zero", formatter.Format(0m));
            Assert.AreEqual("thirteen", formatter.Format(13m));
            Assert.AreEqual("twenty", formatter.Format(20m));
            Assert.AreEqual("twenty-one", formatter.Format(21m));
            Assert.AreEqual("three hundred", formatter.Format(300m));
            Assert.AreEqual("three hundred twenty-one", formatter.Format(321m));
            Assert.AreEqual("one thousand two hundred thirty-four", formatter.Format(1234m));
            Assert.AreEqual("minus one thousand two hundred thirty-four", formatter.Format(-1234m));
            Assert.AreEqual("twenty quadrillion", formatter.Format(20000000000000000m));
            Assert.AreEqual("1,000,000,000,000,000,000", formatter.Format(1000000000000000000m));

            Assert.AreEqual("one point two", formatter.Format(1.2m));
            Assert.AreEqual("one point zero two", formatter.Format(1.02m));
            Assert.AreEqual("one point zero zero zero zero two", formatter.Format(1.00002m));
            Assert.AreEqual("one point two", formatter.Format(1.2));
            Assert.AreEqual("one point zero two", formatter.Format(1.02));
            Assert.AreEqual("one point zero zero zero zero two", formatter.Format(1.00002));

            Assert.AreEqual("minus 79,228,162,514,264,337,593,543,950,335", formatter.Format(decimal.MinValue));
            Assert.AreEqual("79,228,162,514,264,337,593,543,950,335", formatter.Format(decimal.MaxValue));
        }
Esempio n. 3
0
        public void Numeric_Systems_Are_Supported()
        {
            var locale    = Locale.Create("zh-u-nu-hanidec");
            var formatter = NumberFormatter.Create(locale);

            Assert.IsNotNull(formatter);
        }
Esempio n. 4
0
        public void Parse_NotAPattern()
        {
            var locale = Locale.Create("en");
            var path   = $"ldml/numbers/decimalFormats[@numberSystem='latn']/decimalFormatLength[@type='long']/decimalFormat";

            ExceptionAssert.Throws <Exception>(() => NumberPattern.Parse(locale.Find(path)));
        }
Esempio n. 5
0
        public void Decimal_Digit_Replacement()
        {
            var locale    = Locale.Create("zh-u-nu-native");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("一二,三四五.六七九", formatter.Format(12345.6789m));
        }
Esempio n. 6
0
        public void Minimum_Grouping_Digits()
        {
            var locale    = Locale.Create("es_419");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("1", formatter.Format(1));
            Assert.AreEqual("12", formatter.Format(12));
            Assert.AreEqual("123", formatter.Format(123));
            Assert.AreEqual("123", formatter.Format(123));
            Assert.AreEqual("1234", formatter.Format(1234));
            Assert.AreEqual("12,345", formatter.Format(12345));
            Assert.AreEqual("123,456", formatter.Format(123456));
            Assert.AreEqual("1,234,567", formatter.Format(1234567));
            Assert.AreEqual("12,345,678", formatter.Format(12345678));
            Assert.AreEqual("123,456,789", formatter.Format(123456789));
            Assert.AreEqual("1,234,567,890", formatter.Format(1234567890));

            locale    = Locale.Create("es");
            formatter = NumberFormatter.Create(locale);
            Assert.AreEqual("1", formatter.Format(1));
            Assert.AreEqual("12", formatter.Format(12));
            Assert.AreEqual("123", formatter.Format(123));
            Assert.AreEqual("123", formatter.Format(123));
            Assert.AreEqual("1234", formatter.Format(1234));
            Assert.AreEqual("12345", formatter.Format(12345));
            Assert.AreEqual("123.456", formatter.Format(123456));
            Assert.AreEqual("1.234.567", formatter.Format(1234567));
            Assert.AreEqual("12.345.678", formatter.Format(12345678));
            Assert.AreEqual("123.456.789", formatter.Format(123456789));
            Assert.AreEqual("1.234.567.890", formatter.Format(1234567890));
        }
Esempio n. 7
0
        public void Decimal_Symbol_Replacement()
        {
            var locale    = Locale.Create("en");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("-123", formatter.Format(-123));
            Assert.AreEqual("0", formatter.Format(0));
            Assert.AreEqual("123", formatter.Format(123));
            Assert.AreEqual("1234", formatter.Format(1234));
            Assert.AreEqual("1234.568", formatter.Format(1234.56789));
            Assert.AreEqual("12,345", formatter.Format(12345));
            Assert.AreEqual("12,345.679", formatter.Format(12345.6789));

            locale    = Locale.Create("fr");
            formatter = NumberFormatter.Create(locale);
            Assert.AreEqual("123", formatter.Format(123));
            Assert.AreEqual("1234", formatter.Format(1234));
            Assert.AreEqual("1234,568", formatter.Format(1234.56789));
            if (Cldr.Instance.CurrentVersion() < new Version(34, 0))
            {
                Assert.AreEqual("12\u00A0345", formatter.Format(12345));
                Assert.AreEqual("12\u00A0345,679", formatter.Format(12345.6789));
            }
            else
            {
                Assert.AreEqual("12\u202F345", formatter.Format(12345));
                Assert.AreEqual("12\u202F345,679", formatter.Format(12345.6789));
            }
        }
Esempio n. 8
0
        public void Algorithmic_Systems_Are_Supported()
        {
            var locale    = Locale.Create("zh-u-nu-cyrl");
            var formatter = NumberFormatter.Create(locale);

            Assert.IsNotNull(formatter);
        }
Esempio n. 9
0
        public void Decimal_Digit_Devanagari()
        {
            var locale    = Locale.Create("hi-u-nu-deva");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("१२३", formatter.Format(123));
        }
Esempio n. 10
0
        public void Decimal_Digit_Thai()
        {
            var locale    = Locale.Create("th-u-nu-thai");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("๑๒๓", formatter.Format(123));
        }
        public void Japan()
        {
            var locale    = Locale.Create("ja-u-nu-jpan");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("百二十三", formatter.Format(123));
        }
        public void Fraction()
        {
            var locale    = Locale.Create("en-u-nu-grek");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("𐆊´.Α´Β´Β´", formatter.Format(0.122m));
        }
        public void Hebrew()
        {
            var locale    = Locale.Create("he-u-nu-hebr");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("קכ״ג", formatter.Format(123));
        }
        public void TraditionalChinese()
        {
            var locale    = Locale.Create("zh-u-nu-hant");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("一百二十三", formatter.Format(123));
        }
Esempio n. 15
0
        public void Currency_Accounting()
        {
            var locale    = Locale.Create("en");
            var formatter = NumberFormatter.Create(locale, new NumberOptions {
                Style = NumberStyle.CurrencyAccounting
            });

            Assert.AreEqual("CA$123,456.79", formatter.Format(123456.789, "CAD"));
            Assert.AreEqual("(CA$123,456.79)", formatter.Format(-123456.789, "CAD"));

            locale    = Locale.Create("fr");
            formatter = NumberFormatter.Create(locale, new NumberOptions {
                Style = NumberStyle.CurrencyAccounting
            });
            if (Cldr.Instance.CurrentVersion() < new Version(34, 0))
            {
                Assert.AreEqual("123\u00A0456,79\u00A0$CA", formatter.Format(123456.789, "CAD"));
                Assert.AreEqual("(123\u00A0456,79\u00A0$CA)", formatter.Format(-123456.789, "CAD"));
            }
            else
            {
                foreach (var ch in formatter.Format(123456.789, "CAD"))
                {
                    Console.WriteLine($"'{ch}' is {((int)ch).ToString("x2")}");
                }
                Assert.AreEqual("123\u202F456,79\u00A0$CA", formatter.Format(123456.789, "CAD"));
                Assert.AreEqual("(123\u202F456,79\u00A0$CA)", formatter.Format(-123456.789, "CAD"));
            }
        }
Esempio n. 16
0
        public void Language_Cache()
        {
            var a = Plural.Create(Locale.Create("en-US"));
            var b = Plural.Create(Locale.Create("en-NZ"));

            Assert.AreSame(a, b);
        }
Esempio n. 17
0
        public void Decimal_Digit_Chinese()
        {
            var locale    = Locale.Create("zh-u-nu-hanidec");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("一二三", formatter.Format(123));
        }
Esempio n. 18
0
        public void Create_From_Locale()
        {
            var locale  = Locale.Create("de");
            var symbols = NumberSymbols.Create(locale);

            Assert.AreEqual(",", symbols.CurrencyDecimal);
            Assert.AreEqual(".", symbols.CurrencyGroup);
            Assert.AreEqual(",", symbols.Decimal);
            Assert.AreEqual("E", symbols.Exponential);
            Assert.AreEqual(".", symbols.Group);
            Assert.AreEqual("∞", symbols.Infinity);
            Assert.AreEqual(";", symbols.List);
            Assert.AreEqual("-", symbols.MinusSign);
            Assert.AreEqual("NaN", symbols.NotANumber);
            Assert.AreEqual("%", symbols.PercentSign);
            Assert.AreEqual("‰", symbols.PerMille);
            Assert.AreEqual("+", symbols.PlusSign);
            Assert.AreEqual("·", symbols.SuperscriptingExponent);

            locale  = Locale.Create("de-AT");
            symbols = NumberSymbols.Create(locale);
            Assert.AreEqual(",", symbols.CurrencyDecimal);
            Assert.AreEqual(".", symbols.CurrencyGroup);
            Assert.AreEqual(",", symbols.Decimal);
            Assert.AreEqual("E", symbols.Exponential);
            Assert.AreEqual("\u00A0", symbols.Group);
            Assert.AreEqual("∞", symbols.Infinity);
            Assert.AreEqual(";", symbols.List);
            Assert.AreEqual("-", symbols.MinusSign);
            Assert.AreEqual("NaN", symbols.NotANumber);
            Assert.AreEqual("%", symbols.PercentSign);
            Assert.AreEqual("‰", symbols.PerMille);
            Assert.AreEqual("+", symbols.PlusSign);
            Assert.AreEqual("·", symbols.SuperscriptingExponent);
        }
Esempio n. 19
0
        public void Category_No_Language_Rules()
        {
            var locale = Locale.Create("zza");
            var plural = Plural.Create(locale);

            Assert.IsNotNull(plural);

            Assert.AreEqual("other", plural.Category(1));
        }
        public void Decimal_Finance()
        {
            var locale    = Locale.Create("zh-TW-u-nu-finance");
            var formatter = NumberFormatter.Create(locale);

            Assert.AreEqual("零", formatter.Format(0m));
            Assert.AreEqual("參拾", formatter.Format(30m));
            Assert.AreEqual("伍仟", formatter.Format(5000m));
        }
Esempio n. 21
0
        public void Currency_Code_Defaults_to_Locale()
        {
            var locale    = Locale.Create("zh");
            var formatter = NumberFormatter.Create(locale, new NumberOptions {
                Style = NumberStyle.CurrencyStandard
            });

            Assert.AreEqual("¥123.00", formatter.Format(123.00));
        }
Esempio n. 22
0
 public void Ordinal_Formatting_fr_FR()
 {
     var formatter = SpellingFormatter.Create(
         Locale.Create("fr-FR"),
         new SpellingOptions { Style = SpellingStyle.Ordinal });
     Assert.AreEqual("unième", formatter.Format(1));
     Assert.AreEqual("dix-huitième", formatter.Format(18));
     Assert.AreEqual("soixante-dix-neuvième", formatter.Format(79));
 }
Esempio n. 23
0
        public void Scientific_Posix()
        {
            var locale    = Locale.Create("en-u-va-posix");
            var formatter = NumberFormatter.Create(locale, new NumberOptions {
                Style = NumberStyle.Scientific
            });

            Assert.AreEqual("1.234568E+003", formatter.Format(1234.56789));
        }
Esempio n. 24
0
        public void Example()
        {
            var en = Plural.Create(Locale.Create("en"));
            var cy = Plural.Create(Locale.Create("cy"));

            for (int i = 0; i <= 10; ++i)
            {
                Console.WriteLine($"| {i} | {en.Category(i)} | {cy.Category(i)} |");
            }
        }
Esempio n. 25
0
        public void Create_From_Locale_Default()
        {
            var en = Locale.Create("en");

            Assert.AreEqual("latn", NumberingSystem.Create(en).Id);

            var ar = Locale.Create("ar");

            Assert.AreEqual("arab", NumberingSystem.Create(ar).Id);
        }
Esempio n. 26
0
        public void Create_From_Locale_Native()
        {
            var hi_default = Locale.Create("hi-IN");

            Assert.AreEqual("latn", NumberingSystem.Create(hi_default).Id);

            var hi_native = Locale.Create("hi-IN-u-nu-native");

            Assert.AreEqual("deva", NumberingSystem.Create(hi_native).Id);
        }
Esempio n. 27
0
        public void Bad_Style()
        {
            var locale    = Locale.Create("en");
            var formatter = NumberFormatter.Create(locale, new NumberOptions
            {
                Style = (NumberStyle)0xbad
            });

            ExceptionAssert.Throws <NotImplementedException>(() => formatter.Format(0));
        }
Esempio n. 28
0
        public void Create_From_Locale_Traditional()
        {
            var ta_default = Locale.Create("ta");

            Assert.AreEqual("latn", NumberingSystem.Create(ta_default).Id);

            var ta_traditional = Locale.Create("ta-u-nu-traditio");

            Assert.AreEqual("taml", NumberingSystem.Create(ta_traditional).Id);
        }
Esempio n. 29
0
        public void Create_From_Locale_Finance()
        {
            var zh_default = Locale.Create("zh");

            Assert.AreEqual("latn", NumberingSystem.Create(zh_default).Id);

            var zh_finance = Locale.Create("zh-u-nu-finance");

            Assert.AreEqual("hansfin", NumberingSystem.Create(zh_finance).Id);
        }
Esempio n. 30
0
        public void Category_en()
        {
            var locale = Locale.Create("en");
            var plural = Plural.Create(locale);

            Assert.IsNotNull(plural);

            Assert.AreEqual("one", plural.Category(1));
            Assert.AreEqual("other", plural.Category(2));
        }