Skip to content

Commit 563e8eb

Browse files
committed
Add failing test: Fix Seq/Array atOrElse throwing IndexOutOfBoundsException for missing indices
1 parent c13e13e commit 563e8eb

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.softwaremill.quicklens
2+
3+
import org.scalatest.flatspec.AnyFlatSpec
4+
import org.scalatest.matchers.should.Matchers
5+
6+
class ModifySeqAtOrElseTest extends AnyFlatSpec with Matchers {
7+
8+
case class Item(name: String)
9+
10+
it should "modify an existing element using atOrElse" in {
11+
val items = List(Item("a"), Item("b"))
12+
modify(items)(_.atOrElse(1, Item("default")).name).using(_.toUpperCase) should be(
13+
List(Item("a"), Item("B"))
14+
)
15+
}
16+
17+
it should "use the default for a missing index instead of throwing" in {
18+
val items = List(Item("a"), Item("b"))
19+
modify(items)(_.atOrElse(5, Item("default")).name).using(_.toUpperCase) should be(
20+
List(Item("a"), Item("b"), Item("DEFAULT"))
21+
)
22+
}
23+
}

0 commit comments

Comments
 (0)