示例#1
0
        public void Constructor_LdmlFolderStoreContainsMultipleFilesThatOnLoadDescribeWritingSystemsWithIdenticalRFC5646Tags_Throws()
        {
            using (var environment = new TestEnvironment())
            {
                File.WriteAllText(Path.Combine(environment.TestPath, "de-Zxxx-x-audio.ldml"),
                                  LdmlContentForTests.CurrentVersion("de", WellKnownSubTags.Audio.Script, "",
                                                                     WellKnownSubTags.Audio.PrivateUseSubtag));
                File.WriteAllText(Path.Combine(environment.TestPath, "inconsistent-filename.ldml"),
                                  LdmlContentForTests.CurrentVersion("de", WellKnownSubTags.Audio.Script, "",
                                                                     WellKnownSubTags.Audio.PrivateUseSubtag));

                var repository = new LdmlInFolderWritingSystemRepository(environment.TestPath);
                var problems   = repository.LoadProblems;

                Assert.That(problems.Count, Is.EqualTo(2));
                Assert.That(
                    problems[0].Exception,
                    Is.TypeOf <ApplicationException>().With.Property("Message").
                    ContainsSubstring(String.Format(
                                          @"The writing system file {0} seems to be named inconsistently. It contains the Rfc5646 tag: 'de-Zxxx-x-audio'. The name should have been made consistent with its content upon migration of the writing systems.",
                                          Path.Combine(environment.TestPath, "inconsistent-filename.ldml")
                                          ))
                    );
                Assert.That(
                    problems[1].Exception,
                    Is.TypeOf <ArgumentException>().With.Property("Message").
                    ContainsSubstring("Unable to set writing system 'de-Zxxx-x-audio' because this id already exists. Please change this writing system id before setting it.")
                    );
            }
        }
示例#2
0
            public void WriteVersion0LdmlFile(string language)
            {
                string filePath = Path.Combine(GlobalWritingSystemRepositoryMigrator.LdmlPathVersion0, String.Format("{0}.ldml", language));
                string content  = LdmlContentForTests.Version0(language, "", "", "");

                File.WriteAllText(filePath, content);
            }
示例#3
0
 public void WritingSystemLdmlVerisonGetterGetFileVerison_FileIsVersion3_Returns3()
 {
     using (_environment = new TestEnvironment())
     {
         _environment.WriteContentToWritingSystemLdmlFile(LdmlContentForTests.Version3("en", "", "", ""));
         var versionGetter = new WritingSystemLdmlVersionGetter();
         Assert.That(versionGetter.GetFileVersion(_environment.PathToWritingSystemLdmlFile), Is.EqualTo(3));
     }
 }
示例#4
0
 public void WritingSystemLdmlVersionGetterGetFileVersion_FileIsVersion1_Returns1()
 {
     using (_environment = new TestEnvironment())
     {
         _environment.WriteContentToWritingSystemLdmlFile(LdmlContentForTests.Version1English());
         var versionGetter = new WritingSystemLdmlVersionGetter();
         Assert.AreEqual(1, versionGetter.GetFileVersion(_environment.PathToWritingSystemLdmlFile));
     }
 }
示例#5
0
 public void LoadAllDefinitions_WsIsValidRfc5646TagStartingWithx_IsNotTreatedAsFlexPrivateUseAndThrows()
 {
     using (var environment = new TestEnvironment())
     {
         var ldmlPath = Path.Combine(environment.TestPath, "xh.ldml");
         File.WriteAllText(ldmlPath, LdmlContentForTests.Version0("xh", "", "", ""));
         var repo = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem, WritingSystemCompatibility.Strict);
         //Assert.That(() => new LdmlInFolderWritingSystemRepository(environment.TestPath), Throws.Exception.TypeOf<ApplicationException>());
     }
 }
示例#6
0
 public void SaveDefinition_WritingSystemCameFromValidRfc5646WritingSystemStartingWithX_FileNameIsChanged()
 {
     using (var environment = new TestEnvironment())
     {
         var pathToFlexprivateUseLdml = Path.Combine(environment.TestPath, "x-Zxxx-x-audio.ldml");
         File.WriteAllText(pathToFlexprivateUseLdml, LdmlContentForTests.Version2("xh", "", "", ""));
         environment.Collection = new LdmlInFolderWritingSystemRepository(environment.TestPath);
         Assert.That(File.Exists(Path.Combine(environment.TestPath, "xh.ldml")));
     }
 }
