Skip to content

Commit

Permalink
Merge pull request #120 from teyc/fix/case_stmt_trailing_whitespace
Browse files Browse the repository at this point in the history
#117 Case Expression trailing whitespace
  • Loading branch information
bruce-dunwiddie authored Feb 5, 2023
2 parents 2a2f729 + a461656 commit 9339005
Show file tree
Hide file tree
Showing 2 changed files with 25 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
21 changes: 21 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,25 @@ 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)
{
// 0123456789012345678901234567890123456789
const string sql = "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 9339005

Please sign in to comment.