Skip to content

Commit 0b44092

Browse files
committed
Tests for inline namespaces (some fail yet)
1 parent a86fa15 commit 0b44092

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,15 @@ public void TypeTesting(string expression, Type type)
476476
#region default values
477477
[TestCase("default(int)", TestOf = typeof(int), ExpectedResult = 0, Category = "default values")]
478478
[TestCase("default(bool)", TestOf = typeof(bool), ExpectedResult = false, Category = "default values")]
479+
[TestCase("default(System.Boolean)", TestOf = typeof(bool), ExpectedResult = false, Category = "default values, Inline namespaces")]
479480
#endregion
480-
481+
481482
#region typeof keyword
482483
[TestCase("typeof(int)", ExpectedResult = typeof(int), Category = "typeof keyword")]
483484
[TestCase("typeof(float)", ExpectedResult = typeof(float), Category = "typeof keyword")]
484485
[TestCase("typeof(string)", ExpectedResult = typeof(string), Category = "typeof keyword")]
485486
[TestCase("typeof(Regex)", ExpectedResult = typeof(Regex), Category = "typeof keyword")]
487+
[TestCase("typeof(System.Text.RegularExpressions.Regex)", ExpectedResult = typeof(Regex), Category = "typeof keyword,inline namespace")]
486488
[TestCase("typeof(string) == \"Hello\".GetType()", ExpectedResult = true, Category = "typeof keyword")]
487489
[TestCase("typeof(int) == 12.GetType()", ExpectedResult = true, Category = "typeof keyword")]
488490
[TestCase("typeof(string) == 12.GetType()", ExpectedResult = false, Category = "typeof keyword")]
@@ -492,7 +494,7 @@ public void TypeTesting(string expression, Type type)
492494
[TestCase("new ClassForTest1().GetType()", ExpectedResult = typeof(ClassForTest1), Category = "Create instance with new Keyword")]
493495
[TestCase("new ClassForTest2(15).GetType()", ExpectedResult = typeof(ClassForTest2), Category = "Create instance with new Keyword")]
494496
[TestCase("new ClassForTest2(15).Value1", ExpectedResult = 15, Category = "Create instance with new Keyword")]
495-
[TestCase("new CodingSeb.ExpressionEvaluator.Tests.OtherNamespace.ClassInOtherNameSpace1().Value1", ExpectedResult = 26, Category = "Create instance with new Keyword")]
497+
[TestCase("new CodingSeb.ExpressionEvaluator.Tests.OtherNamespace.ClassInOtherNameSpace1().Value1", ExpectedResult = 26, Category = "Create instance with new Keyword,Inline namespace")]
496498
[TestCase("new Regex(@\"\\w*[n]\\w*\").Match(\"Which word contains the desired letter ?\").Value", ExpectedResult = "contains", Category = "Create instance with new Keyword")]
497499
#endregion
498500

@@ -859,6 +861,7 @@ public void TypeTesting(string expression, Type type)
859861

860862
#region Complex expressions
861863
[TestCase("Enumerable.Range(1,4).Cast().Sum(x =>(int)x)", ExpectedResult = 10, Category = "Complex expression,Static method,Instance method,Lambda function,Cast")]
864+
[TestCase("System.Linq.Enumerable.Range(1,4).Cast().Sum(x =>(int)x)", ExpectedResult = 10, Category = "Complex expression,Static method,Instance method,Lambda function,Cast")]
862865
[TestCase("List(1,2,3,4,5,6).ConvertAll(x => (float)x)[2].GetType()", ExpectedResult = typeof(float), Category = "Complex expression,Type Manage,Instance method,Lambda function,Cast,Indexing")]
863866
[TestCase("List(\"hello\", \"bye\").Select(x => x.ToUpper()).ToList().FluidAdd(\"test\").Count", ExpectedResult = 3, Category = "Complex expression,Fluid Functions")]
864867
[TestCase("List(\"hello\", \"bye\").Select(x => x.ToUpper()).ToList().FluidAdd(\"test\")[0]", ExpectedResult = "HELLO", Category = "Complex expression,Fluid Functions")]

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ private bool EvaluateInstanceCreationWithNewKeyword(string expr, string restOfEx
13601360
|| stack.Peek() is ExpressionOperator))
13611361
{
13621362
string completeName = instanceCreationMatch.Groups["name"].Value;
1363-
Type type = GetTypeByFriendlyName(completeName, true);
1363+
Type type = GetTypeByFriendlyName(completeName);
13641364

13651365
i += instanceCreationMatch.Length;
13661366

@@ -2560,12 +2560,12 @@ private bool DefaultFunctions(string name, List<string> args, out object result)
25602560
return functionExists;
25612561
}
25622562

2563-
private Type GetTypeByFriendlyName(string typeName, bool tryWithNamespaceInclude = false)
2563+
private Type GetTypeByFriendlyName(string typeName)
25642564
{
25652565
Type result = null;
25662566
try
25672567
{
2568-
result = Type.GetType(typeName, false, true);
2568+
result = Type.GetType(typeName, false, !OptionCaseSensitiveEvaluationActive);
25692569

25702570
if (result == null)
25712571
{
@@ -2574,7 +2574,7 @@ private Type GetTypeByFriendlyName(string typeName, bool tryWithNamespaceInclude
25742574
return primaryTypesDict[match.Value.ManageCasing(OptionCaseSensitiveEvaluationActive)].ToString();
25752575
});
25762576

2577-
result = Type.GetType(typeName, false, true);
2577+
result = Type.GetType(typeName, false, !OptionCaseSensitiveEvaluationActive);
25782578
}
25792579

25802580
if (result == null)
@@ -2584,12 +2584,11 @@ private Type GetTypeByFriendlyName(string typeName, bool tryWithNamespaceInclude
25842584

25852585
for (int a = 0; a < Assemblies.Count && result == null; a++)
25862586
{
2587-
if (tryWithNamespaceInclude)
2588-
result = Type.GetType($"{typeName},{Assemblies[a].FullName}", false, true);
2587+
result = Type.GetType($"{typeName},{Assemblies[a].FullName}", false, !OptionCaseSensitiveEvaluationActive);
25892588

25902589
for (int i = 0; i < Namespaces.Count && result == null; i++)
25912590
{
2592-
result = Type.GetType($"{Namespaces[i]}.{typeName},{Assemblies[a].FullName}", false, true);
2591+
result = Type.GetType($"{Namespaces[i]}.{typeName},{Assemblies[a].FullName}", false, !OptionCaseSensitiveEvaluationActive);
25932592
}
25942593
}
25952594
}

0 commit comments

Comments
 (0)