Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged Whitespace Management branch into loudej/master.
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
Showing
18 changed files
with
1,262 additions
and
861 deletions.
There are no files selected for viewing
633 changes: 317 additions & 316 deletions
633
src/Castle.MonoRail.Views.Spark.Tests/Castle.MonoRail.Views.Spark.Tests.csproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} | ||
} | ||
} |
250 changes: 128 additions & 122 deletions
250
src/Castle.MonoRail.Views.Spark.Tests/ViewComponents/ViewComponentSectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.