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"); } }
public void Constructor_Pr() { var tag = new LanguageTag(new ExtensionSubtag('x', "aaa")); var expected = LanguageTag.Parse("x-aaa"); Assert.That(tag, Is.EqualTo(expected)); }
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)); }
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)); }
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)); }
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)); }
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 })); }); }
protected ILanguageTag GetAttributeLanguageTag(string name) { var s = GetAttributeString(name); return(s != null? LanguageTag.Parse(s) : null); }
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()); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
public LangAttribute(INode parent, IQualifiedName name, string value) : base(parent, name, value) { if (value == null) { throw new ArgumentNullException("value"); } this.value = LanguageTag.Parse(value); }
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); }
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); }
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); }
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); }