OSDN Git Service

51c92736f8f655522ece5631195f1bad389737df
[fooeditengine/FooEditEngine.git] / WPF / UnitTest / UnitTest1.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 using System;
12 using System.Linq;
13 using Microsoft.VisualStudio.TestTools.UnitTesting;
14 using FooEditEngine;
15
16 namespace UnitTest
17 {
18     [TestClass]
19     public class FoldingCollectionTest
20     {
21         [TestMethod]
22         public void GetFoldingItem()
23         {
24             FoldingCollection collection = new FoldingCollection();
25             collection.Add(new FoldingItem(0, 10));
26             collection.Add(new FoldingItem(1, 5));
27             collection.Add(new FoldingItem(11, 12));
28             FoldingItem item = collection.Get(2, 1);
29             Assert.IsTrue(item.Start == 1 && item.End == 5);
30         }
31
32         [TestMethod]
33         public void GetFarestFoldingItem()
34         {
35             FoldingCollection collection = new FoldingCollection();
36             FoldingItem item = new FoldingItem(0, 10);
37             item.Expand = false;
38             collection.Add(item);
39             collection.Add(new FoldingItem(1, 5));
40             collection.Add(new FoldingItem(11,12));
41             item = collection.GetFarestHiddenFoldingData(2, 1);
42             Assert.IsTrue(item.Start == 0 && item.End == 10);
43         }
44
45         [TestMethod]
46         public void GetFoldingItems()
47         {
48             FoldingCollection collection = new FoldingCollection();
49             collection.Add(new FoldingItem(0, 10));
50             collection.Add(new FoldingItem(1, 5));
51             collection.Add(new FoldingItem(11, 12));
52             foreach (FoldingItem item in collection.GetRange(0, 10))
53                 Assert.IsTrue((item.Start != 11 && item.End != 12));
54         }
55
56         [TestMethod]
57         public void CollapseFoldingItem()
58         {
59             FoldingCollection collection = new FoldingCollection();
60             FoldingItem newItem = new FoldingItem(0,10);
61             collection.Add(newItem);
62             collection.Add(new FoldingItem(1, 5));
63             collection.Add(new FoldingItem(11, 12));
64             collection.Collapse(newItem);
65             foreach (FoldingItem item in collection.GetRange(0, 10))
66                 Assert.IsFalse(item.Expand);
67         }
68
69         [TestMethod]
70         public void ExpandFoldingItem()
71         {
72             FoldingCollection collection = new FoldingCollection();
73             collection.Add(new FoldingItem(0, 10));
74             FoldingItem newItem = new FoldingItem(1, 5);
75             collection.Add(newItem);
76             collection.Add(new FoldingItem(11, 12));
77             collection.Expand(newItem);
78             foreach (FoldingItem item in collection.GetRange(0, 10))
79                 Assert.IsTrue(item.Expand);
80         }
81
82         [TestMethod]
83         public void UpdateItems()
84         {
85             DummyRender render = new DummyRender();
86             Document doc = new Document(render);
87             FoldingCollection collection = new FoldingCollection();
88             collection.Add(new FoldingItem(0, 10));
89             collection.Add(new FoldingItem(1, 5));
90             collection.Add(new FoldingItem(15, 20));
91             collection.Add(new FoldingItem(16, 17));
92             collection.UpdateData(doc, 11, 1, 0);
93             FoldingItem[] result = collection.GetRange(16, 4).ToArray();
94             Assert.IsTrue((result[0].Start == 16 && result[0].End == 21));
95             Assert.IsTrue((result[1].Start == 17 && result[1].End == 18));
96             collection.UpdateData(doc, 11, 0, 1);
97             result = collection.GetRange(16, 4).ToArray();
98             Assert.IsTrue((result[0].Start == 15 && result[0].End == 20));
99             Assert.IsTrue((result[1].Start == 16 && result[1].End == 17));
100         }
101     }
102 }