Skip to content

Commit

Permalink
Merged Whitespace Management branch into loudej/master.
Browse files Browse the repository at this point in the history
Conflicts:
	src/Spark.Tests/Caching/CacheElementTester.cs
	src/Spark.Tests/Constraints.cs
	src/Spark.Tests/Parser/MarkupGrammarTester.cs
	src/Spark.Tests/Spark.Tests.csproj
	src/Spark.Tests/SparkViewFactoryTester.cs
	src/Spark/Compiler/NodeVisitors/ChunkBuilderVisitor.cs
	src/Spark/Parser/Chain.cs
	src/Spark/Parser/CharGrammar.cs
	src/Spark/Parser/Grammar.cs
	src/Spark/Parser/Markup/MarkupGrammar.cs
	src/Spark/Parser/Markup/Node.cs
	src/Spark/Parser/ParseAction.cs
	src/Spark/Parser/ParseActionExtensions.cs
	src/Spark/Parser/ParseResult.cs
	src/Spark/Parser/ParserSettings.cs
	src/Spark/Parser/Syntax/DefaultSyntaxProvider.cs
	src/Spark/Parser/ViewLoader.cs

Signed-off-by: John Gietzen <otac0n@gietzen.us>
  • Loading branch information
corp/jgietzen committed Nov 4, 2010
2 parents d76178f + 673fc74 commit 6d40ed1
Show file tree
Hide file tree
Showing 18 changed files with 1,262 additions and 861 deletions.

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions src/Castle.MonoRail.Views.Spark.Tests/Constraints.cs
@@ -0,0 +1,102 @@
//-------------------------------------------------------------------------
// <copyright file="Constraints.cs">
// Copyright 2008-2010 Louis DeJardin - http://whereslou.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Louis DeJardin</author>
// <author>John Gietzen</author>
//-------------------------------------------------------------------------

namespace Castle.MonoRail.Views.Spark.Tests
{
using System;
using NUnit.Framework;
using NUnit.Framework.Constraints;

/// <summary>
/// The Is class is a helper class with properties and methods that supply a
/// number of constraints used in Asserts.
/// </summary>
public static class Contains
{
/// <summary>
/// Contains.InOrder returns a constraint that tests whether the actual value
/// contains all of the specified items in order.
/// </summary>
/// <param name="items">The list of items to test.</param>
/// <returns>true, if all items are contained within the actual value, in order; false, otherwise.</returns>
public static Constraint InOrder(params string[] items)
{
return new ContainsInOrderConstraint(items);
}

/// <summary>
/// A constraint that tests whether the actual value contains all of the specified items in order.
/// </summary>
private class ContainsInOrderConstraint : Constraint
{
/// <summary>
/// Holds the list of items to test.
/// </summary>
private readonly string[] items;

/// <summary>
/// Initializes a new instance of the <see cref="ContainsInOrderConstraint"/> class.
/// </summary>
/// <param name="items">The list of items to test.</param>
public ContainsInOrderConstraint(params string[] items)
{
this.items = items;
}

/// <summary>
/// Tests whether the actual value contains all of the specified items in order.
/// </summary>
/// <param name="actual">The actual value to test.</param>
/// <returns>true, if all items are contained within the actual value, in order; false, otherwise.</returns>
public override bool Matches(object actual)
{
if (actual == null)
{
return this.items.Length == 0;
}

var actualString = actual.ToString();

int index = 0;
foreach (string value in this.items)
{
int nextIndex = actualString.IndexOf(value, index);
if (nextIndex < 0)
{
return false;
}

index = nextIndex + value.Length;
}

return true;
}

/// <summary>
/// Writes the constraint description to a MessageWriter.
/// </summary>
/// <param name="writer">The writer on which the description is displayed.</param>
public override void WriteDescriptionTo(MessageWriter writer)
{
writer.WriteLine("Tests whether the actual value contains all of the specified items in order.");
}
}
}
}
@@ -1,122 +1,128 @@
// Copyright 2008-2009 Louis DeJardin - http://whereslou.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
using System.IO;
using Castle.MonoRail.Framework;
using Castle.MonoRail.Framework.Services;
using Castle.MonoRail.Framework.Test;
using Castle.MonoRail.Views.Spark.Tests.Stubs;
using NUnit.Framework;
using Rhino.Mocks;

namespace Castle.MonoRail.Views.Spark.Tests.ViewComponents
{
[TestFixture]
public class ViewComponentSectionTests : BaseViewComponentTests
{
public override void Init()
{
base.Init();
viewComponentFactory.Registry.AddViewComponent("ComponentWithSections", typeof(ComponentWithSections));
}

[Test]
public void ComponentWithSimpleSections()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\ComponentWithSimpleSections.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("this-is-a-header"));
Assert.IsTrue(output.Contains("this-is-a-body"));
Assert.IsTrue(output.Contains("this-is-a-footer"));
}

