Skip to content

Commit 0de8645

Browse files
author
Sébastien Geiser
committed
StrongTyped Variables more limited
1 parent 6fbea30 commit 0de8645

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,6 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingScriptEvalu
15731573
.SetCategory("Exception");
15741574

15751575
#endregion
1576-
15771576
}
15781577
}
15791578

@@ -1582,15 +1581,14 @@ public void ExceptionThrowingScriptEvaluation(ExpressionEvaluator evaluator, str
15821581
{
15831582
evaluator.Namespaces.Add("CodingSeb.ExpressionEvaluator.Tests");
15841583

1585-
Assert.Catch(exceptionType, () => evaluator.ScriptEvaluate(evaluator.RemoveComments(script)));
1586-
1587-
if (exceptionMessage != null)
1584+
try
15881585
{
1589-
try
1590-
{
1591-
evaluator.ScriptEvaluate(evaluator.RemoveComments(script));
1592-
}
1593-
catch(Exception exception)
1586+
evaluator.ScriptEvaluate(evaluator.RemoveComments(script));
1587+
}
1588+
catch(Exception exception)
1589+
{
1590+
exception.ShouldBeAssignableTo(exceptionType);
1591+
if (exceptionMessage != null)
15941592
{
15951593
exception.Message.ShouldBe(exceptionMessage);
15961594
}

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,10 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
21232123
{
21242124
if (Variables.ContainsKey(varFuncName))
21252125
throw new ExpressionEvaluatorSyntaxErrorException($"Can not declare a new variable named [{varFuncName}]. A variable with this name already exists");
2126+
else if (varFuncMatch.Groups["varKeyword"].Success)
2127+
throw new ExpressionEvaluatorSyntaxErrorException($"Can not declare a variable wih type and var keyword.");
2128+
else if (varFuncMatch.Groups["dynamicKeyword"].Success)
2129+
throw new ExpressionEvaluatorSyntaxErrorException($"Can not declare a variable wih type and dynamic keyword.");
21262130

21272131
stack.Pop();
21282132

0 commit comments

Comments
 (0)