public virtual void TestDefaultList() { IDictionary <string, MethodInfo> functions = JavascriptCompiler.DEFAULT_FUNCTIONS; var expr = JavascriptCompiler.Compile("sqrt(20)", functions); Assert.AreEqual(Math.Sqrt(20), expr.Evaluate(0, null), DELTA); }
public virtual void TestEmpty() { try { JavascriptCompiler.Compile(string.Empty); Assert.Fail(); } catch (Exception) { } // expected exception try { JavascriptCompiler.Compile("()"); Assert.Fail(); } catch (Exception) { } // expected exception try { JavascriptCompiler.Compile(" \r\n \n \t"); Assert.Fail(); } catch (Exception) { } }
public virtual void TestEmpty() { try { JavascriptCompiler.Compile(string.Empty); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { // expected } try { JavascriptCompiler.Compile("()"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { // expected } try { JavascriptCompiler.Compile(" \r\n \n \t"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { // expected } }
private void AssertEvaluatesTo(string expression, double expected) { Expression evaluator = JavascriptCompiler.Compile(expression); double actual = evaluator.Evaluate(0, null); Assert.AreEqual(expected, actual, DELTA); }
public virtual void TestEmpty() { try { JavascriptCompiler.Compile(string.Empty); Assert.Fail(); } catch (InvalidOperationException) { // expected } try { JavascriptCompiler.Compile("()"); Assert.Fail(); } catch (InvalidOperationException) { // expected } try { JavascriptCompiler.Compile(" \r\n \n \t"); Assert.Fail(); } catch (InvalidOperationException) { // expected } }
public virtual void TestValidCompiles() { Assert.IsNotNull(JavascriptCompiler.Compile("100")); Assert.IsNotNull(JavascriptCompiler.Compile("valid0+100")); Assert.IsNotNull(JavascriptCompiler.Compile("valid0+\n100")); Assert.IsNotNull(JavascriptCompiler.Compile("logn(2, 20+10-5.0)")); }
private void AssertEvaluatesTo(string expression, long expected) { Expression evaluator = JavascriptCompiler.Compile(expression); long actual = (long)evaluator.Evaluate(0, null); Assert.AreEqual(expected, actual); }
public virtual void TestNoArgMethod() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = GetType().GetMethod("ZeroArgMethod"); var expr = JavascriptCompiler.Compile("foo()", functions); Assert.AreEqual(5, expr.Evaluate(0, null), DELTA); }
public virtual void TestThreeArgMethod() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = GetType().GetMethod("ThreeArgMethod", new [] { typeof(double), typeof(double), typeof(double) }); var expr = JavascriptCompiler.Compile("foo(3, 4, 5)", functions); Assert.AreEqual(12, expr.Evaluate(0, null), DELTA); }
public virtual void TestNamespaces() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo.bar"] = GetType().GetMethod("ZeroArgMethod"); string source = "foo.bar()"; var expr = JavascriptCompiler.Compile(source, functions); Assert.AreEqual(5, expr.Evaluate(0, null), DELTA); }
public virtual void TestTwoMethods() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = GetType().GetMethod("ZeroArgMethod"); functions["bar"] = GetType().GetMethod("OneArgMethod", new [] { typeof(double) }); var expr = JavascriptCompiler.Compile("foo() + bar(3)", functions); Assert.AreEqual(11, expr.Evaluate(0, null), DELTA); }
public virtual void TestNull() { try { JavascriptCompiler.Compile(null); Assert.Fail(); } catch (ArgumentNullException) { } }
public virtual void TestNull() { try { JavascriptCompiler.Compile(null); Assert.Fail(); } catch (Exception expected) when(expected.IsNullPointerException()) { // expected } }
public virtual void TestInvalidCompiles() { try { JavascriptCompiler.Compile("100 100"); Assert.Fail(); } catch (InvalidOperationException) { // expected } try { JavascriptCompiler.Compile("7*/-8"); Assert.Fail(); } catch (InvalidOperationException) { // expected } try { JavascriptCompiler.Compile("0y1234"); Assert.Fail(); } catch (InvalidOperationException) { // expected } try { JavascriptCompiler.Compile("500EE"); Assert.Fail(); } catch (InvalidOperationException) { // expected } try { JavascriptCompiler.Compile("500.5EE"); Assert.Fail(); } catch (InvalidOperationException) { // expected } }
public virtual void TestInvalidCompiles() { try { JavascriptCompiler.Compile("100 100"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { // expected } try { JavascriptCompiler.Compile("7*/-8"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { // expected } try { JavascriptCompiler.Compile("0y1234"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { // expected } try { JavascriptCompiler.Compile("500EE"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { // expected } try { JavascriptCompiler.Compile("500.5EE"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { // expected } }
public virtual void TestEmpty() { IDictionary <string, MethodInfo> functions = Collections.EmptyMap <string, MethodInfo>(); try { JavascriptCompiler.Compile("sqrt(20)", functions); Assert.Fail(); } catch (ArgumentException e) { Assert.IsTrue(e.Message.Contains("Unrecognized method")); } }
public virtual void TestWrongNotStatic() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = GetType().GetMethod("NonStaticMethod"); try { JavascriptCompiler.Compile("foo()", functions); Fail(); } catch (ArgumentException e) { IsTrue(e.Message.Contains("is not static")); } }
public virtual void TestWrongReturnType() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = GetType().GetMethod("BogusReturnType"); try { JavascriptCompiler.Compile("foo()", functions); Assert.Fail(); } catch (ArgumentException e) { Assert.IsTrue(e.Message.Contains("does not return a double")); } }
public virtual void TestWrongParameterType() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = GetType().GetMethod("BogusParameterType", new [] { typeof(string) }); try { JavascriptCompiler.Compile("foo(2)", functions); Assert.Fail(); } catch (ArgumentException e) { Assert.IsTrue(e.Message.Contains("must take only double parameters")); } }
public virtual void TestWrongNestedNotPublic() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = typeof(NestedNotPublic).GetMethod("Method"); try { JavascriptCompiler.Compile("foo()", functions); Assert.Fail(); } catch (ArgumentException e) { Assert.IsTrue(e.Message.Contains("is not public")); } }
public virtual void TestWrongNotPublic() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = GetType().GetMethod("NonPublicMethod", BindingFlags.NonPublic | BindingFlags.Static); try { JavascriptCompiler.Compile("foo()", functions); Assert.Fail(); } catch (ArgumentException e) { Assert.IsTrue(e.Message.Contains("is not public")); } }
public virtual void TestInvalidCompiles() { try { JavascriptCompiler.Compile("100 100"); Fail(); } catch (Exception) { } // expected exception try { JavascriptCompiler.Compile("7*/-8"); Fail(); } catch (Exception) { } // expected exception try { JavascriptCompiler.Compile("0y1234"); Fail(); } catch (Exception) { } // expected exception try { JavascriptCompiler.Compile("500EE"); Fail(); } catch (Exception) { } // expected exception try { JavascriptCompiler.Compile("500.5EE"); Fail(); } catch (Exception) { } }
public virtual void TestInvalidNamespaces() { try { JavascriptCompiler.Compile("object.0invalid"); Assert.Fail(); } catch (InvalidOperationException) { //expected } try { JavascriptCompiler.Compile("0.invalid"); Assert.Fail(); } catch (InvalidOperationException) { //expected } try { JavascriptCompiler.Compile("object..invalid"); Assert.Fail(); } catch (InvalidOperationException) { //expected } try { JavascriptCompiler.Compile(".invalid"); Assert.Fail(); } catch (InvalidOperationException) { //expected } }
public virtual void TestInvalidNamespaces() { try { JavascriptCompiler.Compile("object.0invalid"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { //expected } try { JavascriptCompiler.Compile("0.invalid"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { //expected } try { JavascriptCompiler.Compile("object..invalid"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { //expected } try { JavascriptCompiler.Compile(".invalid"); Assert.Fail(); } catch (Exception expected) when(expected.IsParseException()) { //expected } }
public virtual void TestWrongArity() { try { JavascriptCompiler.Compile("tan()"); Assert.Fail(); } catch (ArgumentException expected) { Assert.IsTrue(expected.Message.Contains("arguments for method call")); } try { JavascriptCompiler.Compile("tan(1, 1)"); Assert.Fail(); } catch (ArgumentException expected) { Assert.IsTrue(expected.Message.Contains("arguments for method call")); } }
public virtual void TestThrowingException() { IDictionary <string, MethodInfo> functions = new Dictionary <string, MethodInfo>(); functions["foo"] = typeof(StaticThrowingException).GetMethod("Method"); string source = "3 * foo() / 5"; var expr = JavascriptCompiler.Compile(source, functions); try { expr.Evaluate(0, null); Assert.Fail(); } catch (ArithmeticException e) { Assert.AreEqual(MESSAGE, e.Message); StringWriter sw = new StringWriter(); e.printStackTrace(); //.NET Port Assert.IsTrue(e.StackTrace.Contains("Lucene.Net.Expressions.CompiledExpression.Evaluate(Int32 , FunctionValues[] )")); } }
public virtual void TestInvalidNamespaces() { try { JavascriptCompiler.Compile("object.0invalid"); Fail(); } catch (Exception) { } //expected try { JavascriptCompiler.Compile("0.invalid"); Fail(); } catch (Exception) { } //expected try { JavascriptCompiler.Compile("object..invalid"); Fail(); } catch (Exception) { } //expected try { JavascriptCompiler.Compile(".invalid"); Fail(); } catch (Exception) { } }
public virtual void TestValidNamespaces() { Assert.IsNotNull(JavascriptCompiler.Compile("object.valid0")); Assert.IsNotNull(JavascriptCompiler.Compile("object0.object1.valid1")); }