// 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 BestBrains.System;
using NUnit.Framework;
using Rauchy.Regionerate.ServiceLayer.Components.Tools;
namespace Rauchy.Regionerate.ServiceLayer.Components.Tests
{
///
/// Tests the class.
///
[ TestFixture ]
public sealed class WhitespaceRemoverTests
{
#region Methods (11)
[ Test ]
[ ExpectedException( typeof ( ArgumentNullException ) ) ]
public void ShouldNotAcceptNullString()
{
new WhitespaceRemover().Remove( null );
}
/// public class Foo
/// {
/// public void Bar()
/// {
///
/// ...
///
/// }
/// }
[ Test ]
public void ShouldNotRemoveAWhitespaceInAMethod()
{
string code = CommentReader.GetElement( "code" );
string expected = code;
string actual = new WhitespaceRemover().Remove( code );
Assert.AreEqual( expected, actual );
}
/// public class Foo
/// {
/// public void Bar()
/// {
/// string[] names = new string[]
/// {
///
/// "John", "Mark",
///
///
/// "Martha", "Beth"
///
/// };
///
/// #region My Region
/// ...
/// #endregion
/// }
/// }
[ Test ]
public void ShouldNotRemoveWhitespaceInAMethodWithInnerArrayDeclaration()
{
string code = CommentReader.GetElement( "code" );
string expected = code;
string actual = new WhitespaceRemover().Remove( code );
Assert.AreEqual( expected, actual );
}
/// public class Foo
/// {
/// public void Bar()
/// {
/// using ( Stream stream = GetStream() )
/// {
/// ...
/// }
///
/// ...
///
/// }
/// }
[ Test ]
public void ShouldNotRemoveWhitespaceInAMethodWithInnerUsingBlock()
{
string code = CommentReader.GetElement( "code" );
string expected = code;
string actual = new WhitespaceRemover().Remove( code );
Assert.AreEqual( expected, actual );
}
/// public string Foo
/// {
/// get
/// {
///
/// ...
///
/// }
/// set
/// {
/// ...
/// }
/// }
[ Test ]
public void ShouldNotRemoveWhitespaceInAProperty()
{
string code = CommentReader.GetElement( "code" );
string expected = code;
string actual = new WhitespaceRemover().Remove( code );
Assert.AreEqual( expected, actual );
}
/// public class Foo
/// {
/// public void Bar() {
///
/// ...
///
/// }
/// }
[ Test ]
public void ShouldNotRemoveWhitespaceInASingleLineMethodDeclaration()
{
string code = CommentReader.GetElement( "code" );
string expected = code;
string actual = new WhitespaceRemover().Remove( code );
Assert.AreEqual( expected, actual );
}
///
///
///
[ Test ]
public void ShouldRemoveASingleTabbedWhitespace()
{
string code = CommentReader.GetElement( "code" );
string actual = new WhitespaceRemover().Remove( code ).Trim();
Assert.IsEmpty( actual );
}
///
///
/// This is my code
///
/// This is my code
[ Test ]
public void ShouldRemoveASingleWhitespace()
{
string code = CommentReader.GetElement( "code" );
string expected = CommentReader.GetElement( "expected" );
string actual = new WhitespaceRemover().Remove( code ).Trim();
Assert.AreEqual( expected, actual );
}
///
///
/// Code #1
///
/// Code #2
///
///
/// Code #1
/// Code #2
[ Test ]
public void ShouldRemoveMultipleWhitespaces()
{
string code = CommentReader.GetElement( "code" );
string expected = CommentReader.GetElement( "expected" );
string actual = new WhitespaceRemover().Remove( code ).Trim();
Assert.AreEqual( expected, actual );
}
/// #region MyRegion
///
/// Can't touch this.
///
/// #endregion
[ Test ]
public void ShouldNotRemoveWhitespaceInsideRegions()
{
string code = CommentReader.GetElement( "code" );
string actual = new WhitespaceRemover().Remove( code ).Trim();
Assert.AreEqual( code, actual );
}
/// public void Foo()
/// {
/// }
///
/// public void Bar()
/// {
/// }
/// public void Foo()
/// {
/// }
/// public void Bar()
/// {
/// }
[ Test ]
public void ShouldRemoveWhitespaceBetweenMethods()
{
string code = CommentReader.GetElement( "code" );
string expected = CommentReader.GetElement( "expected" );
string actual = new WhitespaceRemover().Remove( code ).Trim();
Assert.AreEqual( expected, actual );
}
/// public string Foo
/// {
/// get { return _foo; }
/// }
///
/// public string Bar
/// {
/// get { return _bar; }
/// }
/// public string Foo
/// {
/// get { return _foo; }
/// }
/// public string Bar
/// {
/// get { return _bar; }
/// }
[ Test ]
public void ShouldRemoveWhitespaceBetweenProperties()
{
string code = CommentReader.GetElement( "code" );
string expected = CommentReader.GetElement( "expected" );
string actual = new WhitespaceRemover().Remove( code ).Trim();
Assert.AreEqual( expected, actual );
}
///
///
///
[ Test ]
public void ShouldRemoveWhitespaceOnEmptyText()
{
string code = CommentReader.GetElement( "code" );
string actual = new WhitespaceRemover().Remove( code ).Trim();
Assert.IsEmpty( actual );
}
[ Test ]
public void ShouldReturnEmptyOnEmpty()
{
string actual = new WhitespaceRemover().Remove( string.Empty );
Assert.IsEmpty( actual );
}
#endregion
}
}