...
1
2
3
4
5
6
7 package options
8
9 import (
10 "bytes"
11 "testing"
12
13 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
14 )
15
16 func TestCollation(t *testing.T) {
17 t.Run("TestCollationToDocument", func(t *testing.T) {
18 c := &Collation{
19 Locale: "locale",
20 CaseLevel: true,
21 CaseFirst: "first",
22 Strength: 1,
23 NumericOrdering: true,
24 Alternate: "alternate",
25 MaxVariable: "maxVariable",
26 Normalization: true,
27 Backwards: true,
28 }
29
30 doc := c.ToDocument()
31 expected := bsoncore.BuildDocumentFromElements(nil,
32 bsoncore.AppendStringElement(nil, "locale", "locale"),
33 bsoncore.AppendBooleanElement(nil, "caseLevel", (true)),
34 bsoncore.AppendStringElement(nil, "caseFirst", ("first")),
35 bsoncore.AppendInt32Element(nil, "strength", (1)),
36 bsoncore.AppendBooleanElement(nil, "numericOrdering", (true)),
37 bsoncore.AppendStringElement(nil, "alternate", ("alternate")),
38 bsoncore.AppendStringElement(nil, "maxVariable", ("maxVariable")),
39 bsoncore.AppendBooleanElement(nil, "normalization", (true)),
40 bsoncore.AppendBooleanElement(nil, "backwards", (true)),
41 )
42
43 if !bytes.Equal(doc, expected) {
44 t.Fatalf("collation did not match expected. got %v; wanted %v", doc, expected)
45 }
46 })
47 }
48
View as plain text