Skip to content

Commit

Permalink
Using extension method to assert parts now.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdiamond committed Oct 30, 2010
1 parent ca21469 commit 9502a8f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 112 deletions.
65 changes: 23 additions & 42 deletions Nustache.Tests/Describe_Parser.cs
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using NUnit.Framework;
using Nustache.Core;

Expand Down Expand Up @@ -32,17 +31,11 @@ public void It_combines_sections()
new LiteralText("after")
});

CollectionAssert.AreEqual(
new Part[]
{
new LiteralText("before"),
new Block("foo",
new LiteralText("inside"),
new EndSection("foo")),
new LiteralText("after")
},
template.Parts.ToArray(),
new PartComparer());
template.Parts.IsEqualTo(new LiteralText("before"),
new Block("foo",
new LiteralText("inside"),
new EndSection("foo")),
new LiteralText("after"));
}

[Test]
Expand All @@ -65,21 +58,15 @@ public void It_handles_nested_sections()
new LiteralText("after foo")
});

CollectionAssert.AreEqual(
new Part[]
{
new LiteralText("before foo"),
new Block("foo",
new LiteralText("before bar"),
new Block("bar",
new LiteralText("inside bar"),
new EndSection("bar")),
new LiteralText("after bar"),
new EndSection("foo")),
new LiteralText("after foo")
},
template.Parts.ToArray(),
new PartComparer());
template.Parts.IsEqualTo(new LiteralText("before foo"),
new Block("foo",
new LiteralText("before bar"),
new Block("bar",
new LiteralText("inside bar"),
new EndSection("bar")),
new LiteralText("after bar"),
new EndSection("foo")),
new LiteralText("after foo"));
}

[Test]
Expand All @@ -102,21 +89,15 @@ public void It_handles_nested_sections_with_the_same_name()
new LiteralText("after foo 1")
});

CollectionAssert.AreEqual(
new Part[]
{
new LiteralText("before foo 1"),
new Block("foo",
new LiteralText("before foo 2"),
new Block("foo",
new LiteralText("inside foo 2"),
new EndSection("foo")),
new LiteralText("after foo 2"),
new EndSection("foo")),
new LiteralText("after foo 1")
},
template.Parts.ToArray(),
new PartComparer());
template.Parts.IsEqualTo(new LiteralText("before foo 1"),
new Block("foo",
new LiteralText("before foo 2"),
new Block("foo",
new LiteralText("inside foo 2"),
new EndSection("foo")),
new LiteralText("after foo 2"),
new EndSection("foo")),
new LiteralText("after foo 1"));
}

[Test]
Expand Down
70 changes: 18 additions & 52 deletions Nustache.Tests/Describe_Scanner.cs
@@ -1,5 +1,4 @@
using System.Linq;
using NUnit.Framework;
using NUnit.Framework;
using Nustache.Core;

namespace Nustache.Tests
Expand All @@ -14,11 +13,7 @@ public void It_returns_no_parts_for_the_empty_string()

var parts = scanner.Scan("");

CollectionAssert.AreEqual(new Part[]
{
},
parts.ToArray(),
new PartComparer());
parts.IsEmpty();
}

[Test]
Expand All @@ -28,12 +23,7 @@ public void It_scans_literal_text()

var parts = scanner.Scan("foo");

CollectionAssert.AreEqual(new Part[]
{
new LiteralText("foo"),
},
parts.ToArray(),
new PartComparer());
parts.IsEqualTo(new LiteralText("foo"));
}

[Test]
Expand All @@ -43,14 +33,9 @@ public void It_scans_variable_references()

var parts = scanner.Scan("before{{foo}}after");

CollectionAssert.AreEqual(new Part[]
{
new LiteralText("before"),
new VariableReference("foo"),
new LiteralText("after"),
},
parts.ToArray(),
new PartComparer());
parts.IsEqualTo(new LiteralText("before"),
new VariableReference("foo"),
new LiteralText("after"));
}

[Test]
Expand All @@ -60,30 +45,21 @@ public void It_scans_sections()

