1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Tests
17 using Castle
.MonoRail
.Framework
.TransformFilters
.Formatters
;
18 using NUnit
.Framework
;
21 public class WikiFormatTesting
26 public void BoldItalic()
28 string content
= "'''''replace me'''''";
29 string formatted
= new WikiFormatter().Format(content
);
30 string result
= "<b><i>replace me</i></b>" + "\n";
31 Assert
.IsTrue(result
.Equals(formatted
));
37 string content
= "'''replace me'''";
38 string formatted
= new WikiFormatter().Format(content
);
39 string result
= "<b>replace me</b>" + "\n";
40 Assert
.IsTrue(result
.Equals(formatted
));
46 string content
= "''replace me''";
47 string formatted
= new WikiFormatter().Format(content
);
48 string result
= "<i>replace me</i>" + "\n";
49 Assert
.IsTrue(result
.Equals(formatted
));
53 public void Underlined()
55 string content
= "__replace me__";
56 string formatted
= new WikiFormatter().Format(content
);
57 string result
= "<u>replace me</u>" + "\n";
58 Assert
.IsTrue(result
.Equals(formatted
));
64 string content
= "--replace me--";
65 string formatted
= new WikiFormatter().Format(content
);
66 string result
= "<strike>replace me</strike>" + "\n";
67 Assert
.IsTrue(result
.Equals(formatted
));
73 string content
= "{{replace me}}";
74 string formatted
= new WikiFormatter().Format(content
);
75 string result
= "<code>replace me</code>" + "\n";
76 Assert
.IsTrue(result
.Equals(formatted
));
82 string content
= "{{{{replace me}}}}";
83 string formatted
= new WikiFormatter().Format(content
);
84 string result
= "<pre>replace me</pre>" + "\n";
85 Assert
.IsTrue(result
.Equals(formatted
));
91 string content
= "(((replace me)))";
92 string formatted
= new WikiFormatter().Format(content
);
93 string result
= @"<table class=""box"" cellpadding=""0"" cellspacing=""0""><tr><td>replace me</td></tr></table>" +
95 Assert
.IsTrue(result
.Equals(formatted
));
100 #region Table testing
103 public void EmptyTableWithCaption()
105 string content
= "{|" + "\n" +
106 "|+ caption" + "\n" +
109 string table
= new WikiFormatter().Format(content
);
111 string result
= "<table>" +
112 "<caption>caption</caption>" +
115 Assert
.IsTrue(result
.Equals(table
));
119 public void TableWithCaptionAndTwoRows()
121 string content
= "{|" + "\n" +
122 "|+ The table's caption" + "\n" +
127 string table
= new WikiFormatter().Format(content
);
129 string result
= "<table><caption>The table's caption</caption><tr></tr><tr></tr></table>" + "\n";
131 Assert
.IsTrue(result
.Equals(table
));
135 public void TableWithCaptionAndTwoRowsAndCells()
137 string content
= "{|" + "\n" +
138 "|+ The table's caption" + "\n" +
140 "|Cell 1 || Cell 2 || Cell 3" + "\n" +
147 string table
= new WikiFormatter().Format(content
);
150 "<table><caption>The table's caption</caption><tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr><tr><td>Cell A</td><td>Cell B</td><td>Cell C</td></tr></table>" +
153 Assert
.IsTrue(result
.Equals(table
));
157 public void TableWithColumnHeadings()
159 string content
= "{|" + "\n" +
160 "|+ The table's caption" + "\n" +
161 "! Column heading 1 !! Column heading 2 !! Column heading 3" + "\n" +
163 "|Cell 1 || Cell 2 || Cell 3" + "\n" +
170 string table
= new WikiFormatter().Format(content
);
173 "<table><caption>The table's caption</caption><tr><th>Column heading 1</th><th>Column heading 2</th><th>Column heading 3</th></tr><tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr><tr><td>Cell A</td><td>Cell B</td><td>Cell C</td></tr></table>" +
176 Assert
.IsTrue(result
.Equals(table
));
180 public void TableWithColumnAndRowHeadings()
182 string content
= "{|" + "\n" +
183 "|+ The table's caption" + "\n" +
184 "! Column heading 1 !! Column heading 2 !! Column heading 3" + "\n" +
186 "! Row heading 1 " + "\n" +
187 "| Cell 2 || Cell 3" + "\n" +
189 "! Row heading A " + "\n" +
194 string table
= new WikiFormatter().Format(content
);
197 "<table><caption>The table's caption</caption><tr><th>Column heading 1</th><th>Column heading 2</th><th>Column heading 3</th></tr><tr><th>Row heading 1</th><td>Cell 2</td><td>Cell 3</td></tr><tr><th>Row heading A</th><td>Cell B</td><td>Cell C</td></tr></table>" +
200 Assert
.IsTrue(result
.Equals(table
));
204 public void MultiplicationTableTest()
206 string content
= "{| class=\"wikitable\" style=\"text-align:center\"" + "\n" +
207 "|+Multiplication table" + "\n" +
209 "! × !! 1 !! 2 !! 3" + "\n" +
212 "| 1 || 2 || 3" + "\n" +
215 "| 2 || 4 || 6" + "\n" +
218 "| 3 || 6 || 9" + "\n" +
221 "| 4 || 8 || 12" + "\n" +
224 "| 5 || 10 || 15" + "\n" +
227 string table
= new WikiFormatter().Format(content
);
230 "<table class=\"wikitable\" style=\"text-align:center\"><caption>Multiplication table</caption><tr><th>×</th><th>1</th><th>2</th><th>3</th></tr><tr><th>1</th><td>1</td><td>2</td><td>3</td></tr><tr><th>2</th><td>2</td><td>4</td><td>6</td></tr><tr><th>3</th><td>3</td><td>6</td><td>9</td></tr><tr><th>4</th><td>4</td><td>8</td><td>12</td></tr><tr><th>5</th><td>5</td><td>10</td><td>15</td></tr></table>" +
233 Assert
.IsTrue(result
.Equals(table
));
237 public void ColorTest()
239 string content
= "{|" + "\n" +
240 "| style=\"background:red; color:white\" | abc" + "\n" +
242 "| bgcolor=\"red\" | <font color=\"white\"> ghi </font>" + "\n" +
246 string table
= new WikiFormatter().Format(content
);
249 "<table><tr><td style=\"background:red; color:white\">abc</td><td>def</td><td bgcolor=\"red\"><font color=\"white\"> ghi </font></td><td>jkl</td></tr></table>" +
252 Assert
.IsTrue(result
.Equals(table
));
256 public void WidthHeightTest()
258 string content
= "{| style=\"width:75%; height:200px\" border=\"1\"" + "\n" +
260 "| abc || def || ghi" + "\n" +
261 "|- style=\"height:100px\" " + "\n" +
262 "| jkl || style=\"width:200px\" |mno || pqr" + "\n" +
264 "| stu || vwx || yz" + "\n" +
267 string table
= new WikiFormatter().Format(content
);
270 "<table style=\"width:75%; height:200px\" border=\"1\"><tr><td>abc</td><td>def</td><td>ghi</td></tr><tr style=\"height:100px\"><td>jkl</td><td style=\"width:200px\">mno</td><td>pqr</td></tr><tr><td>stu</td><td>vwx</td><td>yz</td></tr></table>" +
273 Assert
.IsTrue(result
.Equals(table
));
277 public void MoreMarkUpTesting()
279 string content
= "{| style=\"background:yellow; color:green\"" + "\n" +
281 "| abc || def || ghi" + "\n" +
282 "|- style=\"background:red; color:white\"" + "\n" +
283 "| jkl || mno || pqr" + "\n" +
285 "| stu || style=\"background:silver\" | vwx || yz" + "\n" +
288 string table
= new WikiFormatter().Format(content
);
291 "<table style=\"background:yellow; color:green\"><tr><td>abc</td><td>def</td><td>ghi</td></tr><tr style=\"background:red; color:white\"><td>jkl</td><td>mno</td><td>pqr</td></tr><tr><td>stu</td><td style=\"background:silver\">vwx</td><td>yz</td></tr></table>" +
294 Assert
.IsTrue(result
.Equals(table
));
298 public void ColumnWidthTest()
300 string content
= "{| border=\"1\" cellpadding=\"2\"" + "\n" +
301 "!width=\"50\"|Name" + "\n" +
302 "!width=\"225\"|Effect" + "\n" +
303 "!width=\"225\"|Games Found In" + "\n" +
305 "|Poké Ball || Regular Poké Ball || All Versions" + "\n" +
307 "|Great Ball || Better than a Poké Ball || All Versions" + "\n" +
310 string table
= new WikiFormatter().Format(content
);
313 "<table border=\"1\" cellpadding=\"2\"><tr><th width=\"50\">Name</th><th width=\"225\">Effect</th><th width=\"225\">Games Found In</th></tr><tr><td>Poké Ball</td><td>Regular Poké Ball</td><td>All Versions</td></tr><tr><td>Great Ball</td><td>Better than a Poké Ball</td><td>All Versions</td></tr></table>" +
316 Assert
.IsTrue(result
.Equals(table
));
320 public void VerticalAlignment()
322 string content
= "{| border=\"1\" cellpadding=\"2\"" + "\n" +
323 "|-valign=\"top\"" + "\n" +
324 "|width=\"10%\"|<b>Row heading</b>" + "\n" +
325 "|width=\"70%\"|A longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." +
327 "|width=\"20%\"|A shorter piece of text." + "\n" +
328 "|-valign=\"top\"" + "\n" +
329 "|<b>Row heading</b>" + "\n" +
330 "|A longer piece of text.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." +
332 "|A shorter piece of text." + "\n" +
335 string table
= new WikiFormatter().Format(content
);
338 "<table border=\"1\" cellpadding=\"2\"><tr valign=\"top\"><td width=\"10%\"><b>Row heading</b></td><td width=\"70%\">A longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</td><td width=\"20%\">A shorter piece of text.</td></tr><tr valign=\"top\"><td><b>Row heading</b></td><td>A longer piece of text.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</td><td>A shorter piece of text.</td></tr></table>" +
341 Assert
.IsTrue(result
.Equals(table
));