public void QueryTest() { DummyRender render = new DummyRender(); Document doc = new Document(); doc.LayoutLines.Render = render; DummyView view = new DummyView(doc, render); doc.Clear(); doc.Append("a\nb\nc"); Assert.IsTrue(view.LayoutLines.GetIndexFromLineNumber(1) == 2); Assert.IsTrue(view.LayoutLines.GetLengthFromLineNumber(1) == 2); Assert.IsTrue(view.LayoutLines.GetLineNumberFromIndex(2) == 1); TextPoint tp = view.LayoutLines.GetTextPointFromIndex(2); Assert.IsTrue(tp.row == 1 && tp.col == 0); Assert.IsTrue(view.LayoutLines.GetIndexFromTextPoint(tp) == 2); doc.Insert(2, "a"); Assert.IsTrue(view.LayoutLines.GetIndexFromLineNumber(2) == 5); Assert.IsTrue(view.LayoutLines.GetLineNumberFromIndex(5) == 2); tp = view.LayoutLines.GetTextPointFromIndex(5); Assert.IsTrue(tp.row == 2 && tp.col == 0); Assert.IsTrue(view.LayoutLines.GetIndexFromTextPoint(tp) == 5); doc.Insert(0, "a"); Assert.IsTrue(view.LayoutLines.GetIndexFromLineNumber(2) == 6); Assert.IsTrue(view.LayoutLines.GetLineNumberFromIndex(6) == 2); tp = view.LayoutLines.GetTextPointFromIndex(6); Assert.IsTrue(tp.row == 2 && tp.col == 0); Assert.IsTrue(view.LayoutLines.GetIndexFromTextPoint(tp) == 6); }
public void TryPixelScrollTest() { DummyRender render = new DummyRender(); Document doc = new Document(); doc.LayoutLines.Render = render; DummyView view = new DummyView(doc, render); view.PageBound = new Rectangle(0, 0, 100, 30); doc.Clear(); doc.Append("a\nb\nc\nd"); bool result; result = view.TryScroll(0.0, 30.0); Assert.AreEqual(result, false); result = view.TryScroll(0.0, 30.0); Assert.AreEqual(result, false); result = view.TryScroll(0.0, 30.0); Assert.AreEqual(result, true); result = view.TryScroll(0.0, 30.0); Assert.AreEqual(result, true); Assert.AreEqual(doc.Src.Row, 3); result = view.TryScroll(0.0, -30.0); Assert.AreEqual(result, false); result = view.TryScroll(0.0, -30.0); Assert.AreEqual(result, false); result = view.TryScroll(0.0, -30.0); Assert.AreEqual(result, true); result = view.TryScroll(0.0, -30.0); Assert.AreEqual(doc.Src.Row, 0); Assert.AreEqual(result, true); }
public void RemoveSingleLineTest() { DummyRender render = new DummyRender(); Document doc = new Document(); doc.LayoutLines.Render = render; DummyView view = new DummyView(doc, render); doc.Clear(); doc.Append("aa\nbb\ncc\ndd"); doc.Remove(9, 1); Assert.IsTrue( view.LayoutLines[0] == "aa\n" && view.LayoutLines[1] == "bb\n" && view.LayoutLines[2] == "cc\n" && view.LayoutLines[3] == "d" ); doc.Remove(9, 1); Assert.IsTrue( view.LayoutLines[0] == "aa\n" && view.LayoutLines[1] == "bb\n" && view.LayoutLines[2] == "cc\n" && view.LayoutLines[3] == "" ); doc.Remove(0, 1); Assert.IsTrue( view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "bb\n" && view.LayoutLines[2] == "cc\n" && view.LayoutLines[3] == "" ); }
public void TestChangesRegisteredProperlyAfterNotifyViewFlushesChanges() { List <int[]> moves = new List <int[]>() { ar(1, 3), ar(4, 4) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); bg.Move(White, 6, 3); var changes = bg.GetChanges(); Assert.AreEqual(3, changes.Count()); var c1 = changes[0]; var c2 = changes[1]; var c3 = changes[2]; Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state"); Assert.IsTrue(c2.IsMove(), "c2 is not move"); Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state"); Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues())); Assert.AreEqual("w 6 3", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues())); //At least one view has to be present for backgammon game to flush the recent changes View view = new DummyView(); bg.ConnectView(view); bg.NotifyAllViews(); //Disconnecting the view again so that we may read the changes bg.DisconnectView(view); changes = bg.GetChanges(); Assert.AreEqual(0, changes.Count()); bg.Move(White, 6, 5); changes = bg.GetChanges(); Assert.AreEqual(2, changes.Count()); var c4 = changes[0]; var c5 = changes[1]; Assert.IsTrue(c4.IsMove()); Assert.IsTrue(c5.IsDiceState()); Assert.AreEqual("w 6 5", c4.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 4, 4, 4, 4 }, c5.AsDiceState().GetDiceValues())); }
public void RemoveMultiLineTest() { DummyRender render = new DummyRender(); Document doc = new Document(); doc.LayoutLines.Render = render; DummyView view = new DummyView(doc, render); doc.Clear(); doc.Append("a\n"); doc.Append("b\n"); doc.Append("c\n"); doc.Append("d\n"); doc.Append("e\n"); doc.Append("f\n"); doc.Remove(2, 4); Assert.IsTrue( view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "d\n" && view.LayoutLines[2] == "e\n" && view.LayoutLines[3] == "f\n"); doc.Remove(4, 4); Assert.IsTrue( view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "d\n"); doc.Clear(); doc.Append("a\n"); doc.Append("b\n"); doc.Append("c\n"); doc.Append("d\n"); doc.Remove(2, 6); Assert.IsTrue(view.LayoutLines[0] == "a\n"); doc.Clear(); doc.Append("a\n"); doc.Append("b\n"); doc.Append("c\n"); doc.Append("d\n"); doc.Append("e\n"); doc.Append("f\n"); doc.Insert(4, "a"); doc.Remove(2, 5); Assert.IsTrue( view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "d\n" && view.LayoutLines[2] == "e\n" && view.LayoutLines[3] == "f\n"); }
public void InsertSingleLineTest() { DummyRender render = new DummyRender(); Document doc = new Document(); doc.LayoutLines.Render = render; DummyView view = new DummyView(doc, render); doc.Clear(); doc.Append("a\nb\nc\nd"); Assert.IsTrue(view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "b\n" && view.LayoutLines[2] == "c\n" && view.LayoutLines[3] == "d"); doc.Insert(2, "x"); Assert.IsTrue(view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "xb\n" && view.LayoutLines[2] == "c\n" && view.LayoutLines[3] == "d"); doc.Insert(3, "x"); Assert.IsTrue(view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "xxb\n" && view.LayoutLines[2] == "c\n" && view.LayoutLines[3] == "d"); doc.Insert(6, "x"); Assert.IsTrue(view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "xxb\n" && view.LayoutLines[2] == "xc\n" && view.LayoutLines[3] == "d"); doc.Insert(0, "x"); Assert.IsTrue(view.LayoutLines[0] == "xa\n" && view.LayoutLines[1] == "xxb\n" && view.LayoutLines[2] == "xc\n" && view.LayoutLines[3] == "d"); }
public void InsertMultiLineTest() { DummyRender render = new DummyRender(); Document doc = new Document(); doc.LayoutLines.Render = render; DummyView view = new DummyView(doc, render); doc.Clear(); doc.Append("a\nb\nc\nd"); doc.Insert(2, "f\ne"); Assert.IsTrue( view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "f\n" && view.LayoutLines[2] == "eb\n" && view.LayoutLines[3] == "c\n" && view.LayoutLines[4] == "d"); doc.Insert(3, "g\nh"); Assert.IsTrue( view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "fg\n" && view.LayoutLines[2] == "h\n" && view.LayoutLines[3] == "eb\n" && view.LayoutLines[4] == "c\n" && view.LayoutLines[5] == "d"); doc.Insert(0, "x\ny"); Assert.IsTrue( view.LayoutLines[0] == "x\n" && view.LayoutLines[1] == "ya\n" && view.LayoutLines[2] == "fg\n" && view.LayoutLines[3] == "h\n" && view.LayoutLines[4] == "eb\n" && view.LayoutLines[5] == "c\n" && view.LayoutLines[6] == "d"); }
public void WatchDogTest() { RegexMarkerPattern dog = new RegexMarkerPattern(new Regex("h[a-z]+"), HilightType.Url, new Color(0, 0, 0, 255)); IEnumerable <Marker> result = new List <Marker>() { Marker.Create(0, 4, HilightType.Url, new Color(0, 0, 0, 255)), Marker.Create(5, 4, HilightType.Url, new Color(0, 0, 0, 255)) }; string str = "html haml"; DummyRender render = new DummyRender(); Document doc = new Document(); doc.LayoutLines.Render = render; DummyView view = new DummyView(doc, render); doc.MarkerPatternSet.Add(MarkerIDs.Defalut, dog); doc.Clear(); doc.Append(str); IEnumerable <Marker> actual = doc.MarkerPatternSet.GetMarkers(new CreateLayoutEventArgs(0, str.Length, str)); this.AreEqual(result, actual); }