public void IsValidPrivateUseCode_ValidPrivateUseCode_Returns_True() { Assert.That(IetfLanguageTag.IsValidPrivateUseCode("a"), Is.True); Assert.That(IetfLanguageTag.IsValidPrivateUseCode("A"), Is.True); Assert.That(IetfLanguageTag.IsValidPrivateUseCode("1"), Is.True); Assert.That(IetfLanguageTag.IsValidPrivateUseCode("abcdefgh"), Is.True); Assert.That(IetfLanguageTag.IsValidPrivateUseCode("12345678"), Is.True); }
public void IsValidPrivateUseCode_InvalidPrivateUseCode_ReturnsFalse() { Assert.That(IetfLanguageTag.IsValidPrivateUseCode(""), Is.False); Assert.That(IetfLanguageTag.IsValidPrivateUseCode("abcdefghi"), Is.False); Assert.That(IetfLanguageTag.IsValidPrivateUseCode("123456789"), Is.False); }
public void IsValidPrivateUseCode_InvalidPrivateUseCode_ReturnsFalse() { Assert.That(IetfLanguageTag.IsValidPrivateUseCode(""), Is.False); Assert.That(IetfLanguageTag.IsValidPrivateUseCode("abcdefghijklmnop"), Is.False); // temporarily not conforming to standard in the data Assert.That(IetfLanguageTag.IsValidPrivateUseCode("1234567890123456"), Is.False); }
/// <summary> /// Check that the contents of the control are valid. If not, report the error /// to the user and return false. This should prevent the user from closing the /// containing form using OK, but not from cancelling. /// </summary> public bool CheckValid() { CheckDisposed(); string caption = FwCoreDlgControls.kstidError; ScriptSubtag scriptSubtag = ScriptSubtag; // Can't allow a script name without an abbreviation. if (scriptSubtag == null && !string.IsNullOrEmpty(m_scriptName.Text.Trim())) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidMissingScrAbbr, caption); return(false); } if (scriptSubtag != null && scriptSubtag.IsPrivateUse) { if (StandardSubtags.RegisteredScripts.Contains(scriptSubtag.Code)) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidDupScrAbbr, caption); return(false); } if (!IetfLanguageTag.IsValidScriptCode(scriptSubtag.Code)) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidInvalidScrAbbr, caption); return(false); } } RegionSubtag regionSubtag = RegionSubtag; // Can't allow a country name without an abbreviation. if (regionSubtag == null && !string.IsNullOrEmpty(m_regionName.Text.Trim())) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidMissingRgnAbbr, caption); return(false); } if (regionSubtag != null && regionSubtag.IsPrivateUse) { if (StandardSubtags.RegisteredRegions.Contains(regionSubtag.Code)) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidDupRgnAbbr, caption); return(false); } if (!IetfLanguageTag.IsValidRegionCode(regionSubtag.Code)) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidInvalidRgnAbbr, caption); return(false); } } VariantSubtag[] variantSubtags = VariantSubtags.ToArray(); // Can't allow a variant name without an abbreviation. if (string.IsNullOrEmpty(m_variantAbbrev.Text.Trim()) && !string.IsNullOrEmpty(m_variantName.Text.Trim())) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidMissingVarAbbr, caption); return(false); } if (variantSubtags.Length > 0) { foreach (VariantSubtag variantSubtag in variantSubtags) { if (variantSubtag.IsPrivateUse) { if (StandardSubtags.RegisteredVariants.Contains(variantSubtag.Code)) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidDupVarAbbr, caption); return(false); } if (!IetfLanguageTag.IsValidPrivateUseCode(variantSubtag.Code)) { MessageBox.Show(FindForm(), FwCoreDlgControls.kstidInvalidVarAbbr, caption); return(false); } } } List <string> parts = variantSubtags.Select(v => v.Code).ToList(); // If these subtags are private use, the first element of each must also be distinct. if (m_ws.Language.IsPrivateUse) { parts.Add(m_ws.Language.Code.Split('-').First()); } if (scriptSubtag != null && scriptSubtag.IsPrivateUse) { parts.Add(scriptSubtag.Code.Split('-').First()); } if (regionSubtag != null && regionSubtag.IsPrivateUse) { parts.Add(regionSubtag.Code.Split('-').First()); } var uniqueParts = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (string part in parts) { if (uniqueParts.Contains(part)) { MessageBox.Show(FindForm(), String.Format(FwCoreDlgControls.kstidDuplicateParts, part), caption); return(false); } uniqueParts.Add(part); } } return(true); }