Example #1
0
        public void EnableScriptCodeDoesNotCrashOnEmptyRegion()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa-x-special" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            Assert.That(model.EnableScriptCode, Is.False);
        }
Example #2
0
        // [TestCase("x-privateusewaytoolong", false)] // libpalaso fix needs to happen
        public void ValidateOtherVariantsWorks(string code, bool expectedResult)
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            Assert.That(model.ValidateOtherVariants(code), Is.EqualTo(expectedResult));
        }
Example #3
0
        public void IsRegionCodeEnabled(string languageCode, bool shouldBeEnabled)
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { languageCode }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            Assert.That(model.EnableRegionCode, Is.EqualTo(shouldBeEnabled));
        }
Example #4
0
        public void ValidateIetfCode_ReturnsExpected(string newCode, bool expectedValue)
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            Assert.That(model.ValidateIetfCode(newCode), Is.EqualTo(expectedValue));
        }
Example #5
0
        public void GetStandardVariants_ListsLanguageSpecificWithVariants()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr-x-extra" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            CollectionAssert.Contains(model.GetStandardVariants().Select(v => v.Name), "Early Modern French");
        }
Example #6
0
        public void GetScriptList_ContainsQaaa()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);
            var scripts   = model.GetScripts();

            Assert.IsTrue(scripts.Any(s => s.IsPrivateUse && s.Code == "Qaaa"));
        }
Example #7
0
        public void StandardVariantChange_SetToNull_Removes_AndUpdatesCode()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "de-DE-fonipa", "fr" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.StandardVariant = null;
            Assert.That(model.Code, Is.EqualTo("de-DE"));
        }
Example #8
0
        public void GetRegionList_ContainsQM()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);
            var regions   = model.GetRegions();

            Assert.IsTrue(regions.Any(r => r.IsPrivateUse && r.Code == "QM"));
        }
Example #9
0
        public void ScriptItemChange_UpdatesCode()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa-Qaaa-x-Kalaba-Kala-extra", "fr" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.Script = new AdvancedScriptRegionVariantModel.ScriptListItem(new ScriptSubtag("Mala", "not Kala"));
            Assert.That(model.Code, Is.EqualTo("qaa-Qaaa-x-Kalaba-Mala-extra"));
        }
Example #10
0
        public void OtherVariantChange_UpdatesCode()
        {
            // Including fonipa sets the StandardVariant
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "de-DE", "fr" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.OtherVariants = "x-special";
            Assert.That(model.Code, Is.EqualTo("de-DE-x-special"));
        }
Example #11
0
        public void SetScriptNameUpdatesModel()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa-Qaaa-x-kal-Kala" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.ScriptName = "Kalabanolized";
            Assert.That(model.ScriptCode, Is.EqualTo("Kala"));
            Assert.That(fwWsModel.CurrentWsSetupModel.CurrentIso15924Script.Name, Is.EqualTo("Kalabanolized"));
        }
Example #12
0
        public void SetRegionUpdatesCodeAndRegionCode()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr-x-special" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.Region = new AdvancedScriptRegionVariantModel.RegionListItem(StandardSubtags.RegisteredRegions.First(s => s.Code == "US"));
            Assert.That(model.RegionCode, Is.EqualTo("US"));
            Assert.That(model.Code, Is.EqualTo("fr-US-x-special"));
        }
Example #13
0
        public void SetScriptUpdatesCodeAndScriptCode()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.Script = new AdvancedScriptRegionVariantModel.ScriptListItem(StandardSubtags.RegisteredScripts.First(s => s.Code == "Arab"));
            Assert.That(model.ScriptCode, Is.EqualTo("Arab"));
            Assert.That(model.Code, Is.EqualTo("fr-Arab"));
        }
Example #14
0
        public void SetCustomRegionCodeToRealCodeDoesNotLoseCustomStatus()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr-QM-x-CT" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.RegionName = "South Texas";
            model.RegionCode = "CM";
            Assert.That(model.RegionName, Is.EqualTo("South Texas"));
            Assert.That(model.Code, Is.EqualTo("fr-QM-x-CM"));
        }
Example #15
0
        public void SetScriptToQaaaFromEmptyWorks()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);
            var scripts   = model.GetScripts();

            model.Script = scripts.First(s => s.Code == "Qaaa");
            Assert.That(model.ScriptCode, Is.EqualTo("Qaaa"));
            Assert.That(model.Script.Code, Is.EqualTo("Qaaa"));
        }
Example #16
0
        public void SetScriptToQaaaDoesNotLoseCustomCodeOrName()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr-Qaaa-x-Cust" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.ScriptName = "SouthernDrawn";
            model.Script     = model.GetScripts().First(r => r.Code == "Qaaa");
            Assert.That(model.ScriptCode, Is.EqualTo("Cust"));
            Assert.That(model.ScriptName, Is.EqualTo("SouthernDrawn"));
            Assert.That(model.Code, Is.EqualTo("fr-Qaaa-x-Cust"));
        }
Example #17
0
        public void SetScriptCodeDoesNotBlankOutScript()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr-Qaaa-QM-x-Cust-CT" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.ScriptName = "CustScr";
            model.Script     = model.GetScripts().First(r => r.Name == "CustScr");
            Assert.That(model.Script.Label, Is.EqualTo("CustScr (Cust)"));
            model.ScriptCode = "Crud";
            Assert.That(model.Script.Label, Is.EqualTo("CustScr (Crud)"));
        }
Example #18
0
        public void SetRegionCodeDoesNotBlankOutRegion()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr-Qaaa-QM-x-Cust-CT" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.RegionName = "CustReg";
            model.Region     = model.GetRegions().First(r => r.Name == "CustReg");
            Assert.That(model.Region.Label, Is.EqualTo("CustReg (CT)"));
            model.RegionCode = "CM";
            Assert.That(model.Region.Label, Is.EqualTo("CustReg (CM)"));
        }
Example #19
0
        public void SetCustomScriptCodeDoesNotLoseCustomName()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa-Qaaa" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            Assert.That(model.ScriptCode, Is.EqualTo("Qaaa"));
            model.ScriptName = "SuperScript";
            Assert.That(model.ScriptName, Is.EqualTo("SuperScript"));
            model.ScriptCode = "Cust";
            Assert.That(model.ScriptName, Is.EqualTo("SuperScript"));
        }
Example #20
0
        public void CodeSetToFullNonSILCustomFillsInAllData()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.Code = "qaa-Qaax-QX-fonipa-x-kal-Kala-KA-extra1-extra2";
            Assert.That(model.ScriptCode, Is.EqualTo("Qaax"));           // Not Qaaa so the Kala is just a custom variant
            Assert.That(model.RegionCode, Is.EqualTo("QX"));             // Not QM so KA is just a custom variant
            Assert.That(model.StandardVariant, Is.EqualTo("fonipa"));
            Assert.That(model.OtherVariants, Is.EqualTo("x-Kala-KA-extra1-extra2"));
        }
Example #21
0
        public void CodeRemovingPUCodesWorks()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "fr-Qaaa-QM-x-Cust-CT" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.RegionName = "CustomRegion";
            Assert.That(model.RegionCode, Is.EqualTo("CT"));
            Assert.That(model.ScriptCode, Is.EqualTo("Cust"));
            model.Code = "fr-Qaaa-QM";
            Assert.That(model.ScriptCode, Is.EqualTo("Qaaa"), "Private use script code was not removed.");
            Assert.That(model.RegionCode, Is.EqualTo("QM"), "Private use region code was not removed.");
        }
Example #22
0
        public void GetStandardVariants_ListsBasics()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            CollectionAssert.AreEquivalent(new[]
            {
                "None", "ALA-LC Romanization, 1997 edition", "International Phonetic Alphabet",
                "Kirshenbaum Phonetic Alphabet", "North American Phonetic Alphabet",
                "Simplified form", "Uralic Phonetic Alphabet", "X-SAMPA transcription"
            },
                                           model.GetStandardVariants().Select(v => v.Name));
        }
Example #23
0
        public void CodeSetToFullSILCustomFillsInAllData()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.Code = "qaa-Qaaa-QM-fonipa-x-kal-Kala-KA-extra1-extra2";
            Assert.That(model.Script.Code, Is.EqualTo("Kala"));
            Assert.That(model.Script.IsPrivateUse, Is.True);
            Assert.That(model.ScriptCode, Is.EqualTo("Kala"));
            Assert.That(model.Region.Code, Is.EqualTo("KA"));
            Assert.That(model.Region.IsPrivateUse, Is.True);
            Assert.That(model.RegionCode, Is.EqualTo("KA"));
            Assert.That(model.StandardVariant, Is.EqualTo("fonipa"));
            Assert.That(model.OtherVariants, Is.EqualTo("x-extra1-extra2"));
        }
Example #24
0
        public void SetCodeToLangOnlyReturnsEmptyScriptRegionVariant()
        {
            var fwWsModel = new FwWritingSystemSetupModel(new TestWSContainer(new[] { "qaa-Qaaa-QM-fonipa-x-Scrp-ST-extra" }, new[] { "en" }), FwWritingSystemSetupModel.ListType.Vernacular);
            var model     = new AdvancedScriptRegionVariantModel(fwWsModel);

            model.Code = "qaa";
            Assert.That(model.ScriptCode, Is.Null);
            Assert.That(model.ScriptName, Is.Null);
            Assert.That(model.Script.Code, Is.Null);
            Assert.That(model.RegionCode, Is.Null);
            Assert.That(model.RegionName, Is.Null);
            Assert.That(model.Region.Code, Is.Null);
            Assert.That(model.StandardVariant, Is.Null);
            Assert.That(model.OtherVariants, Is.Empty);
        }
Example #25
0
 /// <summary/>
 public AdvancedScriptRegionVariantView(AdvancedScriptRegionVariantModel model = null)
 {
     _model = model;
     InitializeComponent();
 }
Example #26
0
        /// <summary/>
        public void BindToModel(AdvancedScriptRegionVariantModel modelCurrentWsSetupModel)
        {
            _specialTypeComboBox.SelectedIndex = 0;
            RemoveAllEventHandlers();

            _model                     = modelCurrentWsSetupModel;
            _abbreviation.Text         = _model.Abbreviation;
            _ietftagTextBox.Text       = _model.Code;
            _regionNameTextBox.Text    = _model.RegionName;
            _regionCodeTextbox.Text    = _model.RegionCode;
            _regionCodeTextbox.Enabled = _regionNameTextBox.Enabled = _model.EnableRegionCode;
            _scriptCodeTextBox.Text    = _model.ScriptCode;
            _scriptCodeTextBox.Enabled = _scriptNameTextbox.Enabled = _model.EnableScriptCode;
            _scriptNameTextbox.Text    = _model.ScriptName;
            _variantsTextBox.Text      = _model.OtherVariants;
            _scriptChooser.Items.Clear();
            var scripts = _model.GetScripts().ToArray();

            foreach (var scriptChoice in scripts)
            {
                _scriptChooser.Items.Add(new ScriptChoiceView(scriptChoice));
            }

            if (_model.Script != null)
            {
                var index = scripts.IndexOf(r => r.Equals(_model.Script));
                _scriptChooser.SelectedIndex = index;
            }

            _regionChooser.Items.Clear();
            var modelRegions = _model.GetRegions().ToArray();

            foreach (var regionChoice in modelRegions)
            {
                _regionChooser.Items.Add(new RegionChoiceView(regionChoice));
            }

            if (_model.Region != null)
            {
                var index = modelRegions.IndexOf(r => r.Equals(_model.Region));
                _regionChooser.SelectedIndex = index;
            }
            _standardVariantCombo.Items.Clear();
            var standardVariants = _model.GetStandardVariants().ToArray();

            foreach (var variant in standardVariants)
            {
                _standardVariantCombo.Items.Add(new VariantChoiceView(variant));
            }

            // _model.StandardVariant can be null in which case we will select 'None'
            var variantIndex = standardVariants.IndexOf(v => v.Code == _model.StandardVariant);

            _standardVariantCombo.SelectedIndex = variantIndex;
            // Clear all error indicators
            _scriptCodeTextBox.BackColor = Color.Empty;
            _variantsTextBox.BackColor   = Color.Empty;
            _regionCodeTextbox.BackColor = Color.Empty;
            _ietftagTextBox.BackColor    = Color.Empty;
            AddAllEventHandlers();
        }