| 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ |
| 8 | |
| 9 | import ( |
| 10 | "bytesscip-go gomod github.com/golang/go/src go1.18 bytes/" |
| 11 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.18 `encoding/binary`/" |
| 12 | "mathscip-go gomod github.com/golang/go/src go1.18 math/" |
| 13 | "reflectscip-go gomod github.com/golang/go/src go1.18 reflect/" |
| 14 | "testingscip-go gomod github.com/golang/go/src go1.18 testing/" |
| 15 | |
| 16 | "go.mongodb.org/mongo-driver/bson/primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/" |
| 17 | ) |
| 18 | |
| 19 | func TestArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/TestArrayBuilder().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 20 | bits := mathscip-go gomod github.com/golang/go/src go1.18 math/.Float64bitsscip-go gomod github.com/golang/go/src go1.18 math/Float64bits().(3.14159) |
| 21 | pi := make([]byte, 8) |
| 22 | binaryscip-go gomod github.com/golang/go/src go1.18 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.18 `encoding/binary`/LittleEndian..PutUint64scip-go gomod github.com/golang/go/src go1.18 `encoding/binary`/littleEndian#PutUint64().(pi, bits) |
| 23 | |
| 24 | testCases := []struct { |
| 25 | name string |
| 26 | fn interface{} |
| 27 | params []interface{} |
| 28 | expected []byte |
| 29 | }{ |
| 30 | { |
| 31 | "AppendInt32", |
| 32 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendInt32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendInt32()., |
| 33 | []interface{}{int32(256)}, |
| 34 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendInt32Elementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendInt32Element().(nil, "0", int32(256))), |
| 35 | }, |
| 36 | { |
| 37 | "AppendDouble", |
| 38 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendDoublescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDouble()., |
| 39 | []interface{}{float64(3.14159)}, |
| 40 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendDoubleElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDoubleElement().(nil, "0", float64(3.14159))), |
| 41 | }, |
| 42 | { |
| 43 | "AppendString", |
| 44 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendStringscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendString()., |
| 45 | []interface{}{"x"}, |
| 46 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendStringElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendStringElement().(nil, "0", "x")), |
| 47 | }, |
| 48 | { |
| 49 | "AppendDocument", |
| 50 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDocument()., |
| 51 | []interface{}{[]byte{0x05, 0x00, 0x00, 0x00, 0x00}}, |
| 52 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendDocumentElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDocumentElement().(nil, "0", []byte{0x05, 0x00, 0x00, 0x00, 0x00})), |
| 53 | }, |
| 54 | { |
| 55 | "AppendArray", |
| 56 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendArray()., |
| 57 | []interface{}{[]byte{0x05, 0x00, 0x00, 0x00, 0x00}}, |
| 58 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendArrayElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendArrayElement().(nil, "0", []byte{0x05, 0x00, 0x00, 0x00, 0x00})), |
| 59 | }, |
| 60 | { |
| 61 | "AppendBinary", |
| 62 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendBinaryscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendBinary()., |
| 63 | []interface{}{byte(0x02), []byte{0x01, 0x02, 0x03}}, |
| 64 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendBinaryElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendBinaryElement().(nil, "0", byte(0x02), []byte{0x01, 0x02, 0x03})), |
| 65 | }, |
| 66 | { |
| 67 | "AppendObjectID", |
| 68 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendObjectID()., |
| 69 | []interface{}{ |
| 70 | primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.ObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/ObjectID#{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C}, |
| 71 | }, |
| 72 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendObjectIDElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendObjectIDElement().(nil, "0", |
| 73 | primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.ObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/ObjectID#{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C})), |
| 74 | }, |
| 75 | { |
| 76 | "AppendBoolean", |
| 77 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendBooleanscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendBoolean()., |
| 78 | []interface{}{true}, |
| 79 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendBooleanElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendBooleanElement().(nil, "0", true)), |
| 80 | }, |
| 81 | { |
| 82 | "AppendDateTime", |
| 83 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendDateTimescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDateTime()., |
| 84 | []interface{}{int64(256)}, |
| 85 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendDateTimeElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDateTimeElement().(nil, "0", int64(256))), |
| 86 | }, |
| 87 | { |
| 88 | "AppendNull", |
| 89 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendNullscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendNull()., |
| 90 | []interface{}{}, |
| 91 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendNullElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendNullElement().(nil, "0")), |
| 92 | }, |
| 93 | { |
| 94 | "AppendRegex", |
| 95 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendRegexscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendRegex()., |
| 96 | []interface{}{"bar", "baz"}, |
| 97 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendRegexElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendRegexElement().(nil, "0", "bar", "baz")), |
| 98 | }, |
| 99 | { |
| 100 | "AppendJavaScript", |
| 101 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendJavaScriptscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendJavaScript()., |
| 102 | []interface{}{"barbaz"}, |
| 103 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendJavaScriptElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendJavaScriptElement().(nil, "0", "barbaz")), |
| 104 | }, |
| 105 | { |
| 106 | "AppendCodeWithScope", |
| 107 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendCodeWithScopescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendCodeWithScope()., |
| 108 | []interface{}{"barbaz", Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document#([]byte{0x05, 0x00, 0x00, 0x00, 0x00})}, |
| 109 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendCodeWithScopeElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendCodeWithScopeElement().(nil, "0", "barbaz", Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document#([]byte{0x05, 0x00, 0x00, 0x00, 0x00}))), |
| 110 | }, |
| 111 | { |
| 112 | "AppendTimestamp", |
| 113 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendTimestampscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendTimestamp()., |
| 114 | []interface{}{uint32(65536), uint32(256)}, |
| 115 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendTimestampElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendTimestampElement().(nil, "0", uint32(65536), uint32(256))), |
| 116 | }, |
| 117 | { |
| 118 | "AppendInt64", |
| 119 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendInt64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendInt64()., |
| 120 | []interface{}{int64(4294967296)}, |
| 121 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendInt64Elementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendInt64Element().(nil, "0", int64(4294967296))), |
| 122 | }, |
| 123 | { |
| 124 | "AppendDecimal128", |
| 125 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendDecimal128scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDecimal128()., |
| 126 | []interface{}{primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.NewDecimal128scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/NewDecimal128().(4294967296, 65536)}, |
| 127 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendDecimal128Elementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDecimal128Element().(nil, "0", primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.NewDecimal128scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/NewDecimal128().(4294967296, 65536))), |
| 128 | }, |
| 129 | { |
| 130 | "AppendMaxKey", |
| 131 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendMaxKeyscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendMaxKey()., |
| 132 | []interface{}{}, |
| 133 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendMaxKeyElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendMaxKeyElement().(nil, "0")), |
| 134 | }, |
| 135 | { |
| 136 | "AppendMinKey", |
| 137 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendMinKeyscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendMinKey()., |
| 138 | []interface{}{}, |
| 139 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendMinKeyElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendMinKeyElement().(nil, "0")), |
| 140 | }, |
| 141 | { |
| 142 | "AppendSymbol", |
| 143 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendSymbolscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendSymbol()., |
| 144 | []interface{}{"barbaz"}, |
| 145 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendSymbolElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendSymbolElement().(nil, "0", "barbaz")), |
| 146 | }, |
| 147 | { |
| 148 | "AppendDBPointer", |
| 149 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendDBPointerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDBPointer()., |
| 150 | []interface{}{"barbaz", |
| 151 | primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.ObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/ObjectID#{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C}}, |
| 152 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendDBPointerElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDBPointerElement().(nil, "0", "barbaz", |
| 153 | primitivescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/.ObjectIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/primitive`/ObjectID#{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C})), |
| 154 | }, |
| 155 | { |
| 156 | "AppendUndefined", |
| 157 | NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendUndefinedscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendUndefined()., |
| 158 | []interface{}{}, |
| 159 | BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendUndefinedElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendUndefinedElement().(nil, "0")), |
| 160 | }, |
| 161 | } |
| 162 | for _, tc := range testCases { |
| 163 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 164 | |
| 165 | fn := reflectscip-go gomod github.com/golang/go/src go1.18 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.18 reflect/ValueOf().(tc.fn) |
| 166 | if fn.Kindscip-go gomod github.com/golang/go/src go1.18 reflect/Value#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.18 reflect/.Funcscip-go gomod github.com/golang/go/src go1.18 reflect/Func. { |
| 167 | t.Fatalfscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatalf().("fn must be of kind Func but is a %v", fn.Kindscip-go gomod github.com/golang/go/src go1.18 reflect/Value#Kind().()) |
| 168 | } |
| 169 | if fn.Typescip-go gomod github.com/golang/go/src go1.18 reflect/Value#Type().().NumInscip-go gomod github.com/golang/go/src go1.18 reflect/Type#NumIn().() != len(tc.params) { |
| 170 | t.Fatalfscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatalf().("tc.params must match the number of params in tc.fn. params %d; fn %d", fn.Typescip-go gomod github.com/golang/go/src go1.18 reflect/Value#Type().().NumInscip-go gomod github.com/golang/go/src go1.18 reflect/Type#NumIn().(), len(tc.params)) |
| 171 | } |
| 172 | if fn.Typescip-go gomod github.com/golang/go/src go1.18 reflect/Value#Type().().NumOutscip-go gomod github.com/golang/go/src go1.18 reflect/Type#NumOut().() != 1 || fn.Typescip-go gomod github.com/golang/go/src go1.18 reflect/Value#Type().().Outscip-go gomod github.com/golang/go/src go1.18 reflect/Type#Out().(0) != reflectscip-go gomod github.com/golang/go/src go1.18 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.18 reflect/TypeOf().(&ArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#{}) { |
| 173 | t.Fatalfscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatalf().("fn must have one return parameter and it must be an ArrayBuilder.") |
| 174 | } |
| 175 | params := make([]reflectscip-go gomod github.com/golang/go/src go1.18 reflect/.Valuescip-go gomod github.com/golang/go/src go1.18 reflect/Value#, 0, len(tc.params)) |
| 176 | for _, param := range tc.params { |
| 177 | params = append(params, reflectscip-go gomod github.com/golang/go/src go1.18 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.18 reflect/ValueOf().(param)) |
| 178 | } |
| 179 | results := fn.Callscip-go gomod github.com/golang/go/src go1.18 reflect/Value#Call().(params) |
| 180 | got := results[0].Interfacescip-go gomod github.com/golang/go/src go1.18 reflect/Value#Interface().().(*ArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#).Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().() |
| 181 | want := tc.expected |
| 182 | if !bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.Equalscip-go gomod github.com/golang/go/src go1.18 bytes/Equal().(got, want) { |
| 183 | t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Did not receive expected bytes. got %v; want %v", got, want) |
| 184 | } |
| 185 | }) |
| 186 | } |
| 187 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().("TestBuildTwoElementsArray", func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 188 | intArr := BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendInt32Elementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendInt32Element().(nil, "0", int32(1))) |
| 189 | expected := BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendArrayElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendArrayElement().(AppendInt32Elementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendInt32Element().(nil, "0", int32(3)), "1", intArr)) |
| 190 | elem := NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendInt32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendInt32().(int32(1)).Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().() |
| 191 | result := NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().AppendInt32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendInt32().(int32(3)).AppendArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendArray().(elem).Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().() |
| 192 | if !bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.Equalscip-go gomod github.com/golang/go/src go1.18 bytes/Equal().(result, expected) { |
| 193 | t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Arrays do not match. got %v; want %v", result, expected) |
| 194 | } |
| 195 | }) |
| 196 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().("TestBuildInlineArray", func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 197 | docElement := BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendInt32Elementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendInt32Element().(nil, "0", int32(256))) |
| 198 | expected := Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document#(BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendArrayElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendArrayElement().(nil, "0", docElement))) |
| 199 | result := NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().StartArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#StartArray().().AppendInt32scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendInt32().(int32(256)).FinishArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#FinishArray().().Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().() |
| 200 | if !bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.Equalscip-go gomod github.com/golang/go/src go1.18 bytes/Equal().(result, expected) { |
| 201 | t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Documents do not match. got %v; want %v", result, expected) |
| 202 | } |
| 203 | }) |
| 204 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().("TestBuildNestedInlineArray", func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 205 | docElement := BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendDoubleElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendDoubleElement().(nil, "0", 3.14)) |
| 206 | docInline := BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendArrayElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendArrayElement().(nil, "0", docElement)) |
| 207 | expected := Documentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/Document#(BuildDocumentFromElementsscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocumentFromElements.(nil, AppendArrayElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendArrayElement().(nil, "0", docInline))) |
| 208 | result := NewArrayBuilderscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/NewArrayBuilder().().StartArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#StartArray().().StartArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#StartArray().().AppendDoublescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#AppendDouble().(3.14).FinishArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#FinishArray().().FinishArrayscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#FinishArray().().Buildscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/ArrayBuilder#Build().() |
| 209 | if !bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.Equalscip-go gomod github.com/golang/go/src go1.18 bytes/Equal().(result, expected) { |
| 210 | t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Documents do not match. got %v; want %v", result, expected) |
| 211 | } |
| 212 | }) |
| 213 | } |