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(y.IsSubsetOf(x), Is.EqualTo(expected));
                break;

            case "<=":
                Assert.That(x.IsSubsetOf(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 ApplicationException("Invalid test case");
            }
        }
Exemplo n.º 2
0
        public void Constructor_Pr()
        {
            var tag      = new LanguageTag(new ExtensionSubtag('x', "aaa"));
            var expected = LanguageTag.Parse("x-aaa");

            Assert.That(tag, Is.EqualTo(expected));
        }
Exemplo n.º 3
0
        public void Playground()
        {
            var en = Language.EN;           // English language
            var zh = Language.ZH;           // Chinese language

            var latn = Script.Latn;         // Latin script
            var hans = Script.Hans;         // Han (Simplified variant)

            var tw = Region.TW;             // Taiwan, Province of China

            // tag zh-Hans-TW
            var tag1 = new LanguageTag(zh, hans, tw);

            // tag zh-Latn-TW-Pinyin
            var tag2 = new LanguageTag(zh, latn, tw, new [] { Variant.Pinyin });

            // tag en-US-x-twain
            var tag3 = new LanguageTag(en, Region.US, ExtensionSubtag.ForPrivateUse("twain"));

            // tag de-DE-u-co-phonebk
            var tag4 = new LanguageTag(Language.DE, Region.DE, new [] { new ExtensionSubtag('u', "co", "phonebk") });

            var tag5 = LanguageTag.Parse("ru");
            var tag6 = LanguageTag.Parse("zh-Hans-TW");
            var tag7 = LanguageTag.Parse("en-GB-scotland");

            Assert.True(tag1 == tag6);

            // zh-Hans-TW -> zh-Hans
            var tag8 = tag6.Take(LanguageTag.Field.Language | LanguageTag.Field.Script);

            // zh-Hans is subset of zh-Hans-TW
            Assert.True(tag8.IsSubsetOf(tag6));
        }
Exemplo n.º 4
0
        public void IsSubsetOf(string x, string y, bool expected)
        {
            var xTag = LanguageTag.Parse(x);
            var yTag = LanguageTag.Parse(y);

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

            Assert.That(variants, Is.EqualTo(tag.Variants));
        }
