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.
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.
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/>.
13 using Microsoft.VisualStudio.TestTools.UnitTesting;
19 public class FoldingCollectionTest
22 public void HiddenTest()
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));
34 public void HiddenParrentTest()
36 FoldingCollection collection = new FoldingCollection();
37 FoldingItem item = new FoldingItem(0, 10, false);
39 FoldingItem item1 = new FoldingItem(1, 5);
40 collection.Add(item1);
41 Assert.IsTrue(collection.IsParentHidden(item1));
42 Assert.IsTrue(!collection.IsParentHidden(item));
45 public void HasParrentTest()
47 FoldingCollection collection = new FoldingCollection();
48 FoldingItem item = new FoldingItem(0, 10, false);
50 FoldingItem item1 = new FoldingItem(1, 5);
51 collection.Add(item1);
52 Assert.IsTrue(collection.IsHasParent(item1));
53 Assert.IsTrue(!collection.IsHasParent(item));
56 public void GetFoldingItem()
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);
67 public void GetFarestFoldingItem()
69 FoldingCollection collection = new FoldingCollection();
70 FoldingItem item = new FoldingItem(0, 10);
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);
80 public void GetFoldingItems()
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));
91 public void CollapseFoldingItem()
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);
104 public void ExpandFoldingItem()
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);
117 public void UpdateItems()
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));