// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net)
// All rights reserved.
//
// This file is part of Regionerate.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Rauchy.Regionerate.Domain.Entities;
namespace Rauchy.Regionerate.Shared.Components.Rendering.Tests
{
[ TestFixture ]
public sealed class VisibleRegionRendererTests : RegionRendererTests
{
#region Tests (1)
// [rgn] Public Methods (1)
///
/// When the last child of a region is a , there is no need to pad
/// the footer since it will create a large whitespace block.
///
[ Test ]
[ Ignore( "From v0.7, there are no Separators as last children, only between two consecutive children." ) ]
public void DoesNotPadFooterIfLastChildIsSeparator()
{
const int expectedChildrenCount = 0; // Separators are not FunctionalCode, so they are not counted.
Separator separator = new Separator();
Region.Children.Add( separator );
string renderedRegion = Render( Region, expectedChildrenCount );
IList lines = renderedRegion.GetLines();
Assert.AreEqual( 3, lines.Count );
VerifyHeader( lines, expectedChildrenCount );
Assert.AreEqual( Environment.NewLine, lines[ 1 ] );
// Second line should be the actual child
// The footer should not be padded, so the line after the child declaration should not be a new line.
Assert.AreNotEqual( Environment.NewLine, lines[ 2 ] );
}
#endregion Tests
#region Helper Methods (4)
// [rgn] Protected Methods (4)
protected override RegionRenderer CreateConcreteRenderer( CodeLayout.Configuration configuration )
{
return new VisibleRegionRenderer( configuration );
}
///
/// Extracts the lines that are not region headers or footers.
///
protected override IList ExtractBody( IList lines )
{
// Return everything but the first couple and last couple of lines.
IList body = new List();
for ( int i = 2; i < lines.Count - 2; i++ )
{
body.Add( lines[ i ] );
}
return body;
}
protected override void VerifyFooter( IList lines, CodeLayout.RenderingOptions renderingOptions )
{
string expected = string.Format("{0}#endregion {1}\r\n", TextUtilities.GetTabString( renderingOptions ),
RegionTitle );
Assert.AreEqual( expected, lines[ lines.Count - 1 ] );
}
protected override void VerifyHeader( IList lines, int? expectedChildrenCount, CodeLayout.RenderingOptions renderingOptions )
{
string expected = string.Format( "{0}#region {1}{2}{3}", TextUtilities.GetTabString( renderingOptions ),
RegionTitle,
expectedChildrenCount != null
? string.Format( " ({0})", expectedChildrenCount )
: null, Environment.NewLine );
Assert.AreEqual( expected, lines[ 0 ] );
}
#endregion Helper Methods
}
}