OSDN Git Service

FoldingItem.Parentを廃止した。これに伴い、FoldingCollectionにいくつかのメソッドを追加した
[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 HiddenTest()
23         {
24             FoldingCollection collection = new FoldingCollection();
25             collection.Add(new FoldingItem(0, 10,false));
26             collection.Add(new FoldingItem(1, 5));
27             Assert.IsTrue(collection.IsHidden(2));
28             collection = new FoldingCollection();
29             collection.Add(new FoldingItem(0, 10));
30             collection.Add(new FoldingItem(1, 5,false));
31             Assert.IsTrue(collection.IsHidden(2));
32         }
33         [TestMethod]
34         public void HiddenParrentTest()
35         {
36             FoldingCollection collection = new FoldingCollection();
37             FoldingItem item = new FoldingItem(0, 10, false);
38             collection.Add(item);
39             FoldingItem item1 = new FoldingItem(1, 5);
40             collection.Add(item1);
41             Assert.IsTrue(collection.IsParentHidden(item1));
42             Assert.IsTrue(!collection.IsParentHidden(item));
43         }
44         [TestMethod]
45         public void HasParrentTest()
46         {
47             FoldingCollection collection = new FoldingCollection();
48             FoldingItem item = new FoldingItem(0, 10, false);
49             collection.Add(item);
50             FoldingItem item1 = new FoldingItem(1, 5);
51             collection.Add(item1);
52             Assert.IsTrue(collection.IsHasParent(item1));
53             Assert.IsTrue(!collection.IsHasParent(item));
54         }
55         [TestMethod]
56         public void GetFoldingItem()
57         {
58             FoldingCollection collection = new FoldingCollection();
59             collection.Add(new FoldingItem(0, 10));
60             collection.Add(new FoldingItem(1, 5));
61             collection.Add(new FoldingItem(11, 12));
62             FoldingItem item = collection.Get(2, 1);
63             Assert.IsTrue(item.Start == 1 && item.End == 5);
64         }
65
66         [TestMethod]
67         public void GetFarestFoldingItem()
68         {
69             FoldingCollection collection = new FoldingCollection();
70             FoldingItem item = new FoldingItem(0, 10);
71             item.Expand = false;
72             collection.Add(item);
73             collection.Add(new FoldingItem(1, 5));
74             collection.Add(new FoldingItem(11,12));
75             item = collection.GetFarestHiddenFoldingData(2, 1);
76             Assert.IsTrue(item.Start == 0 && item.End == 10);
77         }
78
79         [TestMethod]
80         public void GetFoldingItems()
81         {
82             FoldingCollection collection = new FoldingCollection();
83             collection.Add(new FoldingItem(0, 10));
84             collection.Add(new FoldingItem(1, 5));
85             collection.Add(new FoldingItem(11, 12));
86             foreach (FoldingItem item in collection.GetRange(0, 10))
87                 Assert.IsTrue((item.Start != 11 && item.End != 12));
88         }
89
90         [TestMethod]
91         public void CollapseFoldingItem()
92         {
93             FoldingCollection collection = new FoldingCollection();
94             FoldingItem newItem = new FoldingItem(0,10);
95             collection.Add(newItem);
96             collection.Add(new FoldingItem(1, 5));
97             collection.Add(new FoldingItem(11, 12));
98             collection.Collapse(newItem);
99             foreach (FoldingItem item in collection.GetRange(0, 10))
100                 Assert.IsFalse(item.Expand);
101         }
102
103         [TestMethod]
104         public void ExpandFoldingItem()
105         {
106             FoldingCollection collection = new FoldingCollection();
107             collection.Add(new FoldingItem(0, 10));
108             FoldingItem newItem = new FoldingItem(1, 5);
109             collection.Add(newItem);
110             collection.Add(new FoldingItem(11, 12));
111             collection.Expand(newItem);
112             foreach (FoldingItem item in collection.GetRange(0, 10))
113                 Assert.IsTrue(item.Expand);
114         }
115
116         [TestMethod]
117         public void UpdateItems()
118         {
119             DummyRender render = new DummyRender();
120             Document doc = new Document();
121             doc.LayoutLines.Render = render;
122             FoldingCollection collection = new FoldingCollection();
123             collection.Add(new FoldingItem(0, 10));
124             collection.Add(new FoldingItem(1, 5));
125             collection.Add(new FoldingItem(15, 20));
126             collection.Add(new FoldingItem(16, 17));
127             collection.UpdateData(doc, 11, 1, 0);
128             FoldingItem[] result = collection.GetRange(16, 4).ToArray();
129             Assert.IsTrue((result[0].Start == 16 && result[0].End == 21));
130             Assert.IsTrue((result[1].Start == 17 && result[1].End == 18));
131             collection.UpdateData(doc, 11, 0, 1);
132             result = collection.GetRange(16, 4).ToArray();
133             Assert.IsTrue((result[0].Start == 15 && result[0].End == 20));
134             Assert.IsTrue((result[1].Start == 16 && result[1].End == 17));
135         }
136     }
137 }