Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reviewed Expression Tests as part of [Issue #259](https://github.com/apache/lucenenet/issues/259) #435

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ indent_size = 4

# C# files
[*.cs]
indent_style = space
indent_size = 4

#### Core EditorConfig Options ####

Expand Down
54 changes: 15 additions & 39 deletions src/Lucene.Net.Tests.Expressions/JS/TestCustomFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lucene.Net.Support;
using Lucene.Net.Support;
using Lucene.Net.Util;
using NUnit.Framework;
using System;
Expand Down Expand Up @@ -56,10 +56,7 @@ public virtual void TestDefaultList()
Assert.AreEqual(Math.Sqrt(20), expr.Evaluate(0, null), DELTA);
}

public static double ZeroArgMethod()
{
return 5;
}
public static double ZeroArgMethod() => 5;

/// <summary>tests a method with no arguments</summary>
[Test]
Expand All @@ -71,10 +68,7 @@ public virtual void TestNoArgMethod()
Assert.AreEqual(5, expr.Evaluate(0, null), DELTA);
}

public static double OneArgMethod(double arg1)
{
return 3 + arg1;
}
public static double OneArgMethod(double arg1) => 3 + arg1;

/// <summary>tests a method with one arguments</summary>
[Test]
Expand All @@ -86,18 +80,14 @@ public virtual void TestOneArgMethod()
Assert.AreEqual(6, expr.Evaluate(0, null), DELTA);
}

public static double ThreeArgMethod(double arg1, double arg2, double arg3)
{
return arg1 + arg2 + arg3;
}
public static double ThreeArgMethod(double arg1, double arg2, double arg3) => arg1 + arg2 + arg3;

/// <summary>tests a method with three arguments</summary>
[Test]
public virtual void TestThreeArgMethod()
{
IDictionary<string, MethodInfo> functions = new Dictionary<string, MethodInfo>();
functions["foo"] = GetType().GetMethod("ThreeArgMethod", new []{ typeof(double), typeof(
double), typeof(double)});
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);
}
Expand All @@ -113,10 +103,7 @@ public virtual void TestTwoMethods()
Assert.AreEqual(11, expr.Evaluate(0, null), DELTA);
}

public static string BogusReturnType()
{
return "bogus!";
}
public static string BogusReturnType() => "bogus!";

/// <summary>wrong return type: must be double</summary>
[Test]
Expand All @@ -135,10 +122,7 @@ public virtual void TestWrongReturnType()
}
}

public static double BogusParameterType(string s)
{
return 0;
}
public static double BogusParameterType(string s) => 0;

/// <summary>wrong param type: must be doubles</summary>
[Test]
Expand All @@ -153,15 +137,11 @@ public virtual void TestWrongParameterType()
}
catch (ArgumentException e)
{
Assert.IsTrue(e.Message.Contains("must take only double parameters"
));
Assert.IsTrue(e.Message.Contains("must take only double parameters"));
}
}

public virtual double NonStaticMethod()
{
return 0;
}
public virtual double NonStaticMethod() => 0;

/// <summary>wrong modifiers: must be static</summary>
[Test]
Expand All @@ -180,10 +160,7 @@ public virtual void TestWrongNotStatic()
}
}

internal static double NonPublicMethod()
{
return 0;
}
internal static double NonPublicMethod() => 0;

/// <summary>wrong modifiers: must be public</summary>
[Test]
Expand All @@ -205,10 +182,7 @@ public virtual void TestWrongNotPublic()

internal class NestedNotPublic
{
public static double Method()
{
return 0;
}
public static double Method() => 0;
}

/// <summary>wrong class modifiers: class containing method is not public</summary>
Expand All @@ -228,6 +202,9 @@ public virtual void TestWrongNestedNotPublic()
}
}


//LUCENENET: testClassLoader() was not ported. (May not apply to Lucene.Net)


internal static string MESSAGE = "This should not happen but it happens";

Expand All @@ -240,7 +217,7 @@ public static double Method()
}

/// <summary>the method throws an exception.</summary>
/// <remarks>the method throws an exception. We should check the stack trace that it contains the source code of the expression as file name.
/// <remarks>We should check the stack trace that it contains the source code of the expression as file name.
/// </remarks>
[Test]
public virtual void TestThrowingException()
Expand All @@ -265,7 +242,6 @@ public virtual void TestThrowingException()
}

