11using NUnit . Framework ;
2- using Should ;
3- using System ;
42using System . Collections . Generic ;
53using System . Text . RegularExpressions ;
64
@@ -11,21 +9,30 @@ public class ExpressionEvaluatorScriptEvaluateTests
119 {
1210 private static Regex removeAllWhiteSpacesRegex = new Regex ( @"\s+" ) ;
1311
12+ #region Scripts that must succeed
13+
1414 public static IEnumerable < TestCaseData > TestCasesForScriptEvaluateTests
1515 {
1616 get
1717 {
18- // while
18+ #region while
19+
1920 yield return new TestCaseData ( Resources . Script0001 , null , true ) . SetCategory ( "Script" ) . SetCategory ( "while" ) . SetCategory ( "variable assignation" ) . SetCategory ( "++" ) . SetCategory ( "+=" ) . Returns ( "0,1,2,3,4" ) ;
2021 yield return new TestCaseData ( removeAllWhiteSpacesRegex . Replace ( Resources . Script0001 , "" ) , null , true ) . SetCategory ( "Script" ) . SetCategory ( "while" ) . SetCategory ( "variable assignation" ) . SetCategory ( "++" ) . SetCategory ( "+=" ) . Returns ( "0,1,2,3,4" ) ;
2122
22- // for
23+ #endregion
24+
25+ #region for
26+
2327 yield return new TestCaseData ( Resources . Script0002 , null , true ) . SetCategory ( "Script" ) . SetCategory ( "for" ) . SetCategory ( "variable assignation" ) . SetCategory ( "++" ) . SetCategory ( "+=" ) . Returns ( "0,1,2,3,4" ) ;
2428 yield return new TestCaseData ( removeAllWhiteSpacesRegex . Replace ( Resources . Script0002 , "" ) , null , true ) . SetCategory ( "Script" ) . SetCategory ( "for" ) . SetCategory ( "variable assignation" ) . SetCategory ( "++" ) . SetCategory ( "+=" ) . Returns ( "0,1,2,3,4" ) ;
2529 yield return new TestCaseData ( Resources . Script0003 , null , true ) . SetCategory ( "Script" ) . SetCategory ( "for" ) . SetCategory ( "variable assignation" ) . SetCategory ( "++" ) . SetCategory ( "+=" ) . Returns ( "0,1,2,3,4" ) ;
2630 yield return new TestCaseData ( removeAllWhiteSpacesRegex . Replace ( Resources . Script0003 , "" ) , null , true ) . SetCategory ( "Script" ) . SetCategory ( "for" ) . SetCategory ( "variable assignation" ) . SetCategory ( "++" ) . SetCategory ( "+=" ) . Returns ( "0,1,2,3,4" ) ;
2731
28- // if, else if, else
32+ #endregion
33+
34+ #region if, else if, else
35+
2936 yield return new TestCaseData ( Resources . Script0004 . Replace ( "[valx]" , "0" ) . Replace ( "[valy]" , "1" ) , null , true ) . SetCategory ( "Script" ) . SetCategory ( "if" ) . SetCategory ( "variable assignation" ) . Returns ( 1 ) ;
3037 yield return new TestCaseData ( removeAllWhiteSpacesRegex . Replace ( Resources . Script0004 . Replace ( "[valx]" , "0" ) . Replace ( "[valy]" , "1" ) , "" ) . Replace ( "else" , "else " ) , null , true ) . SetCategory ( "Script" ) . SetCategory ( "if" ) . SetCategory ( "variable assignation" ) . Returns ( 1 ) ;
3138 yield return new TestCaseData ( Resources . Script0004 . Replace ( "[valx]" , "-1" ) . Replace ( "[valy]" , "1" ) , null , true ) . SetCategory ( "Script" ) . SetCategory ( "if" ) . SetCategory ( "variable assignation" ) . Returns ( 1 ) ;
@@ -57,6 +64,8 @@ public static IEnumerable<TestCaseData> TestCasesForScriptEvaluateTests
5764
5865 yield return new TestCaseData ( Resources . Script0005 . Replace ( "[valx]" , "1" ) . Replace ( "[valy]" , "0" ) , null , true ) . SetCategory ( "Script" ) . SetCategory ( "if" ) . SetCategory ( "variable assignation" ) . Returns ( 4 ) ;
5966 yield return new TestCaseData ( removeAllWhiteSpacesRegex . Replace ( Resources . Script0005 . Replace ( "[valx]" , "1" ) . Replace ( "[valy]" , "0" ) , "" ) . Replace ( "else" , "else " ) , null , true ) . SetCategory ( "Script" ) . SetCategory ( "if" ) . SetCategory ( "variable assignation" ) . Returns ( 4 ) ;
67+
68+ #endregion
6069 }
6170 }
6271
@@ -73,5 +82,43 @@ public object TestCasesForScriptEvaluate(string script, Dictionary<string, objec
7382
7483 return evaluator . ScriptEvaluate ( script ) ;
7584 }
85+
86+ #endregion
87+
88+ #region Remove Comments
89+
90+ public static IEnumerable < TestCaseData > TestCasesForRemoveCommentsTests
91+ {
92+ get
93+ {
94+ yield return new TestCaseData ( "// simple line comment" ) . SetCategory ( "RemoveComments" ) . Returns ( " " ) ;
95+ yield return new TestCaseData ( "/* simple block comment */" ) . SetCategory ( "RemoveComments" ) . Returns ( " " ) ;
96+ yield return new TestCaseData ( "/* multi line\r \n block comment */" ) . SetCategory ( "RemoveComments" ) . Returns ( "\r \n " ) ;
97+ yield return new TestCaseData ( "/* multi line\r block comment */" ) . SetCategory ( "RemoveComments" ) . Returns ( "\r " ) ;
98+ yield return new TestCaseData ( "/* multi line\n block comment */" ) . SetCategory ( "RemoveComments" ) . Returns ( "\n " ) ;
99+ yield return new TestCaseData ( @"a = ""apple""; // test" ) . SetCategory ( "RemoveComments" ) . Returns ( @"a = ""apple""; " ) ;
100+ yield return new TestCaseData ( @"a = ""apple""; /* test */" ) . SetCategory ( "RemoveComments" ) . Returns ( @"a = ""apple""; " ) ;
101+ yield return new TestCaseData ( @"// /*comment within comments */" ) . SetCategory ( "RemoveComments" ) . Returns ( @" " ) ;
102+ yield return new TestCaseData ( @"/* //comment within comments */" ) . SetCategory ( "RemoveComments" ) . Returns ( @" " ) ;
103+ yield return new TestCaseData ( @"// bla bla /*comment within comments */ bla bla" ) . SetCategory ( "RemoveComments" ) . Returns ( @" " ) ;
104+ yield return new TestCaseData ( @"/* bla bla //comment within comments */" ) . SetCategory ( "RemoveComments" ) . Returns ( @" " ) ;
105+ yield return new TestCaseData ( @"// ""bla bla"" " ) . SetCategory ( "RemoveComments" ) . Returns ( @" " ) ;
106+ yield return new TestCaseData ( @"/* ""bla bla"" */" ) . SetCategory ( "RemoveComments" ) . Returns ( @" " ) ;
107+ yield return new TestCaseData ( @"""// test """ ) . SetCategory ( "RemoveComments" ) . SetCategory ( "Not a comments" ) . Returns ( @"""// test """ ) ;
108+ yield return new TestCaseData ( @"""/* test */""" ) . SetCategory ( "RemoveComments" ) . SetCategory ( "Not a comments" ) . Returns ( @"""/* test */""" ) ;
109+ yield return new TestCaseData ( @"""bla bla // test """ ) . SetCategory ( "RemoveComments" ) . SetCategory ( "Not a comments" ) . Returns ( @"""bla bla // test """ ) ;
110+ yield return new TestCaseData ( @"""bla bla /* test */ bla bla""" ) . SetCategory ( "RemoveComments" ) . SetCategory ( "Not a comments" ) . Returns ( @"""bla bla /* test */ bla bla""" ) ;
111+ }
112+ }
113+
114+ [ TestCaseSource ( nameof ( TestCasesForRemoveCommentsTests ) ) ]
115+ public string RemoveCommentsTests ( string script )
116+ {
117+ ExpressionEvaluator evaluator = new ExpressionEvaluator ( ) ;
118+
119+ return evaluator . RemoveComments ( script ) ;
120+ }
121+
122+ #endregion
76123 }
77124}
0 commit comments