Skip to content

Commit 5959b7c

Browse files
codingsebSébastien Geiser
authored andcommitted
Correction of multiple bugs with String interpolation, doublequote char and string escape. + More string tests
1 parent 148f392 commit 5959b7c

15 files changed

+303
-20
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorScriptEvaluateTests.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,89 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
600600

601601
#endregion
602602

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+
603686
#endregion
604687

605688
#region while

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,21 @@ public void TypeTesting(string expression, Type type)
104104
[TestCase("\"Hello World\"", TestOf = typeof(string), ExpectedResult = "Hello World", Category = "SimpleString")]
105105
[TestCase("\"Hello\" + \"World\"", TestOf = typeof(string), ExpectedResult = "HelloWorld", Category = "SimpleString")]
106106

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")]
107112
[TestCase("\"" + @"\\\n" + "\"", TestOf = typeof(string), ExpectedResult = "\\\n", Category = "StringEscape")]
108113
[TestCase("@\"" + @"\\n" + "\"", TestOf = typeof(string), ExpectedResult = @"\\n", Category = "StringEscape")]
109114

110115
[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")]
111120
[TestCase("$\"Test { 5+5 } Test\"", TestOf = typeof(string), ExpectedResult = "Test 10 Test", Category = "StringInterpolation")]
112-
[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")]
113122
[TestCase("$\"Test { 5+5 + \" Test{\" } Test\"", TestOf = typeof(string), ExpectedResult = "Test 10 Test{ Test", Category = "StringInterpolation")]
114123
[TestCase("$\"Test { 5+5 + \" Test{{ }\" } Test\"", TestOf = typeof(string), ExpectedResult = "Test 10 Test{{ } Test", Category = "StringInterpolation")]
115124

@@ -163,6 +172,7 @@ public void TypeTesting(string expression, Type type)
163172
[TestCase(@"'\r'", TestOf = typeof(char), ExpectedResult = '\r', Category = "char")]
164173
[TestCase(@"'\t'", TestOf = typeof(char), ExpectedResult = '\t', Category = "char")]
165174
[TestCase(@"'\v'", TestOf = typeof(char), ExpectedResult = '\v', Category = "char")]
175+
[TestCase("'\"'", TestOf = typeof(char), ExpectedResult = '"', Category = "char")]
166176
[TestCase("\"hello\" + ' ' + '!'", ExpectedResult = "hello !", Category = "char")]
167177
[TestCase("(int)'a'", ExpectedResult = 97, Category = "char")]
168178
[TestCase("'a'.CompareTo('b')", ExpectedResult = -1, Category = "char")]

CodingSeb.ExpressionEvaluator.Tests/Resources.Designer.cs

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

CodingSeb.ExpressionEvaluator.Tests/Resources.resx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,34 @@
226226
<data name="Script0036" type="System.Resources.ResXFileRef, System.Windows.Forms">
227227
<value>resources\script0036.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
228228
</data>
229+
<data name="Script0037" type="System.Resources.ResXFileRef, System.Windows.Forms">
230+
<value>resources\script0037.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
231+
</data>
232+
<data name="Script0038" type="System.Resources.ResXFileRef, System.Windows.Forms">
233+
<value>resources\script0038.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
234+
</data>
235+
<data name="Script0039" type="System.Resources.ResXFileRef, System.Windows.Forms">
236+
<value>resources\script0039.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
237+
</data>
238+
<data name="Script0040" type="System.Resources.ResXFileRef, System.Windows.Forms">
239+
<value>resources\script0040.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
240+
</data>
241+
<data name="Script0041" type="System.Resources.ResXFileRef, System.Windows.Forms">
242+
<value>resources\script0041.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
243+
</data>
244+
<data name="Script0042" type="System.Resources.ResXFileRef, System.Windows.Forms">
245+
<value>resources\script0042.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
246+
</data>
247+
<data name="Script0043" type="System.Resources.ResXFileRef, System.Windows.Forms">
248+
<value>resources\script0043.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
249+
</data>
250+
<data name="Script0044" type="System.Resources.ResXFileRef, System.Windows.Forms">
251+
<value>resources\script0044.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
252+
</data>
253+
<data name="Script0045" type="System.Resources.ResXFileRef, System.Windows.Forms">
254+
<value>resources\script0045.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
255+
</data>
256+
<data name="Script0046" type="System.Resources.ResXFileRef, System.Windows.Forms">
257+
<value>resources\script0046.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
258+
</data>
229259
</root>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Script0037 */
2+
3+
test = "\"" ;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Script0038 */
2+
3+
xmlTagRegexPattern = "(?<begining>[<]tag\\s+id\\s*[=]\\s*\"A.Id.For.The_Tag[^\"]*\"\\s*version\\s*[=]\\s*\")(?<version>[^\"]*)";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Script0039 */
2+
3+
xmlTagRegexPattern = $"(?<begining>[<]tag\\s+id\\s*[=]\\s*{'"'}A.Id.For.The_Tag[^{'"'}]*{'"'}\\s*version\\s*[=]\\s*{'"'})(?<version>[^{'"'}]*)";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Script0040 */
2+
3+
xmlTagRegexPattern = $"(?<begining>[<]tag\\s+id\\s*[=]\\s*{"\""}A.Id.For.The_Tag[^{"\""}]*{"\""}\\s*version\\s*[=]\\s*{"\""})(?<version>[^{"\""}]*)";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Script0041 */
2+
3+
xmlTagRegexPattern = $@"(?<begining>[<]tag\s+id\s*[=]\s*{"\""}A.Id.For.The_Tag[^{"\""}]*{"\""}\s*version\s*[=]\s*{"\""})(?<version>[^{"\""}]*)";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Script0042 */
2+
3+
doubleQuoteChar = '"';

0 commit comments

Comments
 (0)