Skip to content

Commit

Permalink
bruce-dunwiddie#117 Case statement should include whitespace if Inclu…
Browse files Browse the repository at this point in the history
…deWhiteSpace=true
  • Loading branch information
teyc committed Feb 4, 2023
1 parent 4d018ee commit 3af9529
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public TSQLCaseExpression Parse(ITSQLTokenizer tokenizer)

tokenizer.MoveNext();

TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
caseExpression.Tokens);

return caseExpression;
}
}
Expand Down
22 changes: 22 additions & 0 deletions TSQL_Parser/Tests/Expressions/CaseExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using TSQL.Tokens;

using Tests.Tokens;
using TSQL.Expressions.Parsers;

namespace Tests.Expressions
{
Expand Down Expand Up @@ -81,5 +82,26 @@ public void CaseExpression_Regression_Duplicated_Case()
},
tokens);
}

[TestCase(false, 30)]
[TestCase(true, 31)]
public void CaseExpression_Should_Include_TrailingWhitespace_If_Flag_Is_True(bool includeWhiteSpace, int expectedEndPosition)
{
const string sql =
// 0123456789012345678901234567890123456789
"CASE 1 WHEN 2 THEN 2 ELSE 3 END ";

TSQLTokenizer tokenizer = new TSQLTokenizer(sql)
{
IncludeWhitespace = includeWhiteSpace
};

Assert.IsTrue(tokenizer.MoveNext());

var expression = new TSQLCaseExpressionParser().Parse(tokenizer);
Assert.AreEqual(0, expression.BeginPosition);
Assert.AreEqual(expectedEndPosition, expression.EndPosition);

}
}
}

0 comments on commit 3af9529

Please sign in to comment.