Add unit tests for Collections, #1116 #1124
Open
+299
−61
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add unit tests for Collections, including some Harmony tests.
Fixes #1116
Description
This PR adds unit tests for the
Lucene.Net.Support.Collections
type. Some of the tests are from Harmony where applicable, and others are lucenenet-specific.Similar to the discussion at #1121 (comment), this fixes some culture/locale inconsistencies with Java. It also removes some ToString methods that were Culture-aware overloads, but these overloads were unused (and this is an internal class, so that's not a breaking change).
As noted in the methods,
Collections.ToString
is based on thetoString
method from Java'sAbstractCollection
/AbstractMap
. In Java, this method is not Locale-aware, so that the output is consistent across locales. As such, it does not format numbers using i.e. a decimal comma, nor does it use a Locale-aware list separator. It is neither good for serialization/deserialization, nor for display in a UI. It is simply a string representation to be used for debugging and diagnostic purposes and is intended to be closer to a code representation than user-facing. (Even then it's arguably poor in some ways, as strings are not enclosed in double quotes, but it is what it is.)For example, this Java code (can be run with JBang if you'd like) sets the current Locale to
fr-FR
, which has a decimal comma, but it does not use that in the output. (Java does not have a list separator concept in its Locales, as far as I know, but if it did, that should use a semicolon forfr-FR
if it were Locale-aware.)Note the comma list separator and decimal point that indicates that the output is not Locale-aware. I set up the List-based test to exactly mimic this behavior, and assert the same output. This discovered that the test failed for cultures with a decimal comma, since it was just calling
.ToString()
on the value, which will use the current thread's culture. I changed this to useConvert.ToString
with passing in the invariant culture to match Java's behavior. These ToString methods are only used in building exception messages or console app outputs so that fits the bill of diagnostic purposes that do not need to be locale-aware.Additionally, it was discovered that the Object-based ToString method could fail if the argument was null, so this has been fixed along with making the file enabled for nullable type checking. This caused some inconsistencies in warnings between .NET Framework, .NET Standard, and .NET 8, so if it seems like the annotations are a little too much, this was likely because of getting warnings in one of the other targets. In particular, the private IComparer implementations were made aggressively nullable.