diff --git a/.editorconfig b/.editorconfig
index 46bd2ece87..090a230876 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -4,6 +4,8 @@
[*]
charset = utf-8-bom
trim_trailing_whitespace = true
+insert_final_newline = true
+resharper_enforce_empty_line_at_end_of_file = true
[*.md]
indent_style = space
@@ -189,4 +191,4 @@ dotnet_diagnostic.IDE0070.severity = none
### SonarCloud Issues ###
# S907: Remove this use of 'goto'
-dotnet_diagnostic.S907.severity = none
\ No newline at end of file
+dotnet_diagnostic.S907.severity = none
diff --git a/.idea/.idea.Lucene.Net/.idea/.gitignore b/.idea/.idea.Lucene.Net/.idea/.gitignore
new file mode 100644
index 0000000000..e4c6e33706
--- /dev/null
+++ b/.idea/.idea.Lucene.Net/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/contentModel.xml
+/.idea.Lucene.Net.iml
+/projectSettingsUpdater.xml
+/modules.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.idea.Lucene.Net/.idea/.name b/.idea/.idea.Lucene.Net/.idea/.name
new file mode 100644
index 0000000000..79a5e09981
--- /dev/null
+++ b/.idea/.idea.Lucene.Net/.idea/.name
@@ -0,0 +1 @@
+Lucene.Net
\ No newline at end of file
diff --git a/.idea/.idea.Lucene.Net/.idea/encodings.xml b/.idea/.idea.Lucene.Net/.idea/encodings.xml
new file mode 100644
index 0000000000..df87cf951f
--- /dev/null
+++ b/.idea/.idea.Lucene.Net/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.Lucene.Net/.idea/indexLayout.xml b/.idea/.idea.Lucene.Net/.idea/indexLayout.xml
new file mode 100644
index 0000000000..7b08163ceb
--- /dev/null
+++ b/.idea/.idea.Lucene.Net/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.Lucene.Net/.idea/vcs.xml b/.idea/.idea.Lucene.Net/.idea/vcs.xml
new file mode 100644
index 0000000000..35eb1ddfbb
--- /dev/null
+++ b/.idea/.idea.Lucene.Net/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Directory.Build.targets b/Directory.Build.targets
index 92406f90f8..c39e315ef9 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -26,6 +26,7 @@
$(DefineConstants);FEATURE_SPANFORMATTABLE
+ $(DefineConstants);FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
diff --git a/build b/build
old mode 100644
new mode 100755
diff --git a/src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs b/src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs
index 2422201cdd..2bcea6cc3f 100644
--- a/src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs
+++ b/src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs
@@ -1,5 +1,7 @@
using Lucene.Net.Util;
using NUnit.Framework;
+using System;
+using System.Runtime.InteropServices;
using Assert = Lucene.Net.TestFramework.Assert;
namespace Lucene.Net.Expressions.JS
@@ -23,7 +25,7 @@ namespace Lucene.Net.Expressions.JS
public class TestJavascriptOperations : LuceneTestCase
{
-
+
private void AssertEvaluatesTo(string expression, long expected)
{
Expression evaluator = JavascriptCompiler.Compile(expression);
@@ -91,8 +93,17 @@ public virtual void TestDivisionOperation()
AssertEvaluatesTo("10/5/2", 1);
AssertEvaluatesTo("(27/9)/3", 1);
AssertEvaluatesTo("27/(9/3)", 9);
- //.NET Port division overflow cast to double evals to long.MinValue
- AssertEvaluatesTo("1/0", -9223372036854775808);
+ // LUCENENET: division overflow cast to double then to long evaluates to long.MinValue, except on arm64
+ // where it matches Java's behavior and Lucene's assertion. This only happens with the conv.i8 opcode with
+ // positive infinity on the stack. 1.0 / 0.0 == double.PositiveInfinity. In C#, if you cast
+ // double.PositiveInfinity to long in an unchecked context it returns 0. The C# spec for conversion in an
+ // unchecked context from double to long states "If the value of the operand is NaN or infinite, the result
+ // of the conversion is an unspecified value of the destination type." Likewise, the docs for conv.i8 state
+ // "If overflow occurs converting a floating-point type to an integer the value returned is unspecified."
+ // Essentially this is undefined behavior, so we are going to assert an architecture-specific value
+ // primarily to ensure it produces something rather than throws. CPU architectures other than arm64, x86,
+ // and x64 may produce different results.
+ AssertEvaluatesTo("1/0", RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? 9223372036854775807 : -9223372036854775808);
}
[Test]
@@ -373,7 +384,7 @@ public virtual void TestHexConst2()
AssertEvaluatesTo("0X0", 0);
AssertEvaluatesTo("0X1", 1);
AssertEvaluatesTo("0XF", 15);
- AssertEvaluatesTo("0X1234ABCDEF", 78193085935L);
+ AssertEvaluatesTo("0X1234ABCDEF", 78193085935L);
}
[Test]
diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs b/src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs
index 456de6e36b..9879c64749 100644
--- a/src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs
+++ b/src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs
@@ -180,4 +180,4 @@ public virtual void TestGetRandomAcceptedString()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs b/src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs
index 1e970ad26b..f882b146af 100644
--- a/src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs
+++ b/src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs
@@ -2,7 +2,6 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
-using System.Linq;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
using JCG = J2N.Collections.Generic;
@@ -148,4 +147,4 @@ public virtual void TestBasic()
TestFloor(c, "zzz", "goo");
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs b/src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs
index aab64f6162..13f3686af5 100644
--- a/src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs
+++ b/src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs
@@ -35,7 +35,7 @@ public virtual void TestRegexps()
int num = AtLeast(500);
for (int i = 0; i < num; i++)
{
- AssertAutomaton((new RegExp(AutomatonTestUtil.RandomRegexp(Random), RegExpSyntax.NONE)).ToAutomaton());
+ AssertAutomaton(new RegExp(AutomatonTestUtil.RandomRegexp(Random), RegExpSyntax.NONE).ToAutomaton());
}
}
@@ -89,4 +89,4 @@ private static void AssertAutomaton(Automaton a)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestDeterminizeLexicon.cs b/src/Lucene.Net.Tests/Util/Automaton/TestDeterminizeLexicon.cs
index a468d1ea3e..46794317c6 100644
--- a/src/Lucene.Net.Tests/Util/Automaton/TestDeterminizeLexicon.cs
+++ b/src/Lucene.Net.Tests/Util/Automaton/TestDeterminizeLexicon.cs
@@ -71,4 +71,4 @@ public void AssertLexicon()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestLevenshteinAutomata.cs b/src/Lucene.Net.Tests/Util/Automaton/TestLevenshteinAutomata.cs
index 15074fd30c..bc481d0fd4 100644
--- a/src/Lucene.Net.Tests/Util/Automaton/TestLevenshteinAutomata.cs
+++ b/src/Lucene.Net.Tests/Util/Automaton/TestLevenshteinAutomata.cs
@@ -53,7 +53,7 @@ public virtual void TestLev2()
[Test]
public virtual void TestNoWastedStates()
{
- AutomatonTestUtil.AssertNoDetachedStates((new LevenshteinAutomata("abc", false)).ToAutomaton(1));
+ AutomatonTestUtil.AssertNoDetachedStates(new LevenshteinAutomata("abc", false).ToAutomaton(1));
}
///
@@ -435,4 +435,4 @@ private int GetTDistance(string target, string other)
return Math.Abs(d[n][m]);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs b/src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs
index b86b7ae40b..bfb9f91812 100644
--- a/src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs
+++ b/src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs
@@ -1,6 +1,5 @@
using NUnit.Framework;
using Assert = Lucene.Net.TestFramework.Assert;
-using Console = Lucene.Net.Util.SystemConsole;
namespace Lucene.Net.Util.Automaton
{
@@ -250,7 +249,7 @@ public virtual void TestAgainstBrzozowski()
[Test]
public virtual void TestMinimizeHuge()
{
- (new RegExp("+-*(A|.....|BC)*]", RegExpSyntax.NONE)).ToAutomaton();
+ new RegExp("+-*(A|.....|BC)*]", RegExpSyntax.NONE).ToAutomaton();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestSpecialOperations.cs b/src/Lucene.Net.Tests/Util/Automaton/TestSpecialOperations.cs
index a0af00d968..ae4a83664d 100644
--- a/src/Lucene.Net.Tests/Util/Automaton/TestSpecialOperations.cs
+++ b/src/Lucene.Net.Tests/Util/Automaton/TestSpecialOperations.cs
@@ -59,4 +59,4 @@ public virtual void TestFiniteStrings()
Assert.IsTrue(strings.Contains(duck));
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs b/src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs
index 21656909ba..42e7125b24 100644
--- a/src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs
+++ b/src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs
@@ -244,7 +244,7 @@ public void TestRandomRegexes()
int num = AtLeast(250);
for (int i = 0; i < num; i++)
{
- AssertAutomaton((new RegExp(AutomatonTestUtil.RandomRegexp(Random), RegExpSyntax.NONE)).ToAutomaton());
+ AssertAutomaton(new RegExp(AutomatonTestUtil.RandomRegexp(Random), RegExpSyntax.NONE).ToAutomaton());
}
}
@@ -286,4 +286,4 @@ private static void AssertAutomaton(Automaton automaton)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/BaseSortTestCase.cs b/src/Lucene.Net.Tests/Util/BaseSortTestCase.cs
index 364504b9cb..6ed41f97bb 100644
--- a/src/Lucene.Net.Tests/Util/BaseSortTestCase.cs
+++ b/src/Lucene.Net.Tests/Util/BaseSortTestCase.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using System.Linq;
using Lucene.Net.Support;
using NUnit.Framework;
using System;
@@ -44,18 +43,19 @@ public virtual int CompareTo(Entry other)
}
private readonly bool stable;
- private readonly Random random;
protected BaseSortTestCase(bool stable)
{
this.stable = stable;
- this.random = Random;
}
public abstract Sorter NewSorter(Entry[] arr);
+ // LUCENENET specific
public class StableEntryComparer : IComparer
{
+ public static readonly StableEntryComparer Default = new StableEntryComparer();
+
public int Compare(Entry a, Entry b)
{
if (a.Value < b.Value) return -1;
@@ -69,7 +69,8 @@ public int Compare(Entry a, Entry b)
public virtual void AssertSorted(Entry[] original, Entry[] sorted)
{
Assert.AreEqual(original.Length, sorted.Length);
- Entry[] stableSorted = original.OrderBy(e => e, new StableEntryComparer()).ToArray();
+ Entry[] stableSorted = Arrays.CopyOf(original, original.Length);
+ Array.Sort(stableSorted, StableEntryComparer.Default); // LUCENENET: use StableEntryComparer
for (int i = 0; i < original.Length; ++i)
{
Assert.AreEqual(stableSorted[i].Value, sorted[i].Value);
@@ -82,8 +83,8 @@ public virtual void AssertSorted(Entry[] original, Entry[] sorted)
public virtual void SortTest(Entry[] arr)
{
- int o = random.Next(1000);
- var toSort = new Entry[o + arr.Length + random.Next(3)];
+ int o = Random.Next(1000);
+ var toSort = new Entry[o + arr.Length + Random.Next(3)];
Arrays.Copy(arr, 0, toSort, o, arr.Length);
Sorter sorter = NewSorter(toSort);
sorter.Sort(o, o + arr.Length);
@@ -94,50 +95,47 @@ public virtual void SortTest(Entry[] arr)
private void RandomStrategy(Entry[] arr, int i)
{
- arr[i] = new Entry(random.Next(), i);
+ arr[i] = new Entry(Random.Next(), i);
}
private void RandomLowCardinalityStrategy(Entry[] arr, int i)
{
- arr[i] = new Entry(random.nextInt(6), i);
+ arr[i] = new Entry(Random.nextInt(6), i);
}
private void AscendingStrategy(Entry[] arr, int i)
{
arr[i] = i == 0
- ? new Entry(random.nextInt(6), 0)
- : new Entry(arr[i - 1].Value + random.nextInt(6), i);
+ ? new Entry(Random.nextInt(6), 0)
+ : new Entry(arr[i - 1].Value + Random.nextInt(6), i);
}
private void DescendingStrategy(Entry[] arr, int i)
{
arr[i] = i == 0
- ? new Entry(random.nextInt(6), 0)
- : new Entry(arr[i - 1].Value - random.nextInt(6), i);
+ ? new Entry(Random.nextInt(6), 0)
+ : new Entry(arr[i - 1].Value - Random.nextInt(6), i);
}
-
+
private void StrictlyDescendingStrategy(Entry[] arr, int i)
{
arr[i] = i == 0
- ? new Entry(random.nextInt(6), 0)
- : new Entry(arr[i - 1].Value - TestUtil.NextInt32(random, 1, 5), i);
-
+ ? new Entry(Random.nextInt(6), 0)
+ : new Entry(arr[i - 1].Value - TestUtil.NextInt32(Random, 1, 5), i);
}
private void AscendingSequencesStrategy(Entry[] arr, int i)
{
arr[i] = i == 0
- ? new Entry(random.nextInt(6), 0)
- : new Entry(Rarely(random) ? random.nextInt(1000) : arr[i - 1].Value + random.nextInt(6), i);
-
+ ? new Entry(Random.nextInt(6), 0)
+ : new Entry(Rarely(Random) ? Random.nextInt(1000) : arr[i - 1].Value + Random.nextInt(6), i);
}
-
+
private void MostlyAscendingStrategy(Entry[] arr, int i)
{
arr[i] = i == 0
- ? new Entry(random.nextInt(6), 0)
- : new Entry(arr[i - 1].Value + TestUtil.NextInt32(random, -8, 10), i);
-
+ ? new Entry(Random.nextInt(6), 0)
+ : new Entry(arr[i - 1].Value + TestUtil.NextInt32(Random, -8, 10), i);
}
private void DoTest(Strategy strategy, int length)
@@ -169,7 +167,7 @@ public virtual void TestOne()
[Test]
public virtual void TestTwo()
{
- DoTest(RandomStrategy, 2);
+ DoTest(RandomLowCardinalityStrategy, 2);
}
[Test]
@@ -181,31 +179,31 @@ public virtual void TestRandom()
[Test]
public virtual void TestRandomLowCardinality()
{
- DoTest(RandomLowCardinalityStrategy, 2);
+ DoTest(RandomLowCardinalityStrategy);
}
[Test]
public virtual void TestAscending()
{
- DoTest(AscendingStrategy, 2);
+ DoTest(AscendingStrategy);
}
[Test]
public virtual void TestAscendingSequences()
{
- DoTest(AscendingSequencesStrategy, 2);
+ DoTest(AscendingSequencesStrategy);
}
[Test]
public virtual void TestDescending()
{
- DoTest(DescendingStrategy, 2);
+ DoTest(DescendingStrategy);
}
[Test]
public virtual void TestStrictlyDescendingStrategy()
{
- DoTest(StrictlyDescendingStrategy, 2);
+ DoTest(StrictlyDescendingStrategy);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs b/src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs
index 3867046094..ff321b8367 100644
--- a/src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs
+++ b/src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs
@@ -1,11 +1,14 @@
using Lucene.Net.Support;
using NUnit.Framework;
-using RandomizedTesting.Generators;
using System;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
using Int64 = J2N.Numerics.Int64;
+#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
+using RandomizedTesting.Generators; // for Random.NextInt64 extension method
+#endif
+
namespace Lucene.Net.Util.Fst
{
/*
@@ -338,4 +341,4 @@ private void NextInput(Random r, int[] ints)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs b/src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs
index f652109d94..3f0bc46638 100644
--- a/src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs
+++ b/src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs
@@ -428,4 +428,4 @@ private void Verify(BytesStore bytes, byte[] expected, int totalLength)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Util/Fst/TestFSTs.cs b/src/Lucene.Net.Tests/Util/Fst/TestFSTs.cs
index 9eaa6e14af..f21e68457d 100644
--- a/src/Lucene.Net.Tests/Util/Fst/TestFSTs.cs
+++ b/src/Lucene.Net.Tests/Util/Fst/TestFSTs.cs
@@ -2,7 +2,6 @@
using J2N.Threading.Atomic;
using Lucene.Net.Diagnostics;
using Lucene.Net.Index.Extensions;
-using Lucene.Net.Support;
using Lucene.Net.Util.Automaton;
using NUnit.Framework;
using RandomizedTesting.Generators;
@@ -10,7 +9,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
-using System.Linq;
using System.Text;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
@@ -128,7 +126,7 @@ public virtual void TestBasicFSA()
{
pairs.Add(new InputOutput