Skip to content

Commit 261dd7f

Browse files
committed
Bson specification testing
Moved specifications submodule out of driver-core into a testing directory. Deleted old copy of bson specification tests and updated to use the submodule Fixed Json output for positive exponents to match the the extended json specification Added test exceptions to BinaryVectorGenericBsonTest Added BsonBinaryVector prose tests Added extra regression tests to ensure both explicit and implicit doubles with positive exponets parse as expected. JAVA-5877 JAVA-5779 JAVA-5782 JAVA-5652
1 parent 4eac65c commit 261dd7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+211
-5559
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "specifications"]
2-
path = driver-core/src/test/resources/specifications
2+
path = testing/resources/specifications
33
url = https://github.com/mongodb/specifications

bson/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ plugins {
2525

2626
base.archivesName.set("bson")
2727

28+
tasks.processTestResources {
29+
from("${rootProject.projectDir}/testing/resources")
30+
into("${layout.buildDirectory.get()}/resources/test")
31+
}
32+
2833
configureMavenPublication {
2934
pom {
3035
name.set("BSON")

bson/src/main/org/bson/BinaryVector.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.bson.annotations.Beta;
2020
import org.bson.annotations.Reason;
21+
import org.bson.diagnostics.Logger;
22+
import org.bson.diagnostics.Loggers;
2123

2224
import static org.bson.assertions.Assertions.isTrueArgument;
2325
import static org.bson.assertions.Assertions.notNull;
@@ -33,6 +35,7 @@
3335
* @since 5.3
3436
*/
3537
public abstract class BinaryVector {
38+
protected static final Logger LOGGER = Loggers.getLogger("BinaryVector");
3639
private final DataType dataType;
3740

3841
BinaryVector(final DataType dataType) {
@@ -67,6 +70,13 @@ public static PackedBitBinaryVector packedBitVector(final byte[] data, final byt
6770
notNull("data", data);
6871
isTrueArgument("Padding must be between 0 and 7 bits. Provided padding: " + padding, padding >= 0 && padding <= 7);
6972
isTrueArgument("Padding must be 0 if vector is empty. Provided padding: " + padding, padding == 0 || data.length > 0);
73+
if (padding > 0) {
74+
int mask = (1 << padding) - 1;
75+
if ((data[data.length - 1] & mask) != 0) {
76+
// JAVA-5848 in version 6.0.0 will convert this logging into an IllegalArgumentException
77+
LOGGER.warn("The last " + padding + " padded bits should be zero in the final byte.");
78+
}
79+
}
7080
return new PackedBitBinaryVector(data, padding);
7181
}
7282

bson/src/main/org/bson/json/ExtendedJsonDoubleConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ExtendedJsonDoubleConverter implements Converter<Double> {
2121
public void convert(final Double value, final StrictJsonWriter writer) {
2222
writer.writeStartObject();
2323
writer.writeName("$numberDouble");
24-
writer.writeString(Double.toString(value));
24+
writer.writeString(JsonDoubleHelper.toString(value));
2525
writer.writeEndObject();
2626

2727
}

bson/src/main/org/bson/json/JsonDoubleConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
class JsonDoubleConverter implements Converter<Double> {
2020
@Override
2121
public void convert(final Double value, final StrictJsonWriter writer) {
22-
writer.writeNumber(Double.toString(value));
22+
writer.writeNumber(JsonDoubleHelper.toString(value));
2323
}
2424
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.bson.json;
17+
18+
import java.util.regex.Pattern;
19+
20+
final class JsonDoubleHelper {
21+
22+
private static final Pattern POSITIVE_EXPONENT_PATTERN = Pattern.compile("E([^\\-]+)");
23+
private static final String POSITIVE_EXPONENT_REPLACER = "E+$1";
24+
25+
static String toString(final double value) {
26+
String doubleString = Double.toString(value);
27+
return POSITIVE_EXPONENT_PATTERN.matcher(doubleString).replaceAll(POSITIVE_EXPONENT_REPLACER);
28+
}
29+
30+
private JsonDoubleHelper() {
31+
}
32+
}

bson/src/main/org/bson/json/RelaxedExtendedJsonDoubleConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void convert(final Double value, final StrictJsonWriter writer) {
2424
if (value.isNaN() || value.isInfinite()) {
2525
FALLBACK_CONVERTER.convert(value, writer);
2626
} else {
27-
writer.writeNumber(Double.toString(value));
27+
writer.writeNumber(JsonDoubleHelper.toString(value));
2828
}
2929
}
3030
}

bson/src/test/resources/bson-binary-vector/float32.json

Lines changed: 0 additions & 50 deletions
This file was deleted.

bson/src/test/resources/bson-binary-vector/int8.json

Lines changed: 0 additions & 56 deletions
This file was deleted.

bson/src/test/resources/bson-binary-vector/packed_bit.json

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)