[Test]
public void ComponentWithIfConditionInSection()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\ComponentWithComplexSections.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("this-should-show-up"));
Assert.IsFalse(output.Contains("this-should-not-show-up"));
Assert.IsFalse(output.Contains("if condition"));
}

[Test]
public void ComponentWithForEachInSection()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\ComponentWithComplexSections.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("1,2,3,"));
Assert.IsTrue(output.Contains("<span>10</span><span>9</span><span>8</span>"));
Assert.IsFalse(output.Contains("for each"));
Assert.IsFalse(output.Contains("span each"));
}

[Test]
public void ComponentWithPartialsInSection()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\ComponentWithPartialsInSection.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("this is some text: test123"));
}

[Test]
public void NestedComponentInSection()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\NestedComponentInSection.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("header1"));
Assert.IsTrue(output.Contains("header2"));
Assert.IsTrue(output.Contains("body1"));
Assert.IsTrue(output.Contains("body2"));
Assert.IsTrue(output.Contains("footer1"));
Assert.IsTrue(output.Contains("footer2"));

Assert.IsFalse(output.Contains("<header>"));
Assert.IsFalse(output.Contains("<body>"));
Assert.IsFalse(output.Contains("<footer>"));
Assert.IsFalse(output.Contains("</ComponentWithSections>"));
}

[ViewComponentDetails("ComponentWithSections",Sections="header,body,footer")]
class ComponentWithSections : ViewComponent
{
public override void Render()
{
RenderSection("header");
RenderSection("body");
RenderSection("footer");
}
}
}
}
//-------------------------------------------------------------------------
// <copyright file="Constraints.cs">
// Copyright 2008-2010 Louis DeJardin - http://whereslou.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Louis DeJardin</author>
// <author>John Gietzen</author>
//-------------------------------------------------------------------------

namespace Castle.MonoRail.Views.Spark.Tests.ViewComponents
{
using System;
using System.IO;
using Castle.MonoRail.Framework;
using NUnit.Framework;

[TestFixture]
public class ViewComponentSectionTests : BaseViewComponentTests
{
public override void Init()
{
base.Init();
viewComponentFactory.Registry.AddViewComponent("ComponentWithSections", typeof(ComponentWithSections));
}

[Test]
public void ComponentWithSimpleSections()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\ComponentWithSimpleSections.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("this-is-a-header"));
Assert.IsTrue(output.Contains("this-is-a-body"));
Assert.IsTrue(output.Contains("this-is-a-footer"));
}

[Test]
public void ComponentWithIfConditionInSection()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\ComponentWithComplexSections.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("this-should-show-up"));
Assert.IsFalse(output.Contains("this-should-not-show-up"));
Assert.IsFalse(output.Contains("if condition"));
}

[Test]
public void ComponentWithForEachInSection()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\ComponentWithComplexSections.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.That(output, Contains.InOrder(
"1,2,3,",
"<span>10</span>",
"<span>9</span>",
"<span>8</span>"));
Assert.IsFalse(output.Contains("for each"));
Assert.IsFalse(output.Contains("span each"));
}

[Test]
public void ComponentWithPartialsInSection()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\ComponentWithPartialsInSection.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("this is some text: test123"));
}

[Test]
public void NestedComponentInSection()
{
mocks.ReplayAll();

var writer = new StringWriter();
factory.Process("Home\\NestedComponentInSection.spark", writer, engineContext, controller, controllerContext);

var output = writer.ToString();
Assert.IsTrue(output.Contains("header1"));
Assert.IsTrue(output.Contains("header2"));
Assert.IsTrue(output.Contains("body1"));
Assert.IsTrue(output.Contains("body2"));
Assert.IsTrue(output.Contains("footer1"));
Assert.IsTrue(output.Contains("footer2"));

Assert.IsFalse(output.Contains("<header>"));
Assert.IsFalse(output.Contains("<body>"));
Assert.IsFalse(output.Contains("<footer>"));
Assert.IsFalse(output.Contains("</ComponentWithSections>"));
}

[ViewComponentDetails("ComponentWithSections",Sections="header,body,footer")]
class ComponentWithSections : ViewComponent
{
public override void Render()
{
RenderSection("header");
RenderSection("body");
RenderSection("footer");
}
}
}
}

0 comments on commit 6d40ed1

Please sign in to comment.