Skip to content

Commit

Permalink
Add more wirebson tests (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Dec 25, 2024
1 parent 53d662e commit d102839
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 63 deletions.
83 changes: 48 additions & 35 deletions wirebson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package wirebson

import (
"encoding/hex"
"math"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -265,45 +266,69 @@ var normalTestCases = []normalTestCase{
name: "all",
raw: testutil.MustParseDumpFile("testdata", "all.hex"),
doc: MustDocument(
"document", MustArray(
MustDocument("", "foo", "bar", "baz", "", "qux"),
MustDocument(),
),
"array", MustArray(
MustArray(""),
MustArray("foo"),
MustArray(),
),
// TODO https://github.com/FerretDB/wire/issues/73
"float64", MustArray(42.13, 0.0, math.Copysign(0, -1), math.Inf(1), math.Inf(-1)),
"string", MustArray("foo", ""),
"binary", MustArray(
Binary{Subtype: BinaryUser, B: []byte{0x42}},
Binary{},
),
"objectID", MustArray(ObjectID{0x42}, ObjectID{}),
"bool", MustArray(true, false),
"datetime", MustArray(
time.Date(2021, 7, 27, 9, 35, 42, 123000000, time.UTC),
time.Time{},
),
"document", MustArray(
MustDocument("foo", ""),
MustDocument("", "foo"),
),
"double", MustArray(42.13, 0.0),
"null", MustArray(Null),
"regex", MustArray(Regex{Pattern: "p", Options: "o"}, Regex{}),
"int32", MustArray(int32(42), int32(0)),
"int64", MustArray(int64(42), int64(0)),
"objectID", MustArray(ObjectID{0x42}, ObjectID{}),
"string", MustArray("foo", ""),
"timestamp", MustArray(Timestamp(42), Timestamp(0)),
"decimal128", MustArray(Decimal128{L: 42, H: 13}),
"int64", MustArray(int64(42), int64(0)),
"decimal128", MustArray(Decimal128{L: 42, H: 13}, Decimal128{}),
),
mi: `
{
"document": [
{
"": "foo",
"bar": "baz",
"": "qux",
},
{},
],
"array": [
[
"",
],
[
"foo",
],
[],
],
"float64": [
42.13,
0.0,
-0.0,
+Inf,
-Inf,
],
"string": [
"foo",
"",
],
"binary": [
Binary(user:Qg==),
Binary(generic:),
],
"objectID": [
ObjectID(420000000000000000000000),
ObjectID(000000000000000000000000),
],
"bool": [
true,
false,
Expand All @@ -312,40 +337,28 @@ var normalTestCases = []normalTestCase{
2021-07-27T09:35:42.123Z,
0001-01-01T00:00:00Z,
],
"document": [
{
"foo": "",
},
{
"": "foo",
},
"null": [
null,
],
"double": [
42.13,
0.0,
"regex": [
/p/o,
//,
],
"int32": [
42,
0,
],
"int64": [
int64(42),
int64(0),
],
"objectID": [
ObjectID(420000000000000000000000),
ObjectID(000000000000000000000000),
],
"string": [
"foo",
"",
],
"timestamp": [
Timestamp(42),
Timestamp(0),
],
"int64": [
int64(42),
int64(0),
],
"decimal128": [
Decimal128(42,13),
Decimal128(0,0),
],
}`,
},
Expand Down
62 changes: 34 additions & 28 deletions wirebson/testdata/all.hex
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
00000000 b3 01 00 00 04 61 72 72 61 79 00 28 00 00 00 04 |.....array.(....|
00000010 30 00 0d 00 00 00 02 30 00 01 00 00 00 00 00 04 |0......0........|
00000020 31 00 10 00 00 00 02 30 00 04 00 00 00 66 6f 6f |1......0.....foo|
00000030 00 00 00 04 62 69 6e 61 72 79 00 16 00 00 00 05 |....binary......|
00000040 30 00 01 00 00 00 80 42 05 31 00 00 00 00 00 00 |0......B.1......|
00000050 00 04 62 6f 6f 6c 00 0d 00 00 00 08 30 00 01 08 |..bool......0...|
00000060 31 00 00 00 04 64 61 74 65 74 69 6d 65 00 1b 00 |1....datetime...|
00000070 00 00 09 30 00 2b e6 51 e7 7a 01 00 00 09 31 00 |...0.+.Q.z....1.|
00000080 00 28 d3 ed 7c c7 ff ff 00 04 64 6f 63 75 6d 65 |.(..|.....docume|
00000090 6e 74 00 29 00 00 00 03 30 00 0f 00 00 00 02 66 |nt.)....0......f|
000000a0 6f 6f 00 01 00 00 00 00 00 03 31 00 0f 00 00 00 |oo........1.....|
000000b0 02 00 04 00 00 00 66 6f 6f 00 00 00 04 64 6f 75 |......foo....dou|
000000c0 62 6c 65 00 1b 00 00 00 01 30 00 71 3d 0a d7 a3 |ble......0.q=...|
000000d0 10 45 40 01 31 00 00 00 00 00 00 00 00 00 00 04 |[email protected]...........|
000000e0 69 6e 74 33 32 00 13 00 00 00 10 30 00 2a 00 00 |int32......0.*..|
000000f0 00 10 31 00 00 00 00 00 00 04 69 6e 74 36 34 00 |..1.......int64.|
00000100 1b 00 00 00 12 30 00 2a 00 00 00 00 00 00 00 12 |.....0.*........|
00000110 31 00 00 00 00 00 00 00 00 00 00 04 6f 62 6a 65 |1...........obje|
00000120 63 74 49 44 00 23 00 00 00 07 30 00 42 00 00 00 |ctID.#....0.B...|
00000130 00 00 00 00 00 00 00 00 07 31 00 00 00 00 00 00 |.........1......|
00000140 00 00 00 00 00 00 00 00 04 73 74 72 69 6e 67 00 |.........string.|
00000150 18 00 00 00 02 30 00 04 00 00 00 66 6f 6f 00 02 |.....0.....foo..|
00000160 31 00 01 00 00 00 00 00 04 74 69 6d 65 73 74 61 |1........timesta|
00000170 6d 70 00 1b 00 00 00 11 30 00 2a 00 00 00 00 00 |mp......0.*.....|
00000180 00 00 11 31 00 00 00 00 00 00 00 00 00 00 04 64 |...1...........d|
00000190 65 63 69 6d 61 6c 31 32 38 00 18 00 00 00 13 30 |ecimal128......0|
000001a0 00 2a 00 00 00 00 00 00 00 0d 00 00 00 00 00 00 |.*..............|
000001b0 00 00 00 |...|
00000000 13 02 00 00 04 64 6f 63 75 6d 65 6e 74 00 36 00 |.....document.6.|
00000010 00 00 03 30 00 26 00 00 00 02 00 04 00 00 00 66 |...0.&.........f|
00000020 6f 6f 00 02 62 61 72 00 04 00 00 00 62 61 7a 00 |oo..bar.....baz.|
00000030 02 00 04 00 00 00 71 75 78 00 00 03 31 00 05 00 |......qux...1...|
00000040 00 00 00 00 04 61 72 72 61 79 00 20 00 00 00 04 |.....array. ....|
00000050 30 00 10 00 00 00 02 30 00 04 00 00 00 66 6f 6f |0......0.....foo|
00000060 00 00 04 31 00 05 00 00 00 00 00 04 66 6c 6f 61 |...1........floa|
00000070 74 36 34 00 3c 00 00 00 01 30 00 71 3d 0a d7 a3 |t64.<....0.q=...|
00000080 10 45 40 01 31 00 00 00 00 00 00 00 00 00 01 32 |[email protected]|
00000090 00 00 00 00 00 00 00 00 80 01 33 00 00 00 00 00 |..........3.....|
000000a0 00 00 f0 7f 01 34 00 00 00 00 00 00 00 f0 ff 00 |.....4..........|
000000b0 04 73 74 72 69 6e 67 00 18 00 00 00 02 30 00 04 |.string......0..|
000000c0 00 00 00 66 6f 6f 00 02 31 00 01 00 00 00 00 00 |...foo..1.......|
000000d0 04 62 69 6e 61 72 79 00 16 00 00 00 05 30 00 01 |.binary......0..|
000000e0 00 00 00 80 42 05 31 00 00 00 00 00 00 00 04 6f |....B.1........o|
000000f0 62 6a 65 63 74 49 44 00 23 00 00 00 07 30 00 42 |bjectID.#....0.B|
00000100 00 00 00 00 00 00 00 00 00 00 00 07 31 00 00 00 |............1...|
00000110 00 00 00 00 00 00 00 00 00 00 00 04 62 6f 6f 6c |............bool|
00000120 00 0d 00 00 00 08 30 00 01 08 31 00 00 00 04 64 |......0...1....d|
00000130 61 74 65 74 69 6d 65 00 1b 00 00 00 09 30 00 2b |atetime......0.+|
00000140 e6 51 e7 7a 01 00 00 09 31 00 00 28 d3 ed 7c c7 |.Q.z....1..(..|.|
00000150 ff ff 00 04 6e 75 6c 6c 00 08 00 00 00 0a 30 00 |....null......0.|
00000160 00 04 72 65 67 65 78 00 11 00 00 00 0b 30 00 70 |..regex......0.p|
00000170 00 6f 00 0b 31 00 00 00 00 04 69 6e 74 33 32 00 |.o..1.....int32.|
00000180 13 00 00 00 10 30 00 2a 00 00 00 10 31 00 00 00 |.....0.*....1...|
00000190 00 00 00 04 74 69 6d 65 73 74 61 6d 70 00 1b 00 |....timestamp...|
000001a0 00 00 11 30 00 2a 00 00 00 00 00 00 00 11 31 00 |...0.*........1.|
000001b0 00 00 00 00 00 00 00 00 00 04 69 6e 74 36 34 00 |..........int64.|
000001c0 1b 00 00 00 12 30 00 2a 00 00 00 00 00 00 00 12 |.....0.*........|
000001d0 31 00 00 00 00 00 00 00 00 00 00 04 64 65 63 69 |1...........deci|
000001e0 6d 61 6c 31 32 38 00 2b 00 00 00 13 30 00 2a 00 |mal128.+....0.*.|
000001f0 00 00 00 00 00 00 0d 00 00 00 00 00 00 00 13 31 |...............1|
00000200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000210 00 00 00 |...|

0 comments on commit d102839

Please sign in to comment.