示例#7
0
            public void WriteVersion2LdmlFile(string language)
            {
                string folderPath = Path.Combine(Platform.IsLinux ? GlobalWritingSystemRepositoryMigrator.LdmlPathLinuxVersion2 : _baseFolder.Path, "2");

                Directory.CreateDirectory(folderPath);
                string filePath = Path.Combine(folderPath, String.Format("{0}.ldml", language));
                string content  = LdmlContentForTests.Version2(language, "", "", "");

                File.WriteAllText(filePath, content);
            }
示例#8
0
        public void GetFileVersion_V1_ReturnsBadVersion()
        {
            string xml = LdmlContentForTests.Version1("en", "", "", "");

            using (var file = new TempFile(xml))
            {
                var silLdmlVersion = new SilLdmlVersion();
                int result         = silLdmlVersion.GetFileVersion(file.Path);
                Assert.That(result, Is.EqualTo(SilLdmlVersion.BadVersion));
            }
        }
示例#9
0
        public void GetFileVersion_StandardLdml_LatestVersion()
        {
            string xml = LdmlContentForTests.Version3("en", "Latn", "", "");

            using (var file = new TempFile(xml))
            {
                var silLdmlVersion = new SilLdmlVersion();
                int result         = silLdmlVersion.GetFileVersion(file.Path);
                Assert.That(result, Is.EqualTo(LdmlDataMapper.CurrentLdmlVersion));
            }
        }
示例#10
0
        public void GetFileVersion_SilIdentity_LatestVersion()
        {
            string xml = LdmlContentForTests.Version3Identity("en", "Latn", "", "", "123456", "abcd", "variantName", "US",
                                                              "53d542ba498f40f437f7723e69dcf64dab6c9794");

            using (var file = new TempFile(xml))
            {
                var silLdmlVersion = new SilLdmlVersion();
                int result         = silLdmlVersion.GetFileVersion(file.Path);
                Assert.That(result, Is.EqualTo(LdmlDataMapper.CurrentLdmlVersion));
            }
        }
示例#11
0
        public void Constructor_LdmlFolderStoreContainsInconsistentlyNamedFileDifferingInCaseOnly_HasNoProblem()
        {
            using (var environment = new TestEnvironment())
            {
                File.WriteAllText(Path.Combine(environment.TestPath, "tpi-latn.ldml"),
                                  LdmlContentForTests.CurrentVersion("tpi", "Latn", "", ""));

                var repository = new LdmlInFolderWritingSystemRepository(environment.TestPath);
                var problems   = repository.LoadProblems;
                Assert.That(problems.Count, Is.EqualTo(0));
            }
        }
示例#12
0
        public void LoadAllDefinitions_FilenameIsFlexConformPrivateUseAndDoesNotMatchRfc5646Tag_Migrates()
        {
            using (var environment = new TestEnvironment())
            {
                var ldmlPath = Path.Combine(environment.TestPath, "x-en-Zxxx.ldml");
                File.WriteAllText(ldmlPath, LdmlContentForTests.Version0("x-en", "Zxxx", "", ""));
                var repo = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem, WritingSystemCompatibility.Strict);

                // Now try to load up.
                Assert.That(repo.Get("qaa-Zxxx-x-en").Language, Is.EqualTo("qaa"));
            }
        }
示例#13
0
 public void SaveDefinition_WritingSystemCameFromFlexPrivateUseLdml_FileNameIsRetained()
 {
     using (var environment = new TestEnvironment())
     {
         var pathToFlexprivateUseLdml = Path.Combine(environment.TestPath, "x-Zxxx-x-audio.ldml");
         File.WriteAllText(pathToFlexprivateUseLdml, LdmlContentForTests.Version0("x", "Zxxx", "", "x-audio"));
         environment.Collection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem, WritingSystemCompatibility.Flex7V0Compatible);
         var ws = environment.Collection.Get("x-Zxxx-x-audio");
         environment.Collection.SaveDefinition(ws);
         Assert.That(File.Exists(pathToFlexprivateUseLdml));
     }
 }
