Skip to content

Commit 54bf49b

Browse files
committed
Some tests for OptionInlineNamespacesEvaluationRule + refactoring
1 parent 4f96f8b commit 54bf49b

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

+40
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,46 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingEvaluation
15301530

15311531
#endregion
15321532

1533+
#region OptionInlineNamespacesEvaluationRule
1534+
1535+
evaluator = new ExpressionEvaluator()
1536+
{
1537+
OptionInlineNamespacesEvaluationRule = InlineNamespacesEvaluationRule.BlockAll
1538+
};
1539+
1540+
yield return new TestCaseData(evaluator, "new System.Collections.Generic.List<string>(){\"-\"}", typeof(ExpressionEvaluatorSyntaxErrorException))
1541+
.SetCategory("Options")
1542+
.SetCategory("InlineNamespacesEvaluationRule.BlockAll")
1543+
.SetCategory("OptionInlineNamespacesEvaluationRule");
1544+
1545+
evaluator = new ExpressionEvaluator()
1546+
{
1547+
OptionInlineNamespacesEvaluationRule = InlineNamespacesEvaluationRule.AllowOnlyInlineNamespacesList
1548+
};
1549+
1550+
evaluator.InlineNamespacesList = evaluator.Namespaces.ToList();
1551+
1552+
evaluator.InlineNamespacesList.Remove("System.Collections.Generic");
1553+
1554+
yield return new TestCaseData(evaluator, "new System.Collections.Generic.List<string>()", typeof(ExpressionEvaluatorSyntaxErrorException))
1555+
.SetCategory("Options")
1556+
.SetCategory("InlineNamespacesEvaluationRule.AllowOnlyInlineNamespacesList")
1557+
.SetCategory("OptionInlineNamespacesEvaluationRule");
1558+
1559+
evaluator = new ExpressionEvaluator()
1560+
{
1561+
OptionInlineNamespacesEvaluationRule = InlineNamespacesEvaluationRule.BlockOnlyInlineNamespacesList
1562+
};
1563+
1564+
evaluator.InlineNamespacesList = evaluator.Namespaces.ToList();
1565+
1566+
yield return new TestCaseData(evaluator, "new System.Collections.Generic.List<string>(){ \"\" }", typeof(ExpressionEvaluatorSyntaxErrorException))
1567+
.SetCategory("Options")
1568+
.SetCategory("InlineNamespacesEvaluationRule.BlockOnlyInlineNamespacesList")
1569+
.SetCategory("OptionInlineNamespacesEvaluationRule");
1570+
1571+
#endregion
1572+
15331573
#endregion
15341574

15351575
#region TypesToBlock

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

+4-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using System.Dynamic;
1515
using System.Globalization;
1616
using System.Linq;
17-
using System.Linq.Expressions;
1817
using System.Reflection;
1918
using System.Runtime.CompilerServices;
2019
using System.Runtime.InteropServices;
@@ -567,15 +566,9 @@ public bool OptionCaseSensitiveEvaluationActive
567566
/// </summary>
568567
public bool OptionVariablesPersistenceCustomComparer { get; set; }
569568

570-
private StringComparison StringComparisonForCasing { get; set; } = StringComparison.Ordinal;
569+
protected StringComparison StringComparisonForCasing { get; set; } = StringComparison.Ordinal;
571570

572-
protected StringComparer StringComparerForCasing
573-
{
574-
get
575-
{
576-
return OptionCaseSensitiveEvaluationActive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
577-
}
578-
}
571+
protected StringComparer StringComparerForCasing => OptionCaseSensitiveEvaluationActive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
579572

580573
/// <summary>
581574
/// If <c>true</c> all numbers without decimal and suffixes evaluations will be done as double
@@ -618,10 +611,7 @@ public CultureInfo CultureInfoForNumberParsing
618611
/// </summary>
619612
public string OptionNumberParsingDecimalSeparator
620613
{
621-
get
622-
{
623-
return optionNumberParsingDecimalSeparator;
624-
}
614+
get => optionNumberParsingDecimalSeparator;
625615

626616
set
627617
{
@@ -644,10 +634,7 @@ public string OptionNumberParsingDecimalSeparator
644634
/// </summary>
645635
public string OptionNumberParsingThousandSeparator
646636
{
647-
get
648-
{
649-
return optionNumberParsingThousandSeparator;
650-
}
637+
get => optionNumberParsingThousandSeparator;
651638

652639
set
653640
{

0 commit comments

Comments
 (0)