Skip to content

Commit

Permalink
Merge pull request #20 from StevenLiekens/OptionalWhiteSpace
Browse files Browse the repository at this point in the history
Changing 'CreateAlterTemplate' to ignore leading white spaces
  • Loading branch information
keithbloom committed Jun 28, 2015
2 parents c01aba7 + e9d17c5 commit a396868
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Powerup.Tests/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ public void should_template_my_sproc()
var createText = "CREATE PROCEDURE [dbo].[Procy] ";


var sproc = new CreateAlterTemplate(new SqlObject(new ProcedureQuery(),"Hello"));
var sproc = new CreateAlterTemplate(new SqlObject(new ProcedureQuery(), "Hello"));

sproc.AddText(createText);
Assert.That(sproc.TemplatedProcedure(), Is.Not.StringContaining(createText));
}

[Test]
public void should_template_my_sproc_with_leading_white_spaces()
{
var createText = " \t \t CREATE PROCEDURE [dbo].[Procy] ";


var sproc = new CreateAlterTemplate(new SqlObject(new ProcedureQuery(), "Hello"));

sproc.AddText(createText);
Assert.That(sproc.TemplatedProcedure(), Is.Not.StringContaining(createText));
Expand Down
2 changes: 1 addition & 1 deletion src/Powerup/Templates/CreateAlterTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DECLARE @SQL varchar(1000)
{2}
";

readonly Regex removeCreate = new Regex(@"^(CREATE)\s.*(PROCEDURE |PROC |VIEW )(.*)$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
readonly Regex removeCreate = new Regex(@"^(?:\s*)?(CREATE)\s.*(PROCEDURE |PROC |VIEW )(.*)$", RegexOptions.Multiline | RegexOptions.IgnoreCase);

public CreateAlterTemplate(SqlObject sqlObject)
: base(sqlObject)
Expand Down

0 comments on commit a396868

Please sign in to comment.