Skip to content

Commit 4f9b336

Browse files
committed
Fix :+ operator
1 parent 6f63492 commit 4f9b336

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

oolong-bson/src/main/scala/oolong/bson/bson.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ extension (bv: BsonValue)
7676
*
7777
* In a case of key collision bson1 values takes priority
7878
*/
79-
@inline def :+(other: BsonValue): BsonValue = merge(other, bv, false)
79+
@inline def :+(other: BsonValue): BsonValue = merge(bv, other, false)
8080

8181
/**
8282
* Merges two bson values
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package oolong.bson
2+
3+
import org.mongodb.scala.bson.*
4+
import org.scalatest.funsuite.AnyFunSuite
5+
import org.scalatest.matchers.should.Matchers
6+
7+
class BsonMergeSpec extends AnyFunSuite with Matchers {
8+
test(":+ document merge") {
9+
val doc1 = BsonDocument("field1" -> 10, "field2" -> 30)
10+
val doc2 = BsonDocument("field1" -> 20, "field3" -> 40)
11+
12+
val res = doc1 :+ doc2
13+
14+
res shouldBe BsonDocument("field1" -> 10, "field2" -> 30, "field3" -> 40)
15+
}
16+
17+
test("+: document merge") {
18+
val doc1 = BsonDocument("field1" -> 10, "field2" -> 30)
19+
val doc2 = BsonDocument("field1" -> 20, "field3" -> 40)
20+
21+
val res = doc1 +: doc2
22+
23+
res shouldBe BsonDocument("field1" -> 20, "field2" -> 30, "field3" -> 40)
24+
}
25+
}

0 commit comments

Comments
 (0)