public void EncodeLine_Backslashes() { byte[] line = TempSFFileMaker.EncodeLine("abc" + @"\\" + "def", Encoding.ASCII); Assert.AreEqual(10, line.Length); int i = 0; Assert.AreEqual('a', line[i++]); Assert.AreEqual('b', line[i++]); Assert.AreEqual('c', line[i++]); Assert.AreEqual('\\', line[i++]); Assert.AreEqual('\\', line[i++]); Assert.AreEqual('d', line[i++]); Assert.AreEqual('e', line[i++]); Assert.AreEqual('f', line[i++]); Assert.AreEqual(s_cr, line[i++]); Assert.AreEqual(s_lf, line[i++]); TempSFFileMaker testFileMaker = new TempSFFileMaker(); string filename = testFileMaker.CreateFile("EPH", new[] { @"\v 1 c:\abc\def" }, Encoding.UTF8, false); using (TextReader reader = FileUtils.OpenFileForRead(filename, Encoding.UTF8)) { Assert.AreEqual(@"\id EPH", reader.ReadLine()); Assert.AreEqual(@"\v 1 c:\abc\def", reader.ReadLine()); } }
public void TestCreateFileIdLineOnly_ASCII() { CheckDisposed(); using (TempSFFileMaker testFileMaker = new TempSFFileMaker()) { string filename = testFileMaker.CreateFile("EPH", null); // Check the file contents. using (BinaryReader file = new BinaryReader(new FileStream(filename, FileMode.Open))) { byte[] fileContents = file.ReadBytes((int)file.BaseStream.Length); int i = 0; Assert.AreEqual(92, fileContents[i++]); Assert.AreEqual(105, fileContents[i++]); Assert.AreEqual(100, fileContents[i++]); Assert.AreEqual(32, fileContents[i++]); Assert.AreEqual(69, fileContents[i++]); Assert.AreEqual(80, fileContents[i++]); Assert.AreEqual(72, fileContents[i++]); Assert.AreEqual(s_cr, fileContents[i++]); Assert.AreEqual(s_lf, fileContents[i++]); file.Close(); } } }
public void TestCreateFile_UnicodeBOM() { TempSFFileMaker testFileMaker = new TempSFFileMaker(); string filename = testFileMaker.CreateFile("EPH", null, Encoding.Unicode, true); // Check the file contents. using (BinaryReader file = FileUtils.OpenFileForBinaryRead(filename, Encoding.Unicode)) { byte[] fileContents = file.ReadBytes((int)file.BaseStream.Length); int i = 0; Assert.AreEqual(0xff, fileContents[i++]); Assert.AreEqual(0xfe, fileContents[i++]); Assert.AreEqual(92, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); Assert.AreEqual(105, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); Assert.AreEqual(100, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); Assert.AreEqual(32, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); Assert.AreEqual(69, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); Assert.AreEqual(80, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); Assert.AreEqual(72, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); Assert.AreEqual(s_cr, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); Assert.AreEqual(s_lf, fileContents[i++]); Assert.AreEqual(0, fileContents[i++]); } }
public void EncodeLine_Backslashes() { CheckDisposed(); byte[] line = TempSFFileMaker.EncodeLine("abc" + @"\\" + "def", Encoding.ASCII); Assert.AreEqual(10, line.Length); int i = 0; Assert.AreEqual('a', line[i++]); Assert.AreEqual('b', line[i++]); Assert.AreEqual('c', line[i++]); Assert.AreEqual('\\', line[i++]); Assert.AreEqual('\\', line[i++]); Assert.AreEqual('d', line[i++]); Assert.AreEqual('e', line[i++]); Assert.AreEqual('f', line[i++]); Assert.AreEqual(s_cr, line[i++]); Assert.AreEqual(s_lf, line[i++]); using (TempSFFileMaker testFileMaker = new TempSFFileMaker()) { string filename = testFileMaker.CreateFile("EPH", new string[] { @"\v 1 c:\abc\def" }, Encoding.UTF8, false); using (StreamReader reader = new StreamReader(filename)) { Assert.AreEqual(@"\id EPH", reader.ReadLine()); Assert.AreEqual(@"\v 1 c:\abc\def", reader.ReadLine()); } } }
public void LoadParatext5Project() { CheckDisposed(); ScrObjWrapper wrapper = new ScrObjWrapper(); ScrImportSet settings = new ScrImportSet(); Cache.LangProject.TranslatedScriptureOA.ImportSettingsOC.Add(settings); settings.ImportTypeEnum = TypeOfImport.Paratext5; settings.StartRef = new BCVRef(1, 1, 1); settings.EndRef = new BCVRef(66, 22, 21); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string fileName = fileMaker.CreateFile("EXO", new string[] {@"\mt Exodus", @"\c 1", @"\v 1 This is fun!"}); settings.AddFile(fileName, ImportDomain.Main, null, 0); wrapper.LoadScriptureProject(settings); Assert.IsFalse(wrapper.BooksPresent.Contains(1)); Assert.IsTrue(wrapper.BooksPresent.Contains(2)); string sText, sMarker; ImportDomain domain; Assert.IsTrue(wrapper.GetNextSegment(out sText, out sMarker, out domain)); Assert.AreEqual(fileName, wrapper.CurrentFileName); Assert.AreEqual(1, wrapper.CurrentLineNumber); Assert.AreEqual(new BCVRef(2, 1, 0), wrapper.SegmentFirstRef); Assert.AreEqual(new BCVRef(2, 1, 0), wrapper.SegmentLastRef); Assert.AreEqual(2, wrapper.ExternalPictureFolders.Count); Assert.AreEqual(Cache.LangProject.ExternalLinkRootDir, wrapper.ExternalPictureFolders[0]); Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), wrapper.ExternalPictureFolders[1]); } }
public void TestCreateFileNullSILBookId() { CheckDisposed(); using (TempSFFileMaker testFileMaker = new TempSFFileMaker()) { testFileMaker.CreateFile(null, null); } }
public void TestCheckForOverlaps_KeepFile2() { // Add temp file to the project using (TempSFFileMaker filemaker = new TempSFFileMaker()) { ScrImportFileInfo f1 = new ScrImportFileInfo( filemaker.CreateFile("MAT", new string[] {@"\c 1", @"\c 2", @"\c 3"}), m_mappingList, ImportDomain.Main, null, 0, false); m_expectedRemovedFiles.Add(f1); ScrImportFileInfo f2 = new ScrImportFileInfo( filemaker.CreateFile("MAT", new string[] {@"\c 3", @"\c 4", @"\c 5"}), m_mappingList, ImportDomain.Main, null, 0, false); ScrImportFileInfo f3 = new ScrImportFileInfo( filemaker.CreateFile("MAT", new string[] {@"\c 6", @"\c 7"}), m_mappingList, ImportDomain.Main, null, 0, false); ScrImportFileInfo f4 = new ScrImportFileInfo("c:\\Idontexist.blurb", m_mappingList, ImportDomain.Main, null, 0, false); m_resolver.ExpectAndReturn("ChooseFileToRemove", f1, f2, f1); m_fileList.Add(f1); m_fileList.Add(f2); m_fileList.Add(f3); m_fileList.Add(f4); Assert.AreEqual(3, m_fileList.Count); Assert.AreEqual(f2, m_fileList[0]); Assert.AreEqual(f3, m_fileList[1]); Assert.AreEqual(f4, m_fileList[2]); } m_resolver.Verify(); Assert.AreEqual(m_expectedRemovedFiles.Count, m_callCountForVerifyFileRemoved); }
public void TestCreateFileIdLineOnly_ASCII() { TempSFFileMaker testFileMaker = new TempSFFileMaker(); string filename = testFileMaker.CreateFile("EPH", null); // Check the file contents. using (BinaryReader file = FileUtils.OpenFileForBinaryRead(filename, Encoding.ASCII)) { byte[] fileContents = file.ReadBytes((int)file.BaseStream.Length); int i = 0; Assert.AreEqual(92, fileContents[i++]); Assert.AreEqual(105, fileContents[i++]); Assert.AreEqual(100, fileContents[i++]); Assert.AreEqual(32, fileContents[i++]); Assert.AreEqual(69, fileContents[i++]); Assert.AreEqual(80, fileContents[i++]); Assert.AreEqual(72, fileContents[i++]); Assert.AreEqual(s_cr, fileContents[i++]); Assert.AreEqual(s_lf, fileContents[i++]); } }
public void TestCreateFileThreeLines_ASCII() { TempSFFileMaker testFileMaker = new TempSFFileMaker(); string filename = testFileMaker.CreateFile("EPH", new string[] { @"\mt test", @"\p" }); // Check the file contents. using (BinaryReader file = FileUtils.OpenFileForBinaryRead(filename, Encoding.ASCII)) { byte[] fileContents = file.ReadBytes((int)file.BaseStream.Length); int i = 0; Assert.AreEqual(92, fileContents[i++]); Assert.AreEqual(105, fileContents[i++]); Assert.AreEqual(100, fileContents[i++]); Assert.AreEqual(32, fileContents[i++]); Assert.AreEqual(69, fileContents[i++]); Assert.AreEqual(80, fileContents[i++]); Assert.AreEqual(72, fileContents[i++]); Assert.AreEqual(s_cr, fileContents[i++]); Assert.AreEqual(s_lf, fileContents[i++]); Assert.AreEqual(92, fileContents[i++]); Assert.AreEqual(109, fileContents[i++]); Assert.AreEqual(116, fileContents[i++]); Assert.AreEqual(32, fileContents[i++]); Assert.AreEqual(116, fileContents[i++]); Assert.AreEqual(101, fileContents[i++]); Assert.AreEqual(115, fileContents[i++]); Assert.AreEqual(116, fileContents[i++]); Assert.AreEqual(s_cr, fileContents[i++]); Assert.AreEqual(s_lf, fileContents[i++]); Assert.AreEqual(92, fileContents[i++]); Assert.AreEqual(112, fileContents[i++]); Assert.AreEqual(s_cr, fileContents[i++]); Assert.AreEqual(s_lf, fileContents[i++]); } }
public void InlineAfterLineMaker() { CheckDisposed(); m_settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\it ", @"\it*", "Emphasis")); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string fileName = fileMaker.CreateFile("MAT", new string[] { @"\mt \it Matthew\it*", @"\c 1", @"\v 1"}, Encoding.UTF8, false); m_settings.AddFile(fileName, ImportDomain.Main, null, 0); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(40, 0, 0, Paratext.ScrVers.English), new ScrReference(40, 1, 16, Paratext.ScrVers.English)); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 1"); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 2"); Assert.AreEqual(@"\mt", textSeg.Marker); Assert.AreEqual(string.Empty, textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 3"); Assert.AreEqual(@"\it ", textSeg.Marker); Assert.AreEqual("Matthew", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 3"); Assert.AreEqual(@"\it*", textSeg.Marker); Assert.AreEqual(@" ", textSeg.Text); } }
public void SOMustSupportTextAfterVerseAndChapterNum() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string fileName = fileMaker.CreateFile("MAT", new string[] { @"\mt Matthew", @"\c 1 First Chapter", @"\v 1. Verse text", @"\v 2-3aForgot space!", // added 8/6 @"\v 2-3ab.Missing Space", @"\v 2-3.abMissing Space", @"\v 2-3a.bMissing Space", @"\v 2-3.a.b.Missing Space", @"\v 5-blah", @"\v 6- blah", @"\v 7.a,8.a,9a. testing", "\\v 8\u200f-\u200f9 Text with RTL", "\\v 10\u201011 Text with unicode hyphen"}, Encoding.UTF8, false); m_settings.AddFile(fileName, ImportDomain.Main, null, 0); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(40, 0, 0, Paratext.ScrVers.English), new ScrReference(40, 1, 16, Paratext.ScrVers.English)); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 1"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("MAT ", textSeg.Text); Assert.AreEqual(40, textSeg.FirstReference.Book); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 2"); Assert.AreEqual(@"\mt", textSeg.Marker); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(0, textSeg.FirstReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 2"); Assert.AreEqual(@"\c", textSeg.Marker); Assert.AreEqual(" First Chapter ", textSeg.Text); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(1, textSeg.FirstReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 3"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@" Verse text ", textSeg.Text); Assert.AreEqual(@"1.", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(1, textSeg.FirstReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 4"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@"aForgot space! ", textSeg.Text); Assert.AreEqual(@"2-3", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(2, textSeg.FirstReference.Verse); Assert.AreEqual(1, textSeg.LastReference.Chapter); Assert.AreEqual(3, textSeg.LastReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 5"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@"ab.Missing Space ", textSeg.Text); Assert.AreEqual(@"2-3", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(2, textSeg.FirstReference.Verse); Assert.AreEqual(1, textSeg.LastReference.Chapter); Assert.AreEqual(3, textSeg.LastReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 6"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@"abMissing Space ", textSeg.Text); Assert.AreEqual(@"2-3.", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(2, textSeg.FirstReference.Verse); Assert.AreEqual(1, textSeg.LastReference.Chapter); Assert.AreEqual(3, textSeg.LastReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 7"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@"bMissing Space ", textSeg.Text); Assert.AreEqual(@"2-3a.", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(2, textSeg.FirstReference.Verse); Assert.AreEqual(1, textSeg.LastReference.Chapter); Assert.AreEqual(3, textSeg.LastReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 8"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@"a.b.Missing Space ", textSeg.Text); Assert.AreEqual(@"2-3.", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(2, textSeg.FirstReference.Verse); Assert.AreEqual(1, textSeg.LastReference.Chapter); Assert.AreEqual(3, textSeg.LastReference.Verse); // lower 3 bits represent the versification Assert.AreEqual(0, textSeg.LastReference.Segment); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 9"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@"-blah ", textSeg.Text); Assert.AreEqual(@"5", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(5, textSeg.FirstReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 10"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@" blah ", textSeg.Text); Assert.AreEqual(@"6-", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(6, textSeg.FirstReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 11"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(@"a,8.a,9a. testing ", textSeg.Text); Assert.AreEqual(@"7.", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(7, textSeg.FirstReference.Verse); Assert.AreEqual(1, textSeg.LastReference.Chapter); Assert.AreEqual(7, textSeg.LastReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 12"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(" Text with RTL ", textSeg.Text); Assert.AreEqual("8\u200f-\u200f9", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(8, textSeg.FirstReference.Verse); Assert.AreEqual(1, textSeg.LastReference.Chapter); Assert.AreEqual(9, textSeg.LastReference.Verse); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 13"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(" Text with unicode hyphen ", textSeg.Text); Assert.AreEqual("10\u201011", textSeg.LiteralVerseNum); Assert.AreEqual(1, textSeg.FirstReference.Chapter); Assert.AreEqual(10, textSeg.FirstReference.Verse); Assert.AreEqual(1, textSeg.LastReference.Chapter); Assert.AreEqual(11, textSeg.LastReference.Verse); } }
public void TestExcludeByRange() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string fileName = fileMaker.CreateFile("EPH", new string[] {@"\mt Ephesians", @"\c 1", @"\v 1 hello there", @"\id PHP", @"\c 1", @"\v 1 verse 1 of phillipians", @"\v 2 here is verse 2", @"\id COL", @"\c 1", @"\v 1 colossians start", @"\v 2 more stuff"}); m_settings.AddFile(fileName, ImportDomain.Main, null, 0); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(50, 0, 0, Paratext.ScrVers.English), new ScrReference(50, 1, 1, Paratext.ScrVers.English)); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read first segment"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("PHP ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg); Assert.AreEqual(@"\c", textSeg.Marker); Assert.AreEqual(50001001, textSeg.FirstReference.BBCCCVVV); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(50001001, textSeg.FirstReference.BBCCCVVV); Assert.AreEqual(" verse 1 of phillipians ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(50001002, textSeg.FirstReference.BBCCCVVV); Assert.AreEqual(" here is verse 2 ", textSeg.Text); Assert.IsNull(textEnum.Next()); } }
public void HandleP5InlineMarkerWithNoExplicitEndMarker() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string fileName = fileMaker.CreateFile("EPH", new string[] {@"\mt fun \f + \ft footnote \f*", @"\c 1", @"\v 1"}); m_settings.ImportTypeEnum = TypeOfImport.Paratext5; m_settings.AddFile(fileName, ImportDomain.Main, null, 0); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(49, 0, 0, Paratext.ScrVers.English), new ScrReference(49, 1, 1, Paratext.ScrVers.English)); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \id segment"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("EPH ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \mt segment"); Assert.AreEqual(@"\mt", textSeg.Marker); Assert.AreEqual(@"fun ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \f segment"); Assert.AreEqual(@"\f", textSeg.Marker); Assert.AreEqual(@"+ ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \ft segment"); Assert.AreEqual(@"\ft", textSeg.Marker); Assert.AreEqual(@"footnote ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \f* segment"); Assert.AreEqual(@"\f*", textSeg.Marker); Assert.AreEqual(@" ", textSeg.Text); } }
public void TreatBackslashesInDataAsInlineMarkersForP5() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string fileName = fileMaker.CreateFile("EPH", new string[] {@"\mt \it fun\it* Mi\\abi \taki", @"\c 1", @"\v 1"}); m_settings.AddFile(fileName, ImportDomain.Main, null, 0); m_settings.ImportTypeEnum = TypeOfImport.Paratext5; ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(49, 0, 0, Paratext.ScrVers.English), new ScrReference(49, 1, 1, Paratext.ScrVers.English)); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \id segment"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("EPH ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \mt segment"); Assert.AreEqual(@"\mt", textSeg.Marker); Assert.AreEqual(@"", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \it segment"); Assert.AreEqual(@"\it", textSeg.Marker); Assert.AreEqual(@"fun", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \it* segment"); Assert.AreEqual(@"\it*", textSeg.Marker); Assert.AreEqual(@" Mi", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \\abi segment"); Assert.AreEqual(@"\\abi", textSeg.Marker); Assert.AreEqual(@"", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, @"Unable to read \taki segment"); Assert.AreEqual(@"\taki", textSeg.Marker); Assert.AreEqual(@" ", textSeg.Text); } }
public void TestSfNonSpaceDelimitedInlineBackslashMarkers() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string filename = fileMaker.CreateFile("EPH", new string[] {@"\c 1", @"\v 1 This \iis\i* nice."}); m_settings.AddFile(filename, ImportDomain.Main, null, 0); Assert.AreEqual(3, m_settings.GetMappingListForDomain(ImportDomain.Main).Count); m_settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\i", @"\i*", "Emphasis")); Assert.AreEqual(4, m_settings.GetMappingListForDomain(ImportDomain.Main).Count); ImportMappingInfo mapping = m_settings.MappingForMarker(@"\i", MappingSet.Main); Assert.AreEqual(@"\i", mapping.BeginMarker); Assert.AreEqual(@"\i*", mapping.EndMarker); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(49, 0, 0, Paratext.ScrVers.English), new ScrReference(49, 1, 1, Paratext.ScrVers.English) ); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 1"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("EPH ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 2"); Assert.AreEqual(@"\c", textSeg.Marker); Assert.AreEqual(@" ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 3"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(" This ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 4"); Assert.AreEqual(@"\i", textSeg.Marker); Assert.AreEqual("is", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 5"); Assert.AreEqual(@"\i*", textSeg.Marker); Assert.AreEqual(" nice. ", textSeg.Text); } }
public void FigureEntries_good_WithEndMarker() { using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { // Note that ending \fig* is optional even if it is in mapping. string sFilename = fileMaker.CreateFile("ROM", new string[] { @"\mt Romans", @"\c 1", @"\v 1 Hello", @"\fig stuff1|stuff2|stuff3|stuff4|stuff5|stuff6\fig* etc.", @"\fig stuff1|stuff2|stuff3|stuff4|stuff5|stuff6"}, Encoding.UTF8, false); m_mappingList.Add(new ImportMappingInfo(@"\fig", @"\fig*", false, MappingTargetType.Figure, MarkerDomain.Default, null, null)); ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList, ImportDomain.Main, null, 0, true); // Use strict checking to make sure no error occurs. fileInfo.PerformStrictScan(); } }
public void OverlapWhenOneFileContainsSubset() { using (TempSFFileMaker filemaker = new TempSFFileMaker()) { string fileName1 = filemaker.CreateFile("MAT", new string[] {@"\c 3", @"\c 4", @"\c 5", @"\c 6"}); ScrImportFileInfo map1 = new ScrImportFileInfo(fileName1, m_mappingList, ImportDomain.Main, null, 0); string fileName2 = filemaker.CreateFile("MAT", new string[] {@"\c 4", @"\c 5"}); ScrImportFileInfo map2 = new ScrImportFileInfo(fileName2, m_mappingList, ImportDomain.Main, null, 0); Assert.IsTrue(ScrImportFileInfo.CheckForOverlap(map1, map2)); Assert.IsTrue(ScrImportFileInfo.CheckForOverlap(map2, map1)); } }
public void FigureEntries_excluded() { using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string sFilename = fileMaker.CreateFile("ROM", new string[] { @"\mt Romans", @"\c 1", @"\v 1 Hello", @"\fig stuff1|stuff2|stuff3|stuff4|stuff5"}, Encoding.UTF8, false); m_mappingList.Add(new ImportMappingInfo(@"\fig", null, true, MappingTargetType.Figure, MarkerDomain.Default, null, null)); new ScrImportFileInfo(sFilename, m_mappingList, ImportDomain.Main, null, 0, true); } }
public void FigureEntries_bad_tooFewTokens() { using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string sFilename = fileMaker.CreateFile("ROM", new string[] { @"\mt Romans", @"\c 1", @"\v 1 Hello", @"\fig stuff1|stuff2|stuff3|stuff4|stuff5"}, Encoding.UTF8, false); m_mappingList.Add(new ImportMappingInfo(@"\fig", null, false, MappingTargetType.Figure, MarkerDomain.Default, null, null)); // Try it first without strict checking to make sure it does not throw an exception ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList, ImportDomain.Main, null, 0); try { // Use strict checking to make sure the error occurs. fileInfo.PerformStrictScan(); } catch (ScriptureUtilsException e) { Assert.AreEqual(SUE_ErrorCode.BadFigure, e.ErrorCode); return; } Assert.Fail("The expected exception did not happen"); } }
public void TestCharStyleInFootnote() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string filename = fileMaker.CreateFile("EPH", new string[] {@"\c 1", @"\v 1 This %fis a %iemphasized%i* footnote%f* test."}); m_settings.AddFile(filename, ImportDomain.Main, null, 0); Assert.AreEqual(3, m_settings.GetMappingListForDomain(ImportDomain.Main).Count); m_settings.SetMapping(MappingSet.Main, new ImportMappingInfo("%f", "%f*", false, MappingTargetType.TEStyle, MarkerDomain.Footnote, "Note General Paragraph", null)); m_settings.SetMapping(MappingSet.Main, new ImportMappingInfo("%i", "%i*", "Emphasis")); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(49, 0, 0, Paratext.ScrVers.English), new ScrReference(49, 1, 1, Paratext.ScrVers.English) ); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 1"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("EPH ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 2"); Assert.AreEqual(@"\c", textSeg.Marker); Assert.AreEqual(@" ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 3"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(" This ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 4"); Assert.AreEqual("%f", textSeg.Marker); Assert.AreEqual("is a ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 5"); Assert.AreEqual("%i", textSeg.Marker); Assert.AreEqual("emphasized", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 6"); Assert.AreEqual("%i*", textSeg.Marker); Assert.AreEqual(" footnote", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 7"); Assert.AreEqual("%f*", textSeg.Marker); Assert.AreEqual(" test. ", textSeg.Text); } }
public void TestSfDroppedSpaceAfterEndingBackslashMarkers() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { // FYI: this data intentionally includes a spurious space following "don't" and // another following "Footnote." string filename = fileMaker.CreateFile("EPH", new string[] {@"\c 1", @"\v 1 This don't \f Footnote. \fe work."}); m_settings.AddFile(filename, ImportDomain.Main, null, 0); Assert.AreEqual(3, m_settings.GetMappingListForDomain(ImportDomain.Main).Count); m_settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\f ", @"\fe", false, MappingTargetType.TEStyle, MarkerDomain.Footnote, "Note General Paragraph", null)); Assert.AreEqual(4, m_settings.GetMappingListForDomain(ImportDomain.Main).Count); ImportMappingInfo mapping = m_settings.MappingForMarker(@"\f ", MappingSet.Main); Assert.AreEqual(@"\f ", mapping.BeginMarker); Assert.AreEqual(@"\fe", mapping.EndMarker); Assert.AreEqual(true, mapping.IsInline); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(49, 0, 0, Paratext.ScrVers.English), new ScrReference(49, 1, 1, Paratext.ScrVers.English) ); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 1"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("EPH ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 2"); Assert.AreEqual(@"\c", textSeg.Marker); Assert.AreEqual(@" ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 3"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(" This don't ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 4"); Assert.AreEqual(@"\f ", textSeg.Marker); Assert.AreEqual("Footnote. ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 5"); Assert.AreEqual(@"\fe", textSeg.Marker); Assert.AreEqual(" work. ", textSeg.Text); } }
public void BooksInFile() { CheckDisposed(); // Test single book in a file using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { // one book in file string file1 = fileMaker.CreateFile("MAT", new string[] {@"\c 1", @"\v 1"}); m_settings.AddFile(file1, ImportDomain.Main, null, 0); // three books in file string file2 = fileMaker.CreateFile("GAL", new string[] {@"\c 1", @"\v 1", @"\id EPH", @"\c 1", @"\v 1", @"\id PHP", @"\c 1", @"\v 1"}); m_settings.AddFile(file2, ImportDomain.Main, null, 0); // check file with one book ImportFileSource source = m_settings.GetImportFiles(ImportDomain.Main); IEnumerator sourceEnum = source.GetEnumerator(); sourceEnum.MoveNext(); ScrImportFileInfo info = (ScrImportFileInfo)sourceEnum.Current; List<int> bookList1 = info.BooksInFile; Assert.AreEqual(1, bookList1.Count); Assert.AreEqual(40, bookList1[0]); // check file with three books sourceEnum.MoveNext(); info = (ScrImportFileInfo)sourceEnum.Current; List<int> bookList2 = info.BooksInFile; Assert.AreEqual(3, bookList2.Count); Assert.AreEqual(48, bookList2[0]); Assert.AreEqual(49, bookList2[1]); Assert.AreEqual(50, bookList2[2]); } }
public void TestCreateFileNullSILBookId() { TempSFFileMaker testFileMaker = new TempSFFileMaker(); testFileMaker.CreateFile(null, null); }
public void TestSfBackToBackInlineMarkers() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string filename = fileMaker.CreateFile("EPH", new string[] {@"\c 1", @"\v 1 This |iis|r |ua|r nice test."}); m_settings.AddFile(filename, ImportDomain.Main, null, 0); Assert.AreEqual(3, m_settings.GetMappingListForDomain(ImportDomain.Main).Count); m_settings.SetMapping(MappingSet.Main, new ImportMappingInfo("|i", "|r", "Emphasis")); m_settings.SetMapping(MappingSet.Main, new ImportMappingInfo("|u", "|r", "Key Word")); Assert.AreEqual(5, m_settings.GetMappingListForDomain(ImportDomain.Main).Count); ImportMappingInfo mapping = m_settings.MappingForMarker(@"|i", MappingSet.Main); Assert.AreEqual(@"|i", mapping.BeginMarker); Assert.AreEqual(@"|r", mapping.EndMarker); Assert.AreEqual(true, mapping.IsInline); mapping = m_settings.MappingForMarker(@"|u", MappingSet.Main); Assert.AreEqual(@"|u", mapping.BeginMarker); Assert.AreEqual(@"|r", mapping.EndMarker); Assert.AreEqual(true, mapping.IsInline); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(49, 0, 0, Paratext.ScrVers.English), new ScrReference(49, 1, 1, Paratext.ScrVers.English) ); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 1"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("EPH ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 2"); Assert.AreEqual(@"\c", textSeg.Marker); Assert.AreEqual(@" ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 3"); Assert.AreEqual(@"\v", textSeg.Marker); Assert.AreEqual(" This ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 4"); Assert.AreEqual("|i", textSeg.Marker); Assert.AreEqual("is", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 5"); Assert.AreEqual("|r", textSeg.Marker); Assert.AreEqual(" ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 6"); Assert.AreEqual("|u", textSeg.Marker); Assert.AreEqual("a", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read segment 7"); Assert.AreEqual("|r", textSeg.Marker); Assert.AreEqual(" nice test. ", textSeg.Text); } }
public void IgnoreBackslashesInDataForOther() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string fileName = fileMaker.CreateFile("EPH", new string[] {@"\mt \it fun \it* Mi\\abi \taki", @"\c 1", @"\v 1"}); m_settings.AddFile(fileName, ImportDomain.Main, null, 0); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(49, 0, 0, Paratext.ScrVers.English), new ScrReference(49, 1, 1, Paratext.ScrVers.English)); ISCTextSegment textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read first segment"); Assert.AreEqual(@"\id", textSeg.Marker); Assert.AreEqual("EPH ", textSeg.Text); textSeg = textEnum.Next(); Assert.IsNotNull(textSeg, "Unable to read second segment"); Assert.AreEqual(@"\mt", textSeg.Marker); Assert.AreEqual(@"\it fun \it* Mi\\abi \taki ", textSeg.Text); } }
public void FigureEntries_good_SplitAcrossLine_LineWithMarkerFollowing() { using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string sFilename = fileMaker.CreateFile("ROM", new string[] {@"\mt Romans", @"\c 1", @"\v 1 Hello", @"\fig stuff1|stuff2|stuff3|stuff that", @"is for 4|stuff5|stuff6", @"\v 2 This is Paul."}, Encoding.UTF8, false); m_mappingList.Add(new ImportMappingInfo(@"\fig", null, false, MappingTargetType.Figure, MarkerDomain.Default, null, null)); ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList, ImportDomain.Main, null, 0, true); // Use strict checking to make sure no error occurs. fileInfo.PerformStrictScan(); } }
public void DeletedDataFile() { CheckDisposed(); string sFilename = null; try { using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { sFilename = fileMaker.CreateFile("GEN", new string[] {@"\mt Genesis", @"\c 1", @"\v 1 My verse"}); m_settings.AddFile(sFilename, ImportDomain.Main, null, 0); FileInfo file = new FileInfo(sFilename); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(1, 0, 0, Paratext.ScrVers.English), new ScrReference(1, 1, 1, Paratext.ScrVers.English)); file.Delete(); // calling Next will cause the file to be read textEnum.Next(); } } catch (ScriptureUtilsException e) { Assert.AreEqual(e.ErrorCode, SUE_ErrorCode.FileError); return; // correct error } Assert.Fail("The deleted data file was not detected."); }
public void NoOverlapInOneBook() { using (TempSFFileMaker filemaker = new TempSFFileMaker()) { string fileName1 = filemaker.CreateFile("MAT", new string[] {@"\c 1", @"\c 2", @"\c 3", @"\c 4"}); ScrImportFileInfo map1 = new ScrImportFileInfo(fileName1, m_mappingList, ImportDomain.Main, null, 0); string fileName2 = filemaker.CreateFile("MAT", new string[] {@"\c 5", @"\c 6", @"\c 8", @"\c 18"}); ScrImportFileInfo map2 = new ScrImportFileInfo(fileName2, m_mappingList, ImportDomain.Main, null, 0); Assert.IsFalse(ScrImportFileInfo.CheckForOverlap(map1, map2)); Assert.IsFalse(ScrImportFileInfo.CheckForOverlap(map2, map1)); } }
public void IgnoreDeletedDataFile() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string sFilename = fileMaker.CreateFile("GEN", new string[] {@"\mt Genesis", @"\c 1", @"\v 1 My verse"}, Encoding.UTF8, true); m_settings.AddFile(sFilename, ImportDomain.Main, null, 0); sFilename = fileMaker.CreateFile("EXO", new string[] {@"\mt Exodus", @"\c 1", @"\v 1 Delete me!"}, Encoding.UTF8, true); m_settings.AddFile(sFilename, ImportDomain.Main, null, 0); Assert.AreEqual(2, m_settings.GetImportFiles(ImportDomain.Main).Count); FileInfo exodusFile = new FileInfo(sFilename); // now delete exodus and read the segments exodusFile.Delete(); Assert.AreEqual(2, m_settings.GetImportFiles(ImportDomain.Main).Count); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(1, 0, 0, Paratext.ScrVers.English), new ScrReference(1, 1, 1, Paratext.ScrVers.English)); // assume that we will not get an error reading segments. while (textEnum.Next() != null) ; } }
public void OverlapInTwoMaps() { using (TempSFFileMaker filemaker = new TempSFFileMaker()) { string fileName1 = filemaker.CreateFile("MAT", new string[] {@"\c 1", @"\c 2", @"\c 3", @"\id MRK", @"\c 1", @"\c 2", @"\c 3"}); ScrImportFileInfo map1 = new ScrImportFileInfo(fileName1, m_mappingList, ImportDomain.Main, null, 0); string fileName2 = filemaker.CreateFile("MRK", new string[] {@"\c 3", @"\id LUK", @"\c 1", @"\c 2", @"\c 3"}); ScrImportFileInfo map2 = new ScrImportFileInfo(fileName2, m_mappingList, ImportDomain.Main, null, 0); Assert.IsTrue(ScrImportFileInfo.CheckForOverlap(map1, map2)); Assert.IsTrue(ScrImportFileInfo.CheckForOverlap(map2, map1)); } }
public void NoRelevantData() { CheckDisposed(); using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string sFilename = fileMaker.CreateFile("GEN", new string[] {@"\mt Genesis", @"\c 1", @"\v 1 My verse"}); m_settings.AddFile(sFilename, ImportDomain.Main, null, 0); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(2, 0, 0, Paratext.ScrVers.English), new ScrReference(2, 1, 1, Paratext.ScrVers.English)); Assert.IsNull(textEnum.Next(), "Should be no segments to read"); } }
public void TwoFigureEntries_good_NotScanningInline() { using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { // Note that ending \fig* is optional even if it is in mapping. string sFilename = fileMaker.CreateFile("ROM", new string[] { @"\c 1", @"\v 1 Hello", @"\fig stuff1|stuff2|stuff3|stuff4|stuff5|stuff6\fig*", @"\new will I be seen?", @"\v 2 I'm a verse, too.", @"\btfig stuff1|stuff2|stuff3|stuff4|stuff5|stuff6\btfig*"}, Encoding.UTF8, false); m_mappingList.Add(new ImportMappingInfo(@"\fig", @"\fig*", false, MappingTargetType.Figure, MarkerDomain.Default, null, null)); ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList, ImportDomain.Main, null, 0, false); m_mappingList.Delete(m_mappingList[@"\new"]); Assert.IsNull(m_mappingList[@"\new"]); // Use strict checking to make sure no error occurs. fileInfo.PerformStrictScan(); Assert.IsNotNull(m_mappingList[@"\new"]); } }
public void LineNumbers() { using (TempSFFileMaker fileMaker = new TempSFFileMaker()) { string sFilename = fileMaker.CreateFile("GEN", new string[] { @"\c 1", @"\v 1", @"\vt First line", @"second line", @"third line", @"\vt next marker" }); m_settings.AddFile(sFilename, ImportDomain.Main, null, 0); ISCTextEnum textEnum = GetTextEnum(ImportDomain.Main, new ScrReference(1, 0, 0, Paratext.ScrVers.English), new ScrReference(1, 1, 1, Paratext.ScrVers.English)); ISCTextSegment text = textEnum.Next(); // id line text = textEnum.Next(); // Chapter one text = textEnum.Next(); // Verse one text = textEnum.Next(); // First to third line text = textEnum.Next(); // next marker Assert.AreEqual(7, text.CurrentLineNumber); } }