public void ToUsx_EmptySegments() { var delta = Delta.New() .InsertChapter("1") .InsertVerse("1") .InsertBlank("verse_1_1") .InsertVerse("2") .InsertBlank("verse_1_2") .InsertPara("p") .InsertBlank("verse_1_2/li_1") .InsertPara("li") .InsertBlank("verse_1_2/li_2") .InsertPara("li") .InsertBlank("verse_1_2/p_1") .InsertVerse("3") .InsertBlank("verse_1_3") .InsertPara("p") .Insert("\n"); DeltaUsxMapper mapper = CreateMapper(); XElement newUsxElem = mapper.ToUsx("2.5", "PHM", null, delta); XElement expected = Usx("PHM", Chapter("1"), Para("p", Verse("1"), Verse("2")), Para("li"), Para("li"), Para("p", Verse("3"))); Assert.IsTrue(XNode.DeepEquals(newUsxElem, expected)); }
public void ToUsx_HeaderPara() { var delta = Delta.New() .InsertText("Philemon", "h_1") .InsertPara("h") .Insert("\n"); DeltaUsxMapper mapper = CreateMapper(); XElement newUsxElem = mapper.ToUsx("2.5", "PHM", null, delta); XElement expected = Usx("PHM", Para("h", "Philemon")); Assert.IsTrue(XNode.DeepEquals(newUsxElem, expected)); }
public void ToUsx_ConsecutiveSameStyleEmptyParas() { var delta = Delta.New() .InsertPara("p") .InsertPara("p") .Insert("\n"); DeltaUsxMapper mapper = CreateMapper(); XElement newUsxElem = mapper.ToUsx("2.5", "PHM", null, delta); XElement expected = Usx("PHM", Para("p"), Para("p")); Assert.IsTrue(XNode.DeepEquals(newUsxElem, expected)); }
private async Task SyncBookAsync(User user, ParatextProject paratextProject, string fileName, string bookId, Document <Delta> doc) { await doc.FetchAsync(); XElement bookTextElem = await LoadBookTextAsync(fileName); XElement oldUsxElem = bookTextElem.Element("usx"); if (oldUsxElem == null) { throw new InvalidOperationException("Invalid USX data, missing 'usx' element."); } XElement bookElem = oldUsxElem.Element("book"); if (bookElem == null) { throw new InvalidOperationException("Invalid USX data, missing 'book' element."); } XElement newUsxElem = _deltaUsxMapper.ToUsx((string)oldUsxElem.Attribute("version"), (string)bookElem.Attribute("code"), (string)bookElem, doc.Data); var revision = (string)bookTextElem.Attribute("revision"); string bookText; if (XNode.DeepEquals(oldUsxElem, newUsxElem)) { bookText = await _paratextService.GetBookTextAsync(user, paratextProject.Id, bookId); } else { bookText = await _paratextService.UpdateBookTextAsync(user, paratextProject.Id, bookId, revision, newUsxElem.ToString()); } bookTextElem = XElement.Parse(bookText); Delta delta = _deltaUsxMapper.ToDelta(paratextProject.Id, bookTextElem.Element("usx")); Delta diffDelta = doc.Data.Diff(delta); await doc.SubmitOpAsync(diffDelta); await SaveBookTextAsync(bookTextElem, fileName); }
public void ToUsx_VerseText() { var delta = Delta.New() .InsertChapter("1") .InsertVerse("1") .InsertText("Verse text.", "verse_1_1") .InsertPara("p") .Insert("\n"); DeltaUsxMapper mapper = CreateMapper(); XElement newUsxElem = mapper.ToUsx("2.5", "PHM", null, delta); XElement expected = Usx("PHM", Chapter("1"), Para("p", Verse("1"), "Verse text.")); Assert.IsTrue(XNode.DeepEquals(newUsxElem, expected)); }
public void ToUsx_Note() { var delta = Delta.New() .InsertChapter("1") .InsertVerse("1") .InsertText("This is a verse with a footnote", "verse_1_1") .InsertNote(0, Delta.New() .InsertChar("1.1: ", "fr") .InsertChar("Refers to ", "ft") .InsertChar("a footnote", "fq") .Insert(". ") .InsertChar("John 1:1", "xt") .Insert(" and ") .InsertChar("Mark 1:1", "xt") .Insert("."), "f", "+", "verse_1_1") .InsertText(", so that we can test it.", "verse_1_1") .InsertPara("p") .Insert("\n"); DeltaUsxMapper mapper = CreateMapper(); XElement newUsxElem = mapper.ToUsx("2.5", "PHM", null, delta); XElement expected = Usx("PHM", Chapter("1"), Para("p", Verse("1"), "This is a verse with a footnote", Note("f", "+", Char("fr", "1.1: "), Char("ft", "Refers to "), Char("fq", "a footnote"), ". ", Char("xt", "John 1:1"), " and ", Char("xt", "Mark 1:1"), "."), ", so that we can test it.")); Assert.IsTrue(XNode.DeepEquals(newUsxElem, expected)); }