Permalink
Browse files

Lorem: Rendering issue fixed. (#37)

  • Loading branch information...
1 parent 91d5d6b commit c22e2cd1a0fb2efcf02afc555b872156343c230d @am11 am11 committed Mar 8, 2014
@@ -79,5 +79,31 @@ public void Formatting6()
Assert.AreEqual(expected, result);
}
+ [TestMethod]
+ public void Formatting7()
+ {
+ string result = _parser.Parse("ul>li*3>{some text}", ZenType.HTML);
+ string expected = "<ul>" +
+ Environment.NewLine + "<li>some text</li>" +
+ Environment.NewLine + "<li>some text</li>" +
+ Environment.NewLine + "<li>some text</li>" +
+ Environment.NewLine + "</ul>";
+
+ Assert.AreEqual(expected, result);
+ }
+
+ [TestMethod]
+ public void Formatting8()
+ {
+ string result = _parser.Parse("ul>li*3>lorem", ZenType.HTML);
+ string expected = "<ul>" +
+ Environment.NewLine + "<li>random lorem text</li>" +
+ Environment.NewLine + "<li>random lorem text</li>" +
+ Environment.NewLine + "<li>random lorem text</li>" +
+ Environment.NewLine + "</ul>";
+
+ Assert.AreEqual(expected.Split(Environment.NewLine.ToCharArray()).Length, result.Split(Environment.NewLine.ToCharArray()).Length);
+ }
+
}
}
@@ -18,35 +18,40 @@ public void Initialize()
public void Lorem1()
{
string result = _parser.Parse("lorem", ZenType.HTML);
- string expected = "Lorem ipsum dolor sit amet, consectetur adipiscing elit fusce vel sapien elit in malesuada semper mi, id sollicitudin urna fermentum ut fusce varius nisl ac ipsum gravida vel pretium tellus.";
- Assert.AreEqual(expected, result);
+ Assert.AreEqual(result.Split().Length, 30);
}
[TestMethod]
public void Lorem2()
{
string result = _parser.Parse("lorem*3", ZenType.HTML);
- Assert.AreEqual(result.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Length, 3);
+ Assert.AreEqual(result.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length, 3);
}
[TestMethod]
public void Lorem3()
{
string result = _parser.Parse("p>lorem", ZenType.HTML);
- string expected = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit fusce vel sapien elit in malesuada semper mi, id sollicitudin urna fermentum ut fusce varius nisl ac ipsum gravida vel pretium tellus.</p>";
- Assert.AreEqual(expected, result.Replace(Environment.NewLine, ""));
+ Assert.AreEqual(result.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length, 1);
}
[TestMethod]
public void LoremCount()
{
string result = _parser.Parse("p>lorem10", ZenType.HTML);
- string expected = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit fusce vel.</p>";
- Assert.AreEqual(expected, result.Replace(Environment.NewLine, ""));
+ Assert.AreEqual(result.Split().Length, 10);
+ }
+
+ [TestMethod]
+ public void LoremWithText()
+ {
+ string result = _parser.Parse("div>lorem+{some text}", ZenType.HTML);
+
+ Assert.AreEqual(result.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length, 4);
}
[TestMethod]
@@ -1,4 +1,5 @@
-using System.Web.UI;
+using System;
+using System.Web.UI;
using System.Web.UI.HtmlControls;
namespace ZenCoding
@@ -12,7 +13,22 @@ public EmptyHtmlControl()
protected override void Render(HtmlTextWriter writer)
{
+ if (writer == null)
+ return;
+
base.RenderChildren(writer);
+
+ var count = this.Parent.Controls.Count;
+
+ if (count < 2)
+ return;
+
+ var index = this.Parent.Controls.IndexOf(this);
+
+ if ((index == 0 && this.Parent.Controls[index + 1] is EmptyHtmlControl) || index > 0 &&
+ ((index == --count && this.Parent.Controls[count] is EmptyHtmlControl) ||
+ (this.Parent.Controls[index - 1] is EmptyHtmlControl || this.Parent.Controls[index + 1] is EmptyHtmlControl)))
+ writer.WriteLine(Environment.NewLine);
}
}
}
@@ -36,19 +36,20 @@ public static HtmlControl CloneElement(this HtmlControl element, int count)
control.ID = element.ID.Increment(count);
}
- if (element.Controls.Count == 1)
+ var lorem = element as LoremControl;
+
+ if (lorem != null)
+ {
+ (control as LoremControl).InnerText = lorem.Generate(count);
+ }
+ else if (element.Controls.Count == 1)
{
LiteralControl literal = element.Controls[0] as LiteralControl;
+
if (literal != null)
control.Controls.Add(new LiteralControl(literal.Text.Increment(count)));
}
- var lorem = element as LoremControl;
- if (lorem != null)
- {
- lorem.InnerText = lorem.Generate(count);
- }
-
return control;
}
}
@@ -1,6 +1,5 @@
using System;
using System.Linq;
-using System.Web.UI;
namespace ZenCoding
{
@@ -62,14 +61,5 @@ private static string Normalize(string result)
return result;
}
-
- protected override void Render(HtmlTextWriter writer)
- {
- if (writer == null)
- return;
-
- base.RenderChildren(writer);
- writer.Write(Environment.NewLine);
- }
}
}

0 comments on commit c22e2cd

Please sign in to comment.