Exemplo n.º 6
0
        public void CanBeCreatedFromRemoteFeedBurnerSource()
        {
            #region Constants

            var location = new Uri("http://feeds2.feedburner.com/oreilly/radar/atom");
            var document = XmlElement.Parse(location);
            Assert.IsNotNull(document);

            var          feed          = document.Root as IAtomFeed;
            const string generatorName = "Movable Type Pro 4.21-en";
            const string generatorUri  = "http://www.sixapart.com/movabletype/";

            var entry1ContentLang = LanguageTag.Parse("en");
            var entry1ContentBase = "http://radar.oreilly.com/";
            var entry1ContentType = AtomTextType.html;

            #endregion

            Assert.IsNotNull(feed);
            Assert.IsNotNull(feed.Id);
            Assert.IsNotNull(feed.Title);

            Assert.IsNotNull(feed.Generator);
            Assert.AreEqual(generatorName, feed.Generator.GeneratorName);
            Assert.AreEqual(generatorUri, feed.Generator.Uri.ToString());

            var entryCount = feed.Entries.Count();
            Assert.IsTrue(entryCount > 0);
            Assert.IsNotNull(feed.Entries.First().Content);
            Assert.AreEqual(entry1ContentLang, feed.Entries.First().Content.Lang);
            Assert.AreEqual(entry1ContentBase, feed.Entries.First().Content.BaseId.ToString());
            Assert.AreEqual(entry1ContentType, feed.Entries.First().Content.Type);
            Assert.IsTrue(feed.Links.Count() > 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.º 8
0
 public void VariantCollectionCreate(string tagText, Variant appendVariant)
 {
     Assert.Throws <FormatException>(() =>
     {
         var tag = LanguageTag.Parse(tagText);
         VariantCollection.Create(tag.Language, tag.Script, tag.Variants.Union(new [] { appendVariant }));
     });
 }
Exemplo n.º 9
0
        protected ILanguageTag GetAttributeLanguageTag(string name)
        {
            var s = GetAttributeString(name);

            return(s != null?
                   LanguageTag.Parse(s)
                       : null);
        }
Exemplo n.º 10
0
        public void ParseInvalidTag()
        {
            const string original = "xyz-us-Latn";
            var          tag      = LanguageTag.Parse(original);

            Assert.IsNotNull(tag);
            Assert.AreEqual(Language.Undetermined, tag.PrimaryLanguage);
            Assert.AreEqual(string.Empty, tag.ToString());
        }
Exemplo n.º 11
0
        public static ILanguageTag ToLanguageTag(this object self)
        {
            if (self == null)
            {
                return(LanguageTag.Empty);
            }

            return(LanguageTag.Parse(self.ToString()));
        }
        public void Constructor_LangVarExr()
        {
            var tag1     = new LanguageTag(Language.RU, new Variant[] { Variant.Petr1708 }, new ExtensionSubtag[] { new ExtensionSubtag('a', "aaa") });
            var tag2     = new LanguageTag(Language.RU, (Script?)null, (Region?)null, new Variant[] { Variant.Petr1708 }, new ExtensionSubtag[] { new ExtensionSubtag('a', "aaa") }, new PrivateUseSubtags());
            var expected = LanguageTag.Parse("ru-Petr1708-a-aaa");

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
        public void Constructor_Lang()
        {
            var tag1     = new LanguageTag(Language.RU);
            var tag2     = new LanguageTag(Language.RU, (Script?)null, (Region?)null, new Variant[] {}, new ExtensionSubtag[] {}, new PrivateUseSubtags());
            var expected = LanguageTag.Parse("ru");

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
        public void Constructor_LangScrRegVar()
        {
            var tag1     = new LanguageTag(Language.RU, Script.Latn, Region.RU, new Variant[] { Variant.Petr1708 });
            var tag2     = new LanguageTag(Language.RU, Script.Latn, Region.RU, new Variant[] { Variant.Petr1708 }, new ExtensionSubtag[] {}, new PrivateUseSubtags());
            var expected = LanguageTag.Parse("ru-Latn-RU-Petr1708");

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

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

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

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 18
0
        public void Constructor_LangVarExrPr()
        {
            var tag1     = new LanguageTag(Language.RU, new [] { Variant.Petr1708 }, new [] { new ExtensionSubtag('a', "aaa") }, ExtensionSubtag.ForPrivateUse("aaa"));
            var tag2     = new LanguageTag(Language.RU, null, null, new [] { Variant.Petr1708 }, new [] { new ExtensionSubtag('a', "aaa") }, ExtensionSubtag.ForPrivateUse("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.º 19
0
        public void Constructor_LangScrRegVarExr()
        {
            var tag1     = new LanguageTag(Language.RU, Script.Latn, Region.RU, new [] { Variant.Petr1708 }, new [] { new ExtensionSubtag('a', "aaa") });
            var tag2     = new LanguageTag(Language.RU, Script.Latn, Region.RU, new [] { Variant.Petr1708 }, new [] { new ExtensionSubtag('a', "aaa") }, new ExtensionSubtag());
            var expected = LanguageTag.Parse("ru-Latn-RU-Petr1708-a-aaa");

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

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 21
0
        public void Constructor_LangExr()
        {
            var tag1     = new LanguageTag(Language.RU, new [] { new ExtensionSubtag('a', "aaa") });
            var tag2     = new LanguageTag(Language.RU, null, null, new Variant[] {}, new [] { new ExtensionSubtag('a', "aaa") }, new ExtensionSubtag());
            var expected = LanguageTag.Parse("ru-a-aaa");

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

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 23
0
        public void Constructor_LangPr()
        {
            var tag1     = new LanguageTag(Language.RU, ExtensionSubtag.ForPrivateUse("aaa"));
            var tag2     = new LanguageTag(Language.RU, null, null, new Variant[] {}, new ExtensionSubtag[] {}, ExtensionSubtag.ForPrivateUse("aaa"));
            var expected = LanguageTag.Parse("ru-x-aaa");

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

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

            Assert.That(tag1, Is.EqualTo(expected));
            Assert.That(tag2, Is.EqualTo(expected));
        }
Exemplo n.º 26
0
        public LangAttribute(INode parent, IQualifiedName name, string value)
            : base(parent, name, value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            this.value = LanguageTag.Parse(value);
        }
Exemplo n.º 27
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.º 28
0
        public void ParseLanguageScriptRegionTag()
        {
            const string original = "ja-Hrkt-035";
            var          tag      = LanguageTag.Parse(original);

            Assert.IsNotNull(tag);
            Assert.AreEqual(Language.Japanese, tag.PrimaryLanguage);
            Assert.AreEqual(Script.HiraganaKatakana, tag.Script);
            Assert.AreEqual(Region.SouthEasternAsia, tag.Region);
            Assert.AreEqual(original, tag.ToString());
            Assert.IsNull(tag.Country);
        }
Exemplo n.º 29
0
        public static ILanguageTag GetAttributeLanguageTag(this System.Xml.XmlNode self, string name)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            var attrib = self.FindAttribute(name);

            return(attrib != null?
                   LanguageTag.Parse(attrib.Value)
                       : null);
        }
Exemplo n.º 30
0
        public static ILanguageTag ToXmlLang(this System.Xml.XmlNode self)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            var attrib = self.FindAttribute("xml:lang");

            return((attrib != null && attrib.Value != null) ?
                   LanguageTag.Parse(attrib.Value)
                : null);
        }