Skip to content

Commit

Permalink
Fix :+ operator
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Jan 5, 2025
1 parent 6f63492 commit 4f9b336
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion oolong-bson/src/main/scala/oolong/bson/bson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extension (bv: BsonValue)
*
* In a case of key collision bson1 values takes priority
*/
@inline def :+(other: BsonValue): BsonValue = merge(other, bv, false)
@inline def :+(other: BsonValue): BsonValue = merge(bv, other, false)

/**
* Merges two bson values
Expand Down
25 changes: 25 additions & 0 deletions oolong-bson/src/test/scala/oolong/bson/BsonMergeSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package oolong.bson

import org.mongodb.scala.bson.*
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

class BsonMergeSpec extends AnyFunSuite with Matchers {
test(":+ document merge") {
val doc1 = BsonDocument("field1" -> 10, "field2" -> 30)
val doc2 = BsonDocument("field1" -> 20, "field3" -> 40)

val res = doc1 :+ doc2

res shouldBe BsonDocument("field1" -> 10, "field2" -> 30, "field3" -> 40)
}

test("+: document merge") {
val doc1 = BsonDocument("field1" -> 10, "field2" -> 30)
val doc2 = BsonDocument("field1" -> 20, "field3" -> 40)

val res = doc1 +: doc2

res shouldBe BsonDocument("field1" -> 20, "field2" -> 30, "field3" -> 40)
}
}

0 comments on commit 4f9b336

Please sign in to comment.