public void TestFeedTokenDoesNotMarkTokenAsBookmarkIfOtherTokenWithSameRootOutOfScope() { int size = 2; Scope target = new Scope(size); OxmlToken token1 = new OxmlToken("text1", "rootx", null); OxmlToken token2 = new OxmlToken("text2", "rooty", null); OxmlToken token3 = new OxmlToken("text3", "rootx", null); target.FeedToken(token1); target.FeedToken(token2); target.FeedToken(token3); Assert.IsFalse(token3.Bookmarked); }
public void TestFeedTokenDoesNotMarkTokensAsBookmarkIfTextLengthBelowThreshold() { int size = 2; Scope target = new Scope(size); target.MinimumTokenLength = 6; OxmlToken token1 = new OxmlToken("text1", "root", null); OxmlToken token2 = new OxmlToken("text2", "root", null); target.FeedToken(token1); target.FeedToken(token2); Assert.IsFalse(token1.Bookmarked); Assert.IsFalse(token2.Bookmarked); }
public void TestFeedTokenMarksTokenAsBookmarkIfOtherTokenWithSameRoot() { int size = 3; Scope target = new Scope(size); OxmlToken token1 = new OxmlToken("text1", "root", null); OxmlToken token2 = new OxmlToken("text2", "root", null); target.FeedToken(token1); target.FeedToken(token2); Assert.IsTrue(token2.Bookmarked); }
public void TestScopeThrowsArgExWhenSizeLowerThanMinSize() { int size = Scope.minimumSize - 1; bool thrown = false; try { Scope target = new Scope(size); } catch (ArgumentException) { thrown = true; } Assert.IsTrue(thrown); }
public void TestGetConflictsReturnsDict() { int size = 3; Scope target = new Scope(size); var token1 = new OxmlToken("text1", "rootx", null); var token2 = new OxmlToken("text2", "rooty", null); var token3 = new OxmlToken("text3", "rootx", null); var token4 = new OxmlToken("text4", "rooty", null); target.FeedToken(token1); target.FeedToken(token2); target.FeedToken(token3); target.FeedToken(token4); var d = target.GetConflicts(); Assert.IsTrue(d["rootx"].Count == 1); Assert.IsTrue(d["rootx"][0].Contains(token1)); Assert.IsTrue(d["rootx"][0].Contains(token3)); Assert.IsTrue(d["rooty"].Count == 1); Assert.IsTrue(d["rooty"][0].Contains(token2)); Assert.IsTrue(d["rooty"][0].Contains(token4)); }
public void TestFeedTokenStoresBookmarkedTokenOnlyOnce() { // When a root occurs more than twice in a scope, it could be // bookmarked and stored mored than once. // This used to be a bug. This test verifies tehe fix. int size = 3; Scope target = new Scope(size); OxmlToken token1 = new OxmlToken("text1", "root", null); OxmlToken token2 = new OxmlToken("text2", "root", null); OxmlToken token3 = new OxmlToken("text3", "root", null); target.FeedToken(token1); target.FeedToken(token2); target.FeedToken(token3); Assert.AreEqual(3, target.GetConflicts()["root"][0].Count); }
public void TestFeedTokenMarksTokensAsBookmarksWithUniqueBookmarkNames() { int size = 2; Scope target = new Scope(size); OxmlToken token1 = new OxmlToken("text1", "root", null); OxmlToken token2 = new OxmlToken("text2", "root", null); OxmlToken token3 = new OxmlToken("text3", "root", null); target.FeedToken(token1); target.FeedToken(token2); target.FeedToken(token3); Assert.AreNotEqual(token1.BookmarkName, token2.BookmarkName); Assert.AreNotEqual(token1.BookmarkName, token3.BookmarkName); Assert.AreNotEqual(token2.BookmarkName, token3.BookmarkName); }
/*-----------------------------------------------------------------------------------------*/ /* Background worker */ /*-----------------------------------------------------------------------------------------*/ private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; OxmlDocument doc = new OxmlDocument(this.GetOXML()); Scope scope = new Scope(Properties.Settings.Default.ScopeSize); scope.MinimumTokenLength = Properties.Settings.Default.MinimumTokenLength; doc.PurgeShading(); doc.PurgeBookmarks(); // Load ignore list if (!String.IsNullOrEmpty(_ignoreListName)) { IgnoreList IgnoreList = new IgnoreList(GetListPath(_ignoreListName)); scope.IgnoreWords(IgnoreList.LoadWords(_language)); } // Analyse document int blockCount = 0; float numberOfBlocks = (float)doc.GetNumberOfBlocks(); var block = doc.GetNextOxmlBlock(); while (block != null) { var tokens = block.GenerateOxmlTokens(); foreach (var token in tokens) { scope.FeedToken(token); } block = doc.GetNextOxmlBlock(); if (worker.CancellationPending == true) { e.Cancel = true; break; } int progress = (int)(++blockCount / numberOfBlocks * 100); worker.ReportProgress(progress); } // Add bookmarks to document var conflicts = scope.GetConflicts(); foreach (var root in conflicts.Keys) { foreach (var conflict in conflicts[root]) { foreach (var token in conflict) { Debug.WriteLine(String.Format("Adding bookmark {0} for root '{1}' with text '{2}' and range {3}", token.BookmarkName, token.Root, token.Text, token.Range.ToString())); doc.BookmarkRange(token.Range, token.BookmarkName); } } } // Update OXML only if it is valid string oxml = doc.ToOxml(); if (oxml != null) { this._conflicts = conflicts; this.SetOXML(doc.ToOxml()); } else { MessageBox.Show("An error occured while processing this document.", "Eagle Add-In"); } }