示例#14
0
 //This test makes sure that existing Flex private use tags are not changed
 public void CreateNonExistentWritingSystemsFoundInOptionsList_OptionsListFileContainsEntirelyPrivateUseRfcTagThatExistsInRepo_RfcTagIsNotMigrated()
 {
     using (var e = new TestEnvironment("x-blah"))
     {
         e.WriteContentToLdmlFileInWritingSystemFolderWithName("x-blah", LdmlContentForTests.Version0("x-blah", "", "", ""));
         e.CreateLegacyFriendlyWritingSystemRepository();
         e.Helper.CreateNonExistentWritingSystemsFoundInFile();
         Assert.That(File.Exists(e.GetLdmlFileforWs("x-blah")), Is.True);
         Assert.That(File.Exists(e.GetLdmlFileforWs("qaa-x-blah")), Is.False);
         AssertThatXmlIn.File(e.PathToOptionsListFile).HasAtLeastOneMatchForXpath("/optionsList/options/option/name/form[@lang='x-blah']");
         AssertThatXmlIn.File(e.PathToOptionsListFile).HasNoMatchForXpath("/optionsList/options/option/name/form[@lang='qaa-x-blah']");
     }
 }
示例#15
0
 public void Read_ValidLanguageTagStartingWithXButVersion0_Throws()
 {
     using (TempFile version0Ldml = new TempFile())
     {
         using (var writer = new StreamWriter(version0Ldml.Path, false, Encoding.UTF8))
         {
             writer.Write(LdmlContentForTests.Version0("xh", "", "", ""));
         }
         var wsV1    = new WritingSystemDefinitionV1();
         var adaptor = new LdmlAdaptorV1();
         Assert.Throws <ApplicationException>(() => adaptor.Read(version0Ldml.Path, wsV1));
     }
 }
示例#16
0
 public void Set_WritingSystemWasLoadedFromFlexPrivateUseLdmlAndRearranged_DoesNotChangeFileName()
 {
     using (var environment = new TestEnvironment())
     {
         var pathToFlexprivateUseLdml = Path.Combine(environment.TestPath, "x-en-Zxxx-x-audio.ldml");
         File.WriteAllText(pathToFlexprivateUseLdml,
                           LdmlContentForTests.Version0("x-en", "Zxxx", "", "x-audio"));
         environment.Collection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem, WritingSystemCompatibility.Flex7V0Compatible);
         var ws = environment.Collection.Get("x-en-Zxxx-x-audio");
         environment.Collection.Set(ws);
         Assert.That(File.Exists(pathToFlexprivateUseLdml), Is.True);
     }
 }
示例#17
0
 public void MigrateIfNeeded_LdmlV0ContainsIdThatIsNotMigrated_WritingSystemChangeLogDoesNotExist()
 {
     using (var e = new TestEnvironment())
     {
         string writingSystemsPath  = Path.Combine(e.ProjectPath, "WritingSystems");
         string ldmlFilePath        = Path.Combine(writingSystemsPath, "en.ldml");
         string idChangeLogFilePath = Path.Combine(writingSystemsPath, "idchangelog.xml");
         Directory.CreateDirectory(writingSystemsPath);
         File.WriteAllText(ldmlFilePath, LdmlContentForTests.Version0English());
         var migrator = new WritingSystemsMigrator(e.ProjectPath);
         migrator.MigrateIfNecessary();
         // The change log does not exist because no id needed migrating
         Assert.That(File.Exists(idChangeLogFilePath), Is.Not.True);
     }
 }