var parts = scanner.Scan("{{#foo}}inside{{/foo}}");

CollectionAssert.AreEqual(new Part[]
{
new Block("foo"),
new LiteralText("inside"),
new EndSection("foo"),
},
parts.ToArray(),
new PartComparer());
parts.IsEqualTo(new Block("foo"),
new LiteralText("inside"),
new EndSection("foo"));
}

[Test]
public void It_scans_template_definitions()
{
var scanner = new Scanner();

var parts = scanner.Scan("{{<foo}}inside{{/foo}}");

CollectionAssert.AreEqual(new Part[]
{
new TemplateDefinition("foo"),
new LiteralText("inside"),
new EndSection("foo"),
},
parts.ToArray(),
new PartComparer());
parts.IsEqualTo(new TemplateDefinition("foo"),
new LiteralText("inside"),
new EndSection("foo"));
}

[Test]
Expand All @@ -93,14 +69,9 @@ public void It_scans_template_includes()

var parts = scanner.Scan("before{{>foo}}after");

CollectionAssert.AreEqual(new Part[]
{
new LiteralText("before"),
new TemplateInclude("foo"),
new LiteralText("after"),
},
parts.ToArray(),
new PartComparer());
parts.IsEqualTo(new LiteralText("before"),
new TemplateInclude("foo"),
new LiteralText("after"));
}

[Test]
Expand All @@ -110,13 +81,8 @@ public void It_skips_comments()

var parts = scanner.Scan("before{{!foo}}after");

CollectionAssert.AreEqual(new Part[]
{
new LiteralText("before"),
new LiteralText("after"),
},
parts.ToArray(),
new PartComparer());
parts.IsEqualTo(new LiteralText("before"),
new LiteralText("after"));
}
}
}
23 changes: 5 additions & 18 deletions Nustache.Tests/Describe_Section.cs
@@ -1,5 +1,4 @@
using System.Linq;
using NUnit.Framework;
using NUnit.Framework;
using Nustache.Core;

namespace Nustache.Tests
Expand All @@ -15,14 +14,8 @@ public void It_holds_parts_added_to_it()
section.Add(new LiteralText("bar"));
section.Add(new LiteralText("baz"));

CollectionAssert.AreEqual(
new Part[]
{
new LiteralText("bar"),
new LiteralText("baz")
},
section.Parts.ToArray(),
new PartComparer());
section.Parts.IsEqualTo(new LiteralText("bar"),
new LiteralText("baz"));
}

[Test]
Expand All @@ -34,14 +27,8 @@ public void It_does_not_hold_template_definitions_with_other_parts()
section.Add(new TemplateDefinition("baz"));
section.Add(new LiteralText("quux"));

CollectionAssert.AreEqual(
new Part[]
{
new LiteralText("bar"),
new LiteralText("quux")
},
section.Parts.ToArray(),
new PartComparer());
section.Parts.IsEqualTo(new LiteralText("bar"),
new LiteralText("quux"));
}

[Test]
Expand Down
24 changes: 24 additions & 0 deletions Nustache.Tests/EnumerablePartExtensions.cs
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Nustache.Core;

namespace Nustache.Tests
{
internal static class EnumerablePartExtensions
{
public static void IsEmpty(
this IEnumerable<Part> actualParts)
{
Assert.That(actualParts.ToArray(), Is.Empty);
}

public static void IsEqualTo(
this IEnumerable<Part> actualParts,
params Part[] expectedParts)
{
Assert.That(actualParts.ToArray(), Is.EqualTo(expectedParts)
.Using(new PartComparer()));
}
}
}
1 change: 1 addition & 0 deletions Nustache.Tests/Nustache.Tests.csproj
Expand Up @@ -62,6 +62,7 @@
<Compile Include="Describe_Template_Render.cs" />
<Compile Include="Describe_ValueGetter.cs" />
<Compile Include="PartComparer.cs" />
<Compile Include="EnumerablePartExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 9502a8f

Please sign in to comment.