Exemplo n.º 1
0
        public void Operators(string xText, string operatorText, string yText, bool expected)
        {
            var x = LanguageTag.Parse(xText);
            var y = LanguageTag.Parse(yText);

            switch (operatorText)
            {
            case ">=":
                Assert.That(x >= y, Is.EqualTo(expected));
                break;

            case "<=":
                Assert.That(x <= y, Is.EqualTo(expected));
                break;

            case "==":
                Assert.That(x == y, Is.EqualTo(expected));
                break;

            case "!=":
                Assert.That(x != y, Is.EqualTo(expected));
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 2
0
        public void Included(string x, string y, bool expected)
        {
            var xTag = LanguageTag.Parse(x);
            var yTag = LanguageTag.Parse(y);

            Assert.That(xTag.Included(yTag), Is.EqualTo(expected));
        }
Exemplo n.º 3
0
        public void Constructor_Pr()
        {
            var tag      = new LanguageTag(new PrivateUseSubtags("aaa"));
            var expected = LanguageTag.Parse("x-aaa");

            Assert.That(tag, Is.EqualTo(expected));
        }
Exemplo n.º 4
0
        public void VariantCollectionCreate(string tagText)
        {
            var tag      = new LanguageTag(tagText);
            var variants = VariantCollection.Create(tag.Language, tag.Script, tag.Variants);

            Assert.That(variants, Is.EqualTo(tag.Variants));
        }
Exemplo n.º 5
0
 public void VariantCollectionCreate(string tagText, Variant appendVariant)
 {
     Assert.Throws <FormatException>(() =>
     {
         var tag = new LanguageTag(tagText);
         VariantCollection.Create(tag.Language, tag.Script, tag.Variants.Union(new Variant[] { appendVariant }));
     });
 }
Exemplo n.º 6
0
        public void Constructor_LangReg()
        {
            var tag1     = new LanguageTag(Language.RU, Region.RU);
            var tag2     = new LanguageTag(Language.RU, (Script?)null, Region.RU, new Variant[] {}, new ExtensionSubtag[] {}, new PrivateUseSubtags());
            var expected = LanguageTag.Parse("ru-RU");

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 7
0
        public void Constructor_LangVarExrPr()
        {
            var tag1     = new LanguageTag(Language.RU, new Variant[] { Variant.Petr1708 }, new ExtensionSubtag[] { new ExtensionSubtag('a', "aaa") }, new PrivateUseSubtags("aaa"));
            var tag2     = new LanguageTag(Language.RU, (Script?)null, (Region?)null, new Variant[] { Variant.Petr1708 }, new ExtensionSubtag[] { new ExtensionSubtag('a', "aaa") }, new PrivateUseSubtags("aaa"));
            var expected = LanguageTag.Parse("ru-Petr1708-a-aaa-x-aaa");

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 8
0
        public void Constructor_LangScrRegVarExr()
        {
            var tag1     = new LanguageTag(Language.RU, Script.Latn, Region.RU, new Variant[] { Variant.Petr1708 }, new ExtensionSubtag[] { new ExtensionSubtag('a', "aaa") });
            var tag2     = new LanguageTag(Language.RU, Script.Latn, Region.RU, new Variant[] { Variant.Petr1708 }, new ExtensionSubtag[] { new ExtensionSubtag('a', "aaa") }, new PrivateUseSubtags());
            var expected = LanguageTag.Parse("ru-Latn-RU-Petr1708-a-aaa");

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 9
0
        public void Constructor_LangScrRegPr()
        {
            var tag1     = new LanguageTag(Language.RU, Script.Latn, Region.RU, new PrivateUseSubtags("aaa"));
            var tag2     = new LanguageTag(Language.RU, Script.Latn, Region.RU, new Variant[] {}, new ExtensionSubtag[] {}, new PrivateUseSubtags("aaa"));
            var expected = LanguageTag.Parse("ru-Latn-RU-x-aaa");

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 10
0
        public void Constructor_LangScrVar()
        {
            var tag1     = new LanguageTag(Language.RU, Script.Latn, new Variant[] { Variant.Petr1708 });
            var tag2     = new LanguageTag(Language.RU, Script.Latn, (Region?)null, new Variant[] { Variant.Petr1708 }, new ExtensionSubtag[] {}, new PrivateUseSubtags());
            var expected = LanguageTag.Parse("ru-Latn-Petr1708");

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 11
0
        public void TryParse_Success()
        {
            LanguageTag?tag1 = LanguageTag.TryParse("en-GB");

            LanguageTag tag2;
            var         result = LanguageTag.TryParse("en-GB", out tag2);

            Assert.That(result, Is.True);
            Assert.That(tag1, Is.EqualTo(tag2));
        }
Exemplo n.º 12
0
        public void TryParse_Fail(string text, string expected)
        {
            Assert.That(LanguageTag.TryParse(text).HasValue, Is.False);

            LanguageTag tag;
            var         result = LanguageTag.TryParse(text, out tag);

            Assert.That(result, Is.False);
            Assert.That(tag, Is.EqualTo(LanguageTag.Parse(expected)));
        }
Exemplo n.º 13
0
        public void SimpleParse(string text, Language?langEx, Script?scrEx, Region?regionEx)
        {
            var tag = LanguageTag.Parse(text);

            Assert.That(tag.Language, Is.EqualTo(langEx));
            Assert.That(tag.Script, Is.EqualTo(scrEx));
            Assert.That(tag.Region, Is.EqualTo(regionEx));
            Assert.That(tag.Variants, Is.Empty);
            Assert.That(tag.Extensions, Is.Empty);
            Assert.That(tag.PrivateUse, Is.Empty);
        }
Exemplo n.º 14
0
        public void EqualsAndHashCode()
        {
            var tag1  = LanguageTag.Parse("ru-Latn-RU-Petr1708-a-aaa-x-aaa");
            var tag1c = tag1;

            var tag2 = LanguageTag.Parse("x-bbb");


            Assert.That(tag1, Is.EqualTo(tag1));
            Assert.That(tag1, Is.EqualTo(tag1c));
            Assert.That(tag1.Equals((object)tag1), Is.True);

            Assert.That(tag1, Is.Not.EqualTo(tag2));
            Assert.That(tag1.Equals((object)tag2), Is.False);
            Assert.That(tag1.Equals(null), Is.False);

            Assert.That(tag1.GetHashCode(), Is.EqualTo(tag1.GetHashCode()));
            Assert.That(tag1.GetHashCode(), Is.EqualTo(tag1c.GetHashCode()));
            Assert.That(tag1.GetHashCode(), Is.Not.EqualTo(tag2.GetHashCode()));
        }
Exemplo n.º 15
0
 public void TakeNone(string tagSource, LanguageTag.Field fields)
 {
     Assert.That(LanguageTag.Parse(tagSource).Take(fields), Is.EqualTo(new LanguageTag()));
 }
Exemplo n.º 16
0
 public void Take(string tagSource, LanguageTag.Field fields, string expected)
 {
     Assert.That(LanguageTag.Parse(tagSource).Take(fields), Is.EqualTo(LanguageTag.Parse(expected)));
 }
Exemplo n.º 17
0
        private static bool PrefixEquals(Language?lang, Script?script, IEnumerable <Variant> variants, LanguageTag prefix, LanguageTag.Field checking)
        {
            if (checking.IsSet(LanguageTag.Field.Language) &&
                lang != prefix.Language)
            {
                return(false);
            }

            if (checking.IsSet(LanguageTag.Field.Script) &&
                script != prefix.Script)
            {
                return(false);
            }

            if (checking.IsSet(LanguageTag.Field.Variants) &&
                !variants.IsEquivalent(prefix.Variants))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 18
0
        public void ParseWithExtensions(string text, char[] singletones)
        {
            var tag = LanguageTag.Parse(text);

            Assert.That(tag.Extensions.Select(_ => _.Singleton), Is.EquivalentTo(singletones));
        }
Exemplo n.º 19
0
        public void ParseWithVariants(string text, Variant[] variantsEx)
        {
            var tag = LanguageTag.Parse(text);

            Assert.That(tag.Variants, Is.EquivalentTo(variantsEx));
        }
Exemplo n.º 20
0
        public void DefaultConstructor()
        {
            var tag = new LanguageTag();

            Assert.That(tag.Fields, Is.EqualTo(LanguageTag.Field.None));
        }
Exemplo n.º 21
0
 private static LanguageTag[] PrefixesCreater(Variant v)
 {
     return(v.GetTextPrefixes().Select(_ => LanguageTag.Parse(_)).ToArray());
 }
Exemplo n.º 22
0
 public void ToString(string source, string expected)
 {
     Assert.AreEqual(expected, LanguageTag.Parse(source).ToString());
 }
Exemplo n.º 23
0
 public void GrandfatheredNotSupported(string grandfathered)
 {
     Assert.Throws <NotSupportedException>(() => LanguageTag.Parse(grandfathered));
 }
Exemplo n.º 24
0
 public void Parse_Fail(string text)
 {
     Assert.Throws <FormatException>(() => LanguageTag.Parse(text));
 }