/// <summary>test that namespaces work with custom expressions.</summary>
/// <remarks>test that namespaces work with custom expressions.</remarks>
[Test]
public virtual void TestNamespaces()
{
Expand Down
67 changes: 37 additions & 30 deletions src/Lucene.Net.Tests.Expressions/JS/TestJavascriptCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lucene.Net.Util;
using Lucene.Net.Util;
using NUnit.Framework;
using System;
using Assert = Lucene.Net.TestFramework.Assert;
Expand Down Expand Up @@ -40,7 +40,6 @@ public virtual void TestValidNamespaces()
Assert.IsNotNull(JavascriptCompiler.Compile("object0.object1.valid1"));
}

//TODO: change all exceptions to ParseExceptions
[Test]
public virtual void TestInvalidNamespaces()
{
Expand All @@ -49,39 +48,42 @@ public virtual void TestInvalidNamespaces()
JavascriptCompiler.Compile("object.0invalid");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
//expected
}
//expected

try
{
JavascriptCompiler.Compile("0.invalid");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
//expected
}
//expected

try
{
JavascriptCompiler.Compile("object..invalid");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
//expected
}
//expected

try
{
JavascriptCompiler.Compile(".invalid");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
//expected
}
}

//expected
[Test]
public virtual void TestInvalidCompiles()
{
Expand All @@ -90,44 +92,48 @@ public virtual void TestInvalidCompiles()
JavascriptCompiler.Compile("100 100");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
// expected
}
// expected exception
try
{
JavascriptCompiler.Compile("7*/-8");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
// expected
}
// expected exception

try
{
JavascriptCompiler.Compile("0y1234");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
// expected
}
// expected exception

try
{
JavascriptCompiler.Compile("500EE");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
// expected
}
// expected exception

try
{
JavascriptCompiler.Compile("500.5EE");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
// expected
}
}

Expand All @@ -139,30 +145,32 @@ public virtual void TestEmpty()
JavascriptCompiler.Compile(string.Empty);
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
// expected
}
// expected exception

try
{
JavascriptCompiler.Compile("()");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
// expected
}
// expected exception

try
{
JavascriptCompiler.Compile(" \r\n \n \t");
Assert.Fail();
}
catch (Exception)
catch (InvalidOperationException)
{
// expected
}
}

// expected exception
[Test]
public virtual void TestNull()
{
Expand All @@ -173,10 +181,10 @@ public virtual void TestNull()
}
catch (ArgumentNullException)
{
// expected
}
}

// expected exception
[Test]
public virtual void TestWrongArity()
{
Expand All @@ -187,18 +195,17 @@ public virtual void TestWrongArity()
}
catch (ArgumentException expected)
{
Assert.IsTrue(expected.Message.Contains("arguments for method call"
));
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"
));
Assert.IsTrue(expected.Message.Contains("arguments for method call"));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lucene.Net.Util;
using Lucene.Net.Util;
using NUnit.Framework;
using Assert = Lucene.Net.TestFramework.Assert;

Expand Down Expand Up @@ -361,10 +361,10 @@ public virtual void TestHexConst()
AssertEvaluatesTo("0x1", 1);
AssertEvaluatesTo("0xF", 15);
AssertEvaluatesTo("0x1234ABCDEF", 78193085935L);
AssertEvaluatesTo("1 << 0x1", 1 << (0x1));
AssertEvaluatesTo("1 << 0xA", 1 << (0xA));
AssertEvaluatesTo("0x1 << 2", unchecked((int)(0x1)) << 2);
AssertEvaluatesTo("0xA << 2", unchecked((int)(0xA)) << 2);
AssertEvaluatesTo("1 << 0x1", 1 << 0x1);
AssertEvaluatesTo("1 << 0xA", 1 << 0xA);
AssertEvaluatesTo("0x1 << 2", 0x1 << 2);
AssertEvaluatesTo("0xA << 2", 0xA << 2);
}

[Test]
Expand All @@ -373,7 +373,7 @@ public virtual void TestHexConst2()
AssertEvaluatesTo("0X0", 0);
AssertEvaluatesTo("0X1", 1);
AssertEvaluatesTo("0XF", 15);
AssertEvaluatesTo("0X1234ABCDEF", 78193085935L);
AssertEvaluatesTo("0X1234ABCDEF", 78193085935L);
}

[Test]
Expand All @@ -382,7 +382,7 @@ public virtual void TestOctalConst()
AssertEvaluatesTo("00", 0);
AssertEvaluatesTo("01", 1);
AssertEvaluatesTo("010", 8);
AssertEvaluatesTo("0123456777", 21913087);
AssertEvaluatesTo("0123456777", 21913087); // LUCENENET Comment: Javascript octal value via leading 0, compared with decimal value.
AssertEvaluatesTo("1 << 01", 1 << 0x1);
AssertEvaluatesTo("1 << 010", 1 << 0x8);
AssertEvaluatesTo("01 << 2", 0x1 << 2);
Expand Down
Loading