Skip to content

Commit 2981c03

Browse files
authored
Merge pull request #18 from codingseb/dev
Version 1.3.1.0
2 parents b5ed900 + a86fa15 commit 2981c03

22 files changed

+496
-53
lines changed

CodingSeb.ExpressionEvaluator.Tests/CodingSeb.ExpressionEvaluator.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<TargetFrameworks>net45;netcoreapp2.0</TargetFrameworks>
88
</PropertyGroup>
99
<ItemGroup>
10-
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
11-
<PackageReference Include="NUnit" Version="3.10.1" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
10+
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
11+
<PackageReference Include="NUnit" Version="3.11.0" />
12+
<PackageReference Include="NUnit3TestAdapter" Version="3.11.2" />
1313
<PackageReference Include="Shouldly" Version="3.0.2" />
1414
</ItemGroup>
1515
<ItemGroup>

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,123 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
566566

567567
#endregion
568568

569+
#region Array content assignation
570+
571+
yield return new TestCaseData(Resources.Script0033, null, null, null)
572+
.SetCategory("Script")
573+
.SetCategory("Array Assignation")
574+
.SetCategory("=")
575+
.Returns("[0,5,0]");
576+
577+
yield return new TestCaseData(Resources.Script0034, null, null, null)
578+
.SetCategory("Script")
579+
.SetCategory("Array instanciation")
580+
.SetCategory("new")
581+
.SetCategory("Array Assignation")
582+
.SetCategory("=")
583+
.Returns("[0,5,0]");
584+
585+
yield return new TestCaseData(Resources.Script0035, null, null, null)
586+
.SetCategory("Script")
587+
.SetCategory("Array instanciation")
588+
.SetCategory("new")
589+
.SetCategory("Array Assignation")
590+
.SetCategory("=")
591+
.Returns("[1,2,3]");
592+
593+
yield return new TestCaseData(Resources.Script0036, null, null, null)
594+
.SetCategory("Script")
595+
.SetCategory("Array instanciation")
596+
.SetCategory("new")
597+
.SetCategory("Array Assignation")
598+
.SetCategory("=")
599+
.Returns("[1,2,3]");
600+
601+
#endregion
602+
603+
#region StringEscape
604+
605+
yield return new TestCaseData(Resources.Script0037, null, null, null)
606+
.SetCategory("Script")
607+
.SetCategory("Variable Assignation")
608+
.SetCategory("StringEscape")
609+
.SetCategory("=")
610+
.Returns("\"");
611+
612+
yield return new TestCaseData(Resources.Script0038, null, null, null)
613+
.SetCategory("Script")
614+
.SetCategory("Variable Assignation")
615+
.SetCategory("StringEscape")
616+
.SetCategory("=")
617+
.Returns("(?<begining>[<]tag\\s+id\\s*[=]\\s*\"A.Id.For.The_Tag[^\"]*\"\\s*version\\s*[=]\\s*\")(?<version>[^\"]*)");
618+
619+
yield return new TestCaseData(Resources.Script0039, null, null, null)
620+
.SetCategory("Script")
621+
.SetCategory("Variable Assignation")
622+
.SetCategory("StringEscape")
623+
.SetCategory("StringInterpolate")
624+
.SetCategory("=")
625+
.Returns("(?<begining>[<]tag\\s+id\\s*[=]\\s*\"A.Id.For.The_Tag[^\"]*\"\\s*version\\s*[=]\\s*\")(?<version>[^\"]*)");
626+
627+
yield return new TestCaseData(Resources.Script0040, null, null, null)
628+
.SetCategory("Script")
629+
.SetCategory("Variable Assignation")
630+
.SetCategory("StringEscape")
631+
.SetCategory("StringInterpolate")
632+
.SetCategory("=")
633+
.Returns("(?<begining>[<]tag\\s+id\\s*[=]\\s*\"A.Id.For.The_Tag[^\"]*\"\\s*version\\s*[=]\\s*\")(?<version>[^\"]*)");
634+
635+
yield return new TestCaseData(Resources.Script0041, null, null, null)
636+
.SetCategory("Script")
637+
.SetCategory("Variable Assignation")
638+
.SetCategory("StringEscape")
639+
.SetCategory("StringInterpolate")
640+
.SetCategory("=")
641+
.Returns("(?<begining>[<]tag\\s+id\\s*[=]\\s*\"A.Id.For.The_Tag[^\"]*\"\\s*version\\s*[=]\\s*\")(?<version>[^\"]*)");
642+
643+
yield return new TestCaseData(Resources.Script0042, null, null, null)
644+
.SetCategory("Script")
645+
.SetCategory("Variable Assignation")
646+
.SetCategory("char")
647+
.SetCategory("doubleQuote")
648+
.SetCategory("=")
649+
.Returns('"');
650+
651+
yield return new TestCaseData(Resources.Script0043, null, null, null)
652+
.SetCategory("Script")
653+
.SetCategory("Variable Assignation")
654+
.SetCategory("StringInterpolate")
655+
.SetCategory("char")
656+
.SetCategory("doubleQuote")
657+
.SetCategory("=")
658+
.Returns("\"");
659+
660+
yield return new TestCaseData(Resources.Script0044, null, null, null)
661+
.SetCategory("Script")
662+
.SetCategory("Variable Assignation")
663+
.SetCategory("char")
664+
.SetCategory("StringInterpolate")
665+
.SetCategory("=")
666+
.Returns("\"");
667+
668+
yield return new TestCaseData(Resources.Script0045, null, null, null)
669+
.SetCategory("Script")
670+
.SetCategory("Variable Assignation")
671+
.SetCategory("StringEscape")
672+
.SetCategory("StringInterpolate")
673+
.SetCategory("=")
674+
.Returns("(?<begining>[<]tag\\s+id\\s*[=]\\s*\"A.Id.For.The_Tag[^\"]*\"\\s*version\\s*[=]\\s*\")(?<version>[^\"]*)");
675+
676+
yield return new TestCaseData(Resources.Script0046, null, null, null)
677+
.SetCategory("Script")
678+
.SetCategory("Variable Assignation")
679+
.SetCategory("StringEscape")
680+
.SetCategory("StringInterpolate")
681+
.SetCategory("=")
682+
.Returns("(?<begining>[<]tag\\s+id\\s*[=]\\s*\"A.Id.For.The_Tag[^\"]*\"\\s*version\\s*[=]\\s*\")(?<version>[^\"]*)");
683+
684+
#endregion
685+
569686
#endregion
570687

571688
#region while

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Text.RegularExpressions;
55
using Shouldly;
6+
using Newtonsoft.Json;
67

78
namespace CodingSeb.ExpressionEvaluator.Tests
89
{
@@ -103,12 +104,21 @@ public void TypeTesting(string expression, Type type)
103104
[TestCase("\"Hello World\"", TestOf = typeof(string), ExpectedResult = "Hello World", Category = "SimpleString")]
104105
[TestCase("\"Hello\" + \"World\"", TestOf = typeof(string), ExpectedResult = "HelloWorld", Category = "SimpleString")]
105106

107+
[TestCase("\"\\\"\"", TestOf = typeof(string), ExpectedResult = "\"", Category = "StringEscape")]
108+
[TestCase("\"\\n\"", TestOf = typeof(string), ExpectedResult = "\n", Category = "StringEscape")]
109+
[TestCase("\"\\r\"", TestOf = typeof(string), ExpectedResult = "\r", Category = "StringEscape")]
110+
[TestCase("\"\\t\"", TestOf = typeof(string), ExpectedResult = "\t", Category = "StringEscape")]
111+
[TestCase("\""+ @"\\" + "\"", TestOf = typeof(string), ExpectedResult = @"\", Category = "StringEscape")]
106112
[TestCase("\"" + @"\\\n" + "\"", TestOf = typeof(string), ExpectedResult = "\\\n", Category = "StringEscape")]
107113
[TestCase("@\"" + @"\\n" + "\"", TestOf = typeof(string), ExpectedResult = @"\\n", Category = "StringEscape")]
108114

109115
[TestCase("$\"Hello {1 + 2}\"", TestOf = typeof(string), ExpectedResult = "Hello 3", Category = "StringInterpolation")]
116+
[TestCase("$\"{'\"'}\"", TestOf = typeof(string), ExpectedResult = "\"", Category = "StringInterpolation")]
117+
[TestCase("$\"{ '\"' }\"", TestOf = typeof(string), ExpectedResult = "\"", Category = "StringInterpolation")]
118+
[TestCase("$\"{{\"", TestOf = typeof(string), ExpectedResult = "{", Category = "StringInterpolation")]
119+
[TestCase("$\"{ \"{\" }\"", TestOf = typeof(string), ExpectedResult = "{", Category = "StringInterpolation")]
110120
[TestCase("$\"Test { 5+5 } Test\"", TestOf = typeof(string), ExpectedResult = "Test 10 Test", Category = "StringInterpolation")]
111-
[TestCase("$\"Test { 5+5 + \" Test\" } Test\"", TestOf = typeof(string), ExpectedResult = "Test 10 Test Test", Category = "StringInterpolation")]
121+
[TestCase("$\"Test { 5+5 + \" Test\" } Test\"", TestOf = typeof(string), ExpectedResult = "Test 10 Test Test", Category = "StringInterpolation")]
112122
[TestCase("$\"Test { 5+5 + \" Test{\" } Test\"", TestOf = typeof(string), ExpectedResult = "Test 10 Test{ Test", Category = "StringInterpolation")]
113123
[TestCase("$\"Test { 5+5 + \" Test{{ }\" } Test\"", TestOf = typeof(string), ExpectedResult = "Test 10 Test{{ } Test", Category = "StringInterpolation")]
114124

@@ -133,9 +143,9 @@ public void TypeTesting(string expression, Type type)
133143
[TestCase("\"Text()\".Replace(\"(\", \",\")", TestOf = typeof(string), ExpectedResult = "Text,)", Category = "StringWithParenthisOrComaInFunctionsArgs")]
134144

135145
[TestCase("\"Hello,Test,What\".Split(ArrayOfType(typeof(char), ',')).Length", ExpectedResult = 3, Category = "StringSplit,ArrayOfType")]
136-
[TestCase("\"Hello,Test,What\".Split(ArrayOfType(typeof(char), ','))[0]", ExpectedResult = "Hello", Category = "StringSplit,ArrayOfType")]
137-
[TestCase("\"Hello,Test,What\".Split(ArrayOfType(typeof(char), ','))[1]", ExpectedResult = "Test", Category = "StringSplit,ArrayOfType")]
138-
[TestCase("\"Hello,Test,What\".Split(ArrayOfType(typeof(char), ','))[2]", ExpectedResult = "What", Category = "StringSplit,ArrayOfType")]
146+
[TestCase("\"Hello,Test,What\".Split(ArrayOfType(typeof(char), ',')).Json", ExpectedResult = "[\"Hello\",\"Test\",\"What\"]", Category = "StringSplit,ArrayOfType")]
147+
[TestCase("\"Hello,Test,What\".Split(new char[]{','}).Length", ExpectedResult = 3, Category = "StringSplit,Array instanciation")]
148+
[TestCase("\"Hello,Test,What\".Split(new char[]{','}).Json", ExpectedResult = "[\"Hello\",\"Test\",\"What\"]", Category = "StringSplit,Array instanciation")]
139149
#endregion
140150

141151
#region char
@@ -162,6 +172,7 @@ public void TypeTesting(string expression, Type type)
162172
[TestCase(@"'\r'", TestOf = typeof(char), ExpectedResult = '\r', Category = "char")]
163173
[TestCase(@"'\t'", TestOf = typeof(char), ExpectedResult = '\t', Category = "char")]
164174
[TestCase(@"'\v'", TestOf = typeof(char), ExpectedResult = '\v', Category = "char")]
175+
[TestCase("'\"'", TestOf = typeof(char), ExpectedResult = '"', Category = "char")]
165176
[TestCase("\"hello\" + ' ' + '!'", ExpectedResult = "hello !", Category = "char")]
166177
[TestCase("(int)'a'", ExpectedResult = 97, Category = "char")]
167178
[TestCase("'a'.CompareTo('b')", ExpectedResult = -1, Category = "char")]
@@ -860,9 +871,15 @@ public object DirectExpressionEvaluation(string expression)
860871
{
861872
ExpressionEvaluator evaluator = new ExpressionEvaluator();
862873

874+
evaluator.EvaluateVariable += Evaluator_EvaluateVariable;
875+
863876
evaluator.Namespaces.Add("CodingSeb.ExpressionEvaluator.Tests");
864877

865-
return evaluator.Evaluate(expression);
878+
object result = evaluator.Evaluate(expression);
879+
880+
evaluator.EvaluateVariable -= Evaluator_EvaluateVariable;
881+
882+
return result;
866883
}
867884

868885
#endregion
@@ -1088,6 +1105,10 @@ private void Evaluator_EvaluateVariable(object sender, VariableEvaluationEventAr
10881105
{
10891106
e.Value = 8;
10901107
}
1108+
else if (e.This != null && e.Name.Equals("Json"))
1109+
{
1110+
e.Value = JsonConvert.SerializeObject(e.This);
1111+
}
10911112
}
10921113

10931114
#endregion

CodingSeb.ExpressionEvaluator.Tests/Resources.Designer.cs

Lines changed: 160 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)