示例#18
0
        public void MigrateIfNeeded_LdmlV0ContainsIdThatNeedsMigrating_WritingSystemChangeLogUpdated()
        {
            using (var e = new TestEnvironment())
            {
                string writingSystemsPath  = Path.Combine(e.ProjectPath, "WritingSystems");
                string ldmlFilePath        = Path.Combine(writingSystemsPath, "blah.ldml");
                string idChangeLogFilePath = Path.Combine(writingSystemsPath, "idchangelog.xml");
                Directory.CreateDirectory(writingSystemsPath);
                File.WriteAllText(ldmlFilePath, LdmlContentForTests.Version0("blah", "", "", ""));
                var migrator = new WritingSystemsMigrator(e.ProjectPath);
                migrator.MigrateIfNecessary();

                AssertThatXmlIn.File(idChangeLogFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/To[text()='qaa-x-blah']");
            }
        }
示例#19
0
 public void MigrateIfNeeded_WSPrefsAndLdmlV0ContainsIdsThatNeedMigrating_WritingSystemChangeLogUpdated()
 {
     using (var e = new TestEnvironment())
     {
         const string language = "zzas";
         e.WriteToPrefsFile(WritingSystemPrefsFileContent.SingleWritingSystem(language, language, "", "", "", 12, false, language, "", false, true));
         string writingSystemsPath  = Path.Combine(e.ProjectPath, "WritingSystems");
         string ldmlFilePath        = Path.Combine(writingSystemsPath, "en-bogus.ldml");
         string idChangeLogFilePath = Path.Combine(writingSystemsPath, "idchangelog.xml");
         Directory.CreateDirectory(writingSystemsPath);
         File.WriteAllText(ldmlFilePath, LdmlContentForTests.Version0("en-bogus", "", "", ""));
         var migrator = new WritingSystemsMigrator(e.ProjectPath);
         migrator.MigrateIfNecessary();
         AssertThatXmlIn.File(idChangeLogFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/To[text()='en-x-bogus']");
         AssertThatXmlIn.File(idChangeLogFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/To[text()='qaa-Zxxx-x-zzas-audio']");
     }
 }
示例#20
0
        //This is not really a problem, but it would be nice if the file were made consistant. So make we will make them run it through the migrator, which they should be using anyway.
        public void Constructor_LdmlFolderStoreContainsInconsistentlyNamedFile_HasExpectedProblem()
        {
            using (var environment = new TestEnvironment())
            {
                File.WriteAllText(Path.Combine(environment.TestPath, "tpi-Zxxx-x-audio.ldml"),
                                  LdmlContentForTests.CurrentVersion("de", "latn", "ch", "1901"));

                var repository = new LdmlInFolderWritingSystemRepository(environment.TestPath);
                var problems   = repository.LoadProblems;
                Assert.That(problems.Count, Is.EqualTo(1));
                Assert.That(
                    problems[0].Exception,
                    Is.TypeOf <ApplicationException>().With.Property("Message").
                    ContainsSubstring(String.Format(
                                          @"The writing system file {0} seems to be named inconsistently. It contains the Rfc5646 tag: 'de-latn-ch-1901'. The name should have been made consistent with its content upon migration of the writing systems.",
                                          Path.Combine(environment.TestPath, "tpi-Zxxx-x-audio.ldml")
                                          ))
                    );
            }
        }
示例#21
0
 public void Read_ReadPrivateUseWsFromFieldWorksLdmlThenNormalLdmlMissingVersion1Element_Throws()
 {
     using (TempFile badFlexLdml = new TempFile(),
            version0Ldml = new TempFile())
     {
         using (var writer = new StreamWriter(badFlexLdml.Path, false, Encoding.UTF8))
         {
             writer.Write(LdmlContentForTests.Version0("x-en", "", "", "x-private"));
         }
         using (var writer = new StreamWriter(version0Ldml.Path, false, Encoding.UTF8))
         {
             writer.Write(LdmlContentForTests.Version0("en", "", "", ""));
         }
         var wsV1    = new WritingSystemDefinitionV1();
         var wsV0    = new WritingSystemDefinitionV1();
         var adaptor = new LdmlAdaptorV1();
         adaptor.Read(badFlexLdml.Path, wsV0);
         Assert.Throws <ApplicationException>(() => adaptor.Read(version0Ldml.Path, wsV1));
     }
 }
示例#22
0
        public void LoadDefinitions_ValidLanguageTagStartingWithXButV0_Throws()
        {
            using (var environment = new TestEnvironment())
            {
                var pathToFlexprivateUseLdml = Path.Combine(environment.TestPath, "xh.ldml");
                File.WriteAllText(pathToFlexprivateUseLdml, LdmlContentForTests.Version0("xh", "", "", ""));
                var repository = new LdmlInFolderWritingSystemRepository(environment.TestPath);
                var problems   = repository.LoadProblems;

                Assert.That(problems.Count, Is.EqualTo(1));
                Assert.That(
                    problems[0].Exception,
                    Is.TypeOf <ApplicationException>().With.Property("Message").
                    ContainsSubstring(String.Format(
                                          "The LDML tag 'xh' is version 0.  Version {0} was expected.",
                                          WritingSystemDefinition.LatestWritingSystemDefinitionVersion
                                          ))
                    );
            }
        }
示例#23
0
 public void Write_WritePrivateUseWsFromFieldWorksLdmlThenNormalLdml_ContainsVersion2()
 {
     using (TempFile badFlexLdml = new TempFile(),
            version1Ldml = new TempFile())
     {
         var namespaceManager = new XmlNamespaceManager(new NameTable());
         namespaceManager.AddNamespace("palaso", "urn://palaso.org/ldmlExtensions/v1");
         using (var writer = new StreamWriter(badFlexLdml.Path, false, Encoding.UTF8))
         {
             writer.Write(LdmlContentForTests.Version0("x-en", "", "", "x-private"));
         }
         var wsV0    = new WritingSystemDefinitionV1();
         var adaptor = new LdmlAdaptorV1();
         adaptor.Read(badFlexLdml.Path, wsV0);
         adaptor.Write(badFlexLdml.Path, wsV0, new MemoryStream(File.ReadAllBytes(badFlexLdml.Path)));
         var wsV1 = new WritingSystemDefinitionV1();
         adaptor.Write(version1Ldml.Path, wsV1, null);
         var versionReader = new WritingSystemLdmlVersionGetter();
         Assert.That(versionReader.GetFileVersion(version1Ldml.Path), Is.EqualTo(2));
     }
 }
示例#24
0
        public void LoadAllDefinitions_LDMLV0_HasExpectedProblem()
        {
            using (var environment = new TestEnvironment())
            {
                var ldmlPath = Path.Combine(environment.TestPath, "en.ldml");
                File.WriteAllText(ldmlPath, LdmlContentForTests.Version0("en", "", "", ""));

                var repository = new LdmlInFolderWritingSystemRepository(environment.TestPath);
                var problems   = repository.LoadProblems;

                Assert.That(problems.Count, Is.EqualTo(1));
                Assert.That(
                    problems[0].Exception,
                    Is.TypeOf <ApplicationException>().With.Property("Message").
                    ContainsSubstring(String.Format(
                                          "The LDML tag 'en' is version 0.  Version {0} was expected.",
                                          WritingSystemDefinition.LatestWritingSystemDefinitionVersion
                                          ))
                    );
            }
        }
示例#25
0
 public void CorrectlyAppendsLdmlVersion3ToBranchName()
 {
     using (var liftProject = new TemporaryFolder("TempProj_LIFT"))
         using (var liftFile = new TempFileFromFolder(liftProject, "proj.lift", TestLift13File))
         {
             var wsDirectory = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(liftFile.Path), "WritingSystems"));
             using (var writingSystemsDir =
                        TempFileFromFolder.CreateAt(liftProject.Combine("WritingSystems", "lang.ldml"), LdmlContentForTests.Version3("en", "", "", "")))
             {
                 var syncAdjunct = new LiftSynchronizerAdjunct(liftFile.Path);
                 Assert.AreEqual("LIFT0.13_ldml3", syncAdjunct.BranchName, "BranchName should be 'LIFT0.13_ldml3' with version 3 ldml files");
             }
         }
 }
示例#26
0
 //This test makes sure that existing Flex private use tags are not changed
 public void CreateNonExistentWritingSystemsFoundInLift_LiftFileContainsEntirelyPrivateUseRfcTagThatExistsInRepo_RfcTagIsMigrated()
 {
     using (var e = new TestEnvironment(String.Format(TestEnvironment.LiftFile1Content, "x-custom-Zxxx-x-audio", "x-dontcare")))
     {
         e.WriteContentToLdmlFileInWritingSystemFolderWithName("x-custom-Zxxx-x-audio", LdmlContentForTests.Version0("x-custom", "Zxxx", "", "x-audio"));
         e.Helper.CreateNonExistentWritingSystemsFoundInFile();
         Assert.That(File.Exists(e.GetLdmlFileforWs("x-custom-Zxxx-x-audio")), Is.True);
         Assert.That(File.Exists(e.GetLdmlFileforWs("en-Zxxx-x-audio")), Is.False);
         AssertThatXmlIn.File(e.PathToLiftFile).HasAtLeastOneMatchForXpath("/lift/entry/lexical-unit/form[@lang='x-custom-Zxxx-audio']");
         AssertThatXmlIn.File(e.PathToLiftFile).HasNoMatchForXpath("/lift/entry/lexical-unit/form[@lang='custom-Zxxx-x-audio']");
     }
 }