public void TestEqualsReturnsFalseForDiffBookmarkNameProperty() { OxmlToken a = new OxmlToken("Text", "root", null); OxmlToken b = new OxmlToken("Text", "root", null); b.BookmarkName = "b"; Assert.IsFalse(a.Equals(b)); }
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 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 TestGenerateOxmlTokensReturnsOxmlTokens() { string text = "This is a test."; int id = 1; OxmlBlock target = new OxmlBlock(text, id); var expected = new OxmlToken[4]; expected[0] = new OxmlToken("This", "this", new OxmlRange(id, 0, 4)); expected[1] = new OxmlToken("is", "is", new OxmlRange(id, 5, 7)); expected[2] = new OxmlToken("a", "a", new OxmlRange(id, 8, 9)); expected[3] = new OxmlToken("test", "test", new OxmlRange(id, 10, 14)); var actual = target.GenerateOxmlTokens(); Assert.AreEqual(expected.GetLength(0), actual.GetLength(0)); Assert.IsTrue(expected[0].Equals(actual[0])); Assert.IsTrue(expected[1].Equals(actual[1])); Assert.IsTrue(expected[2].Equals(actual[2])); Assert.IsTrue(expected[3].Equals(actual[3])); }
public void FeedToken(OxmlToken token) { Debug.WriteLine(String.Format("Processing token '{0}' ('{1}')", token.Text, token.Root)); // Ensure queue does not exceed scope size if (this._tokens.Count >= this._size) { this._tokens.Dequeue(); } // Ignore small tokens if (token.Text.Length < this._minimumTokenLength) { // If smaller tokens are condidered relevant for scope size, // enqueue a dummy token and process it accordingly later on. // this._tokens.Enqueue(null); return; } // Ignore words from ignore list if (this._wordsToIgnore.Contains(token.Text)) return; // Check for multiple occurrences foreach (var otherToken in this._tokens) { if (otherToken.Root == token.Root) { if (!otherToken.Bookmarked) { otherToken.BookmarkName = GenerateBookmarkName(token.Root); this.StoreToken(otherToken, true); } token.BookmarkName = GenerateBookmarkName(token.Root); this.StoreToken(token, false); break; } } this._tokens.Enqueue(token); }
public void TestEqualsReturnsFalseForDiffTextProperty() { OxmlToken a = new OxmlToken("Text", "root", null); OxmlToken b = new OxmlToken("text", "root", null); Assert.IsFalse(a.Equals(b)); }
public void TestCompareReturnsTrueIfAllPropertiesEqual() { OxmlToken a = new OxmlToken("Text", "root", null); OxmlToken b = new OxmlToken("Text", "root", null); Assert.IsTrue(a.Equals(b)); }
public void TestBookmarkedReturnsTrueIfTokenIsBookmarked() { OxmlToken target = new OxmlToken("Text", "root", null); target.BookmarkName = "name"; Assert.IsTrue(target.Bookmarked); }
public void TestBookmarkedReturnsFalseIfTokenIsNotBookmarked() { OxmlToken target = new OxmlToken("Text", "root", null); Assert.IsFalse(target.Bookmarked); }
public void TestEqualsReturnsFalseIfOtherIsNull() { OxmlToken a = new OxmlToken("Text", "root", null); OxmlToken b = new OxmlToken("Text", "root", null); b.BookmarkName = "b"; Assert.IsFalse(a.Equals(b)); }
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 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); }
private void StoreToken(OxmlToken token, bool newConflict) { if (newConflict) { if (!this._conflicts.ContainsKey(token.Root)) { this._conflicts[token.Root] = new List<List<OxmlToken>>(); } this._conflicts[token.Root].Add(new List<OxmlToken>()); } this._conflicts[token.Root][this._conflicts[token.Root].Count - 1].Add(token); }