1- using NUnit . Framework ;
1+ using Newtonsoft . Json ;
2+ using NUnit . Framework ;
3+ using Shouldly ;
24using System ;
35using System . Collections . Generic ;
46using System . Text . RegularExpressions ;
5- using Shouldly ;
6- using Newtonsoft . Json ;
77
88namespace CodingSeb . ExpressionEvaluator . Tests
99{
@@ -91,6 +91,23 @@ public void TypeTesting(string expression, Type type)
9191
9292 #region Test cases for DirectExpressionEvaluation
9393
94+ #region Other bases numbers
95+
96+ [ TestCase ( "0xab" , ExpectedResult = 0xab , Category = "HexNumber" ) ]
97+ [ TestCase ( "0xAB" , ExpectedResult = 0xab , Category = "HexNumber" ) ]
98+ [ TestCase ( "0x1" , ExpectedResult = 0x1 , Category = "HexNumber" ) ]
99+ [ TestCase ( "0xf" , ExpectedResult = 0xf , Category = "HexNumber" ) ]
100+ [ TestCase ( "-0xf" , ExpectedResult = - 0xf , Category = "HexNumber" ) ]
101+ [ TestCase ( "0xff_2a" , ExpectedResult = 0xff_2a , Category = "HexNumber" ) ]
102+
103+ [ TestCase ( "0b01100111" , ExpectedResult = 0b01100111 , Category = "BinaryNumber" ) ]
104+ [ TestCase ( "0b0100" , ExpectedResult = 0b0100 , Category = "BinaryNumber" ) ]
105+ [ TestCase ( "0b1010" , ExpectedResult = 0b1010 , Category = "BinaryNumber" ) ]
106+ [ TestCase ( "0b10_10" , ExpectedResult = 0b10_10 , Category = "BinaryNumber" ) ]
107+ [ TestCase ( "-0b10_10" , ExpectedResult = - 0b10_10 , Category = "BinaryNumber" ) ]
108+
109+ #endregion
110+
94111 #region Null Expression
95112 [ TestCase ( "null" , ExpectedResult = null , Category = "Null Expression" ) ]
96113 #endregion
@@ -391,6 +408,16 @@ public void TypeTesting(string expression, Type type)
391408 [ TestCase ( "3 --(2 *+(5 - 3 - +(-Abs(-5) - 6)))" , TestOf = typeof ( double ) , ExpectedResult = 29 , Category = "ParenthesisPriority" ) ]
392409 #endregion
393410
411+ #region BitwiseComplement
412+ [ TestCase ( "~-10" , TestOf = typeof ( int ) , ExpectedResult = 9 , Category = "BitwiseComplement" ) ]
413+ [ TestCase ( "~-2" , TestOf = typeof ( int ) , ExpectedResult = 1 , Category = "BitwiseComplement" ) ]
414+ [ TestCase ( "~-1" , TestOf = typeof ( int ) , ExpectedResult = 0 , Category = "BitwiseComplement" ) ]
415+ [ TestCase ( "~0" , TestOf = typeof ( int ) , ExpectedResult = - 1 , Category = "BitwiseComplement" ) ]
416+ [ TestCase ( "~1" , TestOf = typeof ( int ) , ExpectedResult = - 2 , Category = "BitwiseComplement" ) ]
417+ [ TestCase ( "~2" , TestOf = typeof ( int ) , ExpectedResult = - 3 , Category = "BitwiseComplement" ) ]
418+ [ TestCase ( "~10" , TestOf = typeof ( int ) , ExpectedResult = - 11 , Category = "BitwiseComplement" ) ]
419+ #endregion
420+
394421 #region SimpleModulo
395422 [ TestCase ( "-4 % 2" , TestOf = typeof ( int ) , ExpectedResult = 0 , Category = "SimpleModulo" ) ]
396423 [ TestCase ( "-3 % 2" , TestOf = typeof ( int ) , ExpectedResult = - 1 , Category = "SimpleModulo" ) ]
@@ -490,6 +517,24 @@ public void TypeTesting(string expression, Type type)
490517 [ TestCase ( "typeof(string) == 12.GetType()" , ExpectedResult = false , Category = "typeof keyword" ) ]
491518 #endregion
492519
520+ #region sizeof keyword
521+
522+ [ TestCase ( "sizeof(sbyte)" , ExpectedResult = sizeof ( sbyte ) , Category = "sizeof keyword" ) ]
523+ [ TestCase ( "sizeof(byte)" , ExpectedResult = sizeof ( byte ) , Category = "sizeof keyword" ) ]
524+ [ TestCase ( "sizeof(short)" , ExpectedResult = sizeof ( short ) , Category = "sizeof keyword" ) ]
525+ [ TestCase ( "sizeof(ushort)" , ExpectedResult = sizeof ( ushort ) , Category = "sizeof keyword" ) ]
526+ [ TestCase ( "sizeof(int)" , ExpectedResult = sizeof ( int ) , Category = "sizeof keyword" ) ]
527+ [ TestCase ( "sizeof(uint)" , ExpectedResult = sizeof ( uint ) , Category = "sizeof keyword" ) ]
528+ [ TestCase ( "sizeof(long)" , ExpectedResult = sizeof ( long ) , Category = "sizeof keyword" ) ]
529+ [ TestCase ( "sizeof(ulong)" , ExpectedResult = sizeof ( ulong ) , Category = "sizeof keyword" ) ]
530+ [ TestCase ( "sizeof(char)" , ExpectedResult = sizeof ( char ) , Category = "sizeof keyword" ) ]
531+ [ TestCase ( "sizeof(float)" , ExpectedResult = sizeof ( float ) , Category = "sizeof keyword" ) ]
532+ [ TestCase ( "sizeof(double)" , ExpectedResult = sizeof ( double ) , Category = "sizeof keyword" ) ]
533+ [ TestCase ( "sizeof(decimal)" , ExpectedResult = sizeof ( decimal ) , Category = "sizeof keyword" ) ]
534+ [ TestCase ( "sizeof(bool)" , ExpectedResult = sizeof ( bool ) , Category = "sizeof keyword" ) ]
535+
536+ #endregion
537+
493538 #region Create instance with new Keyword
494539 [ TestCase ( "new ClassForTest1().GetType()" , ExpectedResult = typeof ( ClassForTest1 ) , Category = "Create instance with new Keyword" ) ]
495540 [ TestCase ( "new ClassForTest2(15).GetType()" , ExpectedResult = typeof ( ClassForTest2 ) , Category = "Create instance with new Keyword" ) ]
@@ -970,9 +1015,7 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
9701015
9711016 yield return new TestCaseData ( "+x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary +" ) . Returns ( 5 ) ;
9721017 yield return new TestCaseData ( "-5 + +x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary +" ) . Returns ( 0 ) ;
973- yield return new TestCaseData ( "-5++x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary +" ) . Returns ( 0 ) ;
9741018 yield return new TestCaseData ( "5 + +x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary +" ) . Returns ( 10 ) ;
975- yield return new TestCaseData ( "5++x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary +" ) . Returns ( 10 ) ;
9761019 yield return new TestCaseData ( "5 - +x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary +" ) . Returns ( 0 ) ;
9771020 yield return new TestCaseData ( "5-+x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary +" ) . Returns ( 0 ) ;
9781021 yield return new TestCaseData ( "-5 - +x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary +" ) . Returns ( - 10 ) ;
@@ -985,23 +1028,15 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
9851028 yield return new TestCaseData ( "5 + -x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary -" ) . Returns ( 0 ) ;
9861029 yield return new TestCaseData ( "5+-x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary -" ) . Returns ( 0 ) ;
9871030 yield return new TestCaseData ( "-5 - -x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary -" ) . Returns ( 0 ) ;
988- yield return new TestCaseData ( "-5--x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary -" ) . Returns ( 0 ) ;
9891031 yield return new TestCaseData ( "5 - -x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary -" ) . Returns ( 10 ) ;
990- yield return new TestCaseData ( "5--x" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary -" ) . Returns ( 10 ) ;
9911032 yield return new TestCaseData ( "-x - -y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary -" ) . Returns ( 15 ) ;
992- yield return new TestCaseData ( "-x--y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary -" ) . Returns ( 15 ) ;
9931033 yield return new TestCaseData ( "+x - -y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( 25 ) ;
994- yield return new TestCaseData ( "+x--y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( 25 ) ;
9951034 yield return new TestCaseData ( "+x + -y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( - 15 ) ;
9961035 yield return new TestCaseData ( "+x+-y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( - 15 ) ;
9971036 yield return new TestCaseData ( "-x - +y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( - 25 ) ;
9981037 yield return new TestCaseData ( "-x-+y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( - 25 ) ;
9991038 yield return new TestCaseData ( "-x + +y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( 15 ) ;
1000- yield return new TestCaseData ( "-x++y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( 15 ) ;
1001- yield return new TestCaseData ( "-x++y" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-" ) . Returns ( 15 ) ;
10021039 yield return new TestCaseData ( "(-x + +y)" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-,Parenthis" ) . Returns ( 15 ) ;
1003- yield return new TestCaseData ( "(-x++y)" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-,Parenthis" ) . Returns ( 15 ) ;
1004- yield return new TestCaseData ( "-(-x++y)" , variablesForSimpleVariablesInjection , true ) . SetCategory ( "SimpleVariablesInjection,Unary both +-,Parenthis" ) . Returns ( - 15 ) ;
10051040
10061041 yield return new TestCaseData ( "ISTHISREAL" , variablesForSimpleVariablesInjection , false ) . SetCategory ( "SimpleVariablesInjection,IgnoreCase" ) . Returns ( true ) . SetCategory ( "Options, OptionCaseSensitiveEvaluationActive" ) ;
10071042 yield return new TestCaseData ( "isthisreal" , variablesForSimpleVariablesInjection , false ) . SetCategory ( "SimpleVariablesInjection,IgnoreCase" ) . Returns ( true ) . SetCategory ( "Options, OptionCaseSensitiveEvaluationActive" ) ;
@@ -1367,5 +1402,88 @@ public void ExceptionThrowingEvaluation(ExpressionEvaluator evaluator, string ex
13671402 }
13681403
13691404 #endregion
1405+
1406+ #region EvaluateWithSpecificEvaluator
1407+
1408+ #region TestCasesEvaluateWithSpecificEvaluator
1409+
1410+ public static IEnumerable < TestCaseData > TestCasesEvaluateWithSpecificEvaluator
1411+ {
1412+ get
1413+ {
1414+ #region Different culture for numbers
1415+
1416+ yield return new TestCaseData ( new ExpressionEvaluator
1417+ {
1418+ OptionNumberParsingDecimalSeparator = "," ,
1419+ }
1420+ , "0,5" )
1421+ . Returns ( 0.5 )
1422+ . SetCategory ( "Options" )
1423+ . SetCategory ( "Numbers Culture" ) ;
1424+
1425+ yield return new TestCaseData ( new ExpressionEvaluator
1426+ {
1427+ OptionNumberParsingDecimalSeparator = "'" ,
1428+ }
1429+ , "0'5" )
1430+ . Returns ( 0.5 )
1431+ . SetCategory ( "Options" )
1432+ . SetCategory ( "Numbers Culture" ) ;
1433+
1434+ yield return new TestCaseData ( new ExpressionEvaluator
1435+ {
1436+ OptionNumberParsingDecimalSeparator = "." ,
1437+ }
1438+ , "0.5" )
1439+ . Returns ( 0.5 )
1440+ . SetCategory ( "Options" )
1441+ . SetCategory ( "Numbers Culture" ) ;
1442+
1443+ yield return new TestCaseData ( new ExpressionEvaluator
1444+ {
1445+ OptionNumberParsingDecimalSeparator = "," ,
1446+ OptionFunctionArgumentsSeparator = ";"
1447+ }
1448+ , "Max(0,5; 0,7)" )
1449+ . Returns ( 0.7 )
1450+ . SetCategory ( "Options" )
1451+ . SetCategory ( "Numbers Culture" ) ;
1452+
1453+ yield return new TestCaseData ( new ExpressionEvaluator
1454+ {
1455+ OptionNumberParsingDecimalSeparator = "," ,
1456+ OptionNumberParsingThousandSeparator = "'" ,
1457+ OptionFunctionArgumentsSeparator = ";"
1458+ }
1459+ , "Max(1'200,5; 1'111'000,7)" )
1460+ . Returns ( 1111000.7 )
1461+ . SetCategory ( "Options" )
1462+ . SetCategory ( "Numbers Culture" ) ;
1463+
1464+ yield return new TestCaseData ( new ExpressionEvaluator
1465+ {
1466+ OptionNumberParsingDecimalSeparator = "," ,
1467+ OptionNumberParsingThousandSeparator = "'" ,
1468+ OptionInitializersSeparator = ";"
1469+ }
1470+ , "new double[]{1'200,5; 1'111'000,7}.Max()" )
1471+ . Returns ( 1111000.7 )
1472+ . SetCategory ( "Options" )
1473+ . SetCategory ( "Numbers Culture" ) ;
1474+
1475+ #endregion
1476+ }
1477+ }
1478+
1479+ #endregion
1480+
1481+ [ TestCaseSource ( nameof ( TestCasesEvaluateWithSpecificEvaluator ) ) ]
1482+ public object EvaluateWithSpecificEvaluator ( ExpressionEvaluator evaluator , string expression )
1483+ {
1484+ return evaluator . Evaluate ( expression ) ;
1485+ }
1486+
1487+ #endregion
13701488 }
13711489}
0 commit comments