Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 954252314de77662c344d991623b9bedd9c7bf41 @madskristensen committed Jan 22, 2013
@@ -0,0 +1,52 @@
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Collections.Generic;
+using System.Text;
+using P = ZenCoding.Parser;
+
+namespace ZenCoding.Test
+{
+ [TestClass]
+ public class Anonymous
+ {
+ private ZenCoding.Parser _parser;
+
+ [TestInitialize]
+ public void Initialize()
+ {
+ _parser = new ZenCoding.Parser();
+ }
+
+ [TestMethod]
+ public void Anonymous1()
+ {
+ string result = _parser.Parse("#name", ZenType.HTML);
+
+ Assert.AreEqual("<div id=\"name\"></div>", result);
+ }
+
+ [TestMethod]
+ public void Anonymous2()
+ {
+ string result = _parser.Parse("#name.item", ZenType.HTML);
+
+ Assert.AreEqual("<div id=\"name\" class=\"item\"></div>", result);
+ }
+
+ [TestMethod]
+ public void Anonymous3()
+ {
+ string result = _parser.Parse("footer+#name.item", ZenType.HTML);
+
+ Assert.AreEqual("<footer></footer><div id=\"name\" class=\"item\"></div>", result);
+ }
+
+ [TestMethod]
+ public void Anonymous4()
+ {
+ string result = _parser.Parse("#name>.item", ZenType.HTML);
+
+ Assert.AreEqual("<div id=\"name\"><div class=\"item\"></div></div>", result.Replace(Environment.NewLine, string.Empty));
+ }
+ }
+}
@@ -0,0 +1,101 @@
+
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Collections.Generic;
+using System.Text;
+
+namespace ZenCoding.Test
+{
+ [TestClass]
+ public class Attributes
+ {
+ private ZenCoding.Parser _parser;
+
+ [TestInitialize]
+ public void Initialize()
+ {
+ _parser = new ZenCoding.Parser();
+ }
+
+ [TestMethod]
+ public void Attributes1()
+ {
+ string result = _parser.Parse("p[title]", ZenType.HTML);
+ string expected = "<p title=\"\"></p>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void Attributes2()
+ {
+ string result = _parser.Parse("td[colspan title]", ZenType.HTML);
+ string expected = "<td colspan=\"\" title=\"\"></td>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void Attributes3()
+ {
+ string result = _parser.Parse("td[colspan=2]", ZenType.HTML);
+ string expected = "<td colspan=\"2\"></td>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void Attributes4()
+ {
+ string result = _parser.Parse("span[title=\"Hello\" rel]", ZenType.HTML);
+ string expected = "<span title=\"Hello\" rel=\"\"></span>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void Attributes5()
+ {
+ string result = _parser.Parse("a[title=\"Hello world\"]", ZenType.HTML);
+ string expected = "<a href=\"\" title=\"Hello world\"></a>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void Attributes6()
+ {
+ string result = _parser.Parse("a[title=\"Hello world\" rel]", ZenType.HTML);
+ string expected = "<a href=\"\" title=\"Hello world\" rel=\"\"></a>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void AttributesAfterId()
+ {
+ string result = _parser.Parse("div#main[prop=val]", ZenType.HTML);
+ string expected = "<div id=\"main\" prop=\"val\"></div>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void AttributesMultiple()
+ {
+ string result = _parser.Parse("a[prop=val][href=ost] ", ZenType.HTML);
+ string expected = "<a href=\"ost\" prop=\"val\"></a>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void AttributesHrefDefault()
+ {
+ string result = _parser.Parse("a[href=#] ", ZenType.HTML);
+ string expected = "<a href=\"#\"></a>";
+
+ Assert.AreEqual(expected, result);
+ }
+}
+}
@@ -0,0 +1,110 @@
+
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Collections.Generic;
+using System.Text;
+using P = ZenCoding.Parser;
+
+namespace ZenCoding.Test
+{
+ [TestClass]
+ public class ClimbUp
+ {
+ private ZenCoding.Parser _parser;
+
+ [TestInitialize]
+ public void Initialize()
+ {
+ _parser = new ZenCoding.Parser();
+ }
+
+ [TestMethod]
+ public void ClimbUpSimple()
+ {
+ string result = _parser.Parse("div+div>p>span+em^bq", ZenType.HTML);
+ string expected = "<div></div>" +
+ "<div>" +
+ "<p><span></span><em></em></p>" +
+ "<blockquote></blockquote>" +
+ "</div>";
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void ClimbUpException()
+ {
+ string result = _parser.Parse("em^^^^bq", ZenType.HTML);
+ string expected = "<em></em><blockquote></blockquote>";
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void ClimbUpMultiple()
+ {
+ string result = _parser.Parse("div+div>p>span+em^^^bq", ZenType.HTML);
+ string expected = "<div></div>" +
+ "<div>" +
+ "<p><span></span><em></em></p>" +
+ "</div>" +
+ "<blockquote></blockquote>";
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void ClimbUpWithAttributes()
+ {
+ string result = _parser.Parse("p.test^p.cake", ZenType.HTML);
+ string expected = "<p class=\"test\"></p>" +
+ "<p class=\"cake\"></p>";
+
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void ClimbUpWithAttributes2()
+ {
+ string result = _parser.Parse("p.test>span.test^p.cake", ZenType.HTML);
+ string expected = "<p class=\"test\">" +
+ "<span class=\"test\"></span>" +
+ "</p>" +
+ "<p class=\"cake\"></p>";
+
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void ClimbUpWithCount()
+ {
+ string result = _parser.Parse("li*2^p", ZenType.HTML);
+ string expected = "<li></li><li></li><p></p>";
+
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void ClimbUpWithCount2()
+ {
+ string result = _parser.Parse("ul>li*2^p", ZenType.HTML);
+ string expected = "<ul><li></li><li></li></ul><p></p>";
+
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void ClimbUp2()
+ {
+ string result = _parser.Parse("div>ul>li^^p", ZenType.HTML);
+ string expected = "<div><ul><li></li></ul></div><p></p>";
+
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+ }
+}
@@ -0,0 +1,107 @@
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Collections.Generic;
+using System.Text;
+
+namespace ZenCoding.Test
+{
+ [TestClass]
+ public class Count
+ {
+ private ZenCoding.Parser _parser;
+
+ [TestInitialize]
+ public void Initialize()
+ {
+ _parser = new ZenCoding.Parser();
+ }
+
+ [TestMethod]
+ public void CountSimple1()
+ {
+ string result = _parser.Parse("p*3", ZenType.HTML);
+ string expected = "<p></p>" +
+ "<p></p>" +
+ "<p></p>";
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void CountSimple2()
+ {
+ string result = _parser.Parse("div#name>p*2", ZenType.HTML);
+ string expected = "<div id=\"name\">" +
+ "<p></p>" +
+ "<p></p>" +
+ "</div>";
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void CountComplex()
+ {
+ string result = _parser.Parse("div#page>div.logo+ul#navigation>li*5>a", ZenType.HTML);
+ string expected = "<div id=\"page\">" +
+ "<div class=\"logo\"></div>" +
+ "<ul id=\"navigation\">" +
+ "<li><a href=\"\"></a></li>" +
+ "<li><a href=\"\"></a></li>" +
+ "<li><a href=\"\"></a></li>" +
+ "<li><a href=\"\"></a></li>" +
+ "<li><a href=\"\"></a></li>" +
+ "</ul>" +
+ "</div>";
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void CountClass()
+ {
+ string result = _parser.Parse("ul#name>li.item*3", ZenType.HTML);
+ string expected = "<ul id=\"name\">" +
+ "<li class=\"item\"></li>" +
+ "<li class=\"item\"></li>" +
+ "<li class=\"item\"></li>" +
+ "</ul>";
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void CountMultiNesting()
+ {
+ string result = _parser.Parse("table>tr>td#idc$*4>img[onclick]", ZenType.HTML);
+ string expected = "<table><tr>" +
+ "<td id=\"idc1\"><img src=\"\" alt=\"\" onclick=\"\" /></td>" +
+ "<td id=\"idc2\"><img src=\"\" alt=\"\" onclick=\"\" /></td>" +
+ "<td id=\"idc3\"><img src=\"\" alt=\"\" onclick=\"\" /></td>" +
+ "<td id=\"idc4\"><img src=\"\" alt=\"\" onclick=\"\" /></td>" +
+ "</tr></table>";
+
+ Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
+ }
+
+ [TestMethod]
+ public void CountH1to6()
+ {
+ string result = _parser.Parse("h$[title=item$]{Header $}*2", ZenType.HTML);
+ string expected = "<h1 title=\"item1\">Header 1</h1>" + Environment.NewLine +
+ "<h2 title=\"item2\">Header 2</h2>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void CountPadLeft()
+ {
+ string result = _parser.Parse("h1[title=item$]{Header $$$}*2", ZenType.HTML);
+ string expected = "<h1 title=\"item1\">Header 001</h1>" + Environment.NewLine +
+ "<h1 title=\"item2\">Header 002</h1>";
+
+ Assert.AreEqual(expected, result);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 9542523

Please sign in to comment.