OSDN Git Service

29fc69f72f295fd114e5e719c95c6dc9b7532d3c
[fooeditengine/FooEditEngine.git] / WPF / UnitTest / UnitTest3.cs
1 /*
2  * Copyright (C) 2013 FooProject
3  * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
5
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10  */
11
12 using System;
13 using System.Collections.Generic;
14 using System.Linq;
15 using System.Text;
16 using System.Threading.Tasks;
17 using Microsoft.VisualStudio.TestTools.UnitTesting;
18 using FooEditEngine;
19
20 namespace UnitTest
21 {
22     [TestClass]
23     public class UnitTest3
24     {
25         [TestMethod]
26         public void UpdateLineTest()
27         {
28             Document doc = new Document();
29             DummyRender render = new DummyRender();
30             DummyView view = new DummyView(doc,render);
31             doc.Clear();
32             doc.Append("a\nb\nc");
33             Assert.IsTrue(view.LayoutLines[0] == "a\n" && view.LayoutLines[1] == "b\n" && view.LayoutLines[2] == "c");
34             doc.Replace(0, 3, "x");
35             Assert.IsTrue(view.LayoutLines[0] == "x\n");
36         }
37
38         [TestMethod]
39         public void QueryTest()
40         {
41             Document doc = new Document();
42             DummyRender render = new DummyRender();
43             DummyView view = new DummyView(doc, render);
44             doc.Clear();
45             doc.Append("a\nb\nc");
46             Assert.IsTrue(view.LayoutLines.GetIndexFromLineNumber(1) == 2);
47             Assert.IsTrue(view.LayoutLines.GetLengthFromLineNumber(1) == 2);
48             Assert.IsTrue(view.LayoutLines.GetLineNumberFromIndex(2) == 1);
49             TextPoint tp = view.LayoutLines.GetTextPointFromIndex(2);
50             Assert.IsTrue(tp.row == 1 && tp.col == 0);
51             Assert.IsTrue(view.LayoutLines.GetIndexFromTextPoint(tp) == 2);
52         }
53     }
54 }