Skip to content

Commit 6f13524

Browse files
committed
feature: fix the binary compatibility regression and added tests for beEmpty
1 parent 063c019 commit 6f13524

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

common/shared/src/main/scala/org/specs2/collection/IsEmpty.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,30 @@ object IsEmpty extends IsEmptyLowPriority1:
1818
def isEmpty(t: Array[T]): Boolean =
1919
t.isEmpty
2020

21+
given seqIsEmpty[T]: IsEmpty[Seq[T]] with
22+
def isEmpty(t: Seq[T]): Boolean =
23+
t.isEmpty
24+
2125
trait IsEmptyLowPriority1 extends IsEmptyLowPriority2:
2226

23-
given iterableOnceIsEmpty: IsEmpty[IterableOnce[?]] with
24-
def isEmpty(t: IterableOnce[?]): Boolean =
25-
t.iterator.isEmpty
27+
given listIsEmpty[T]: IsEmpty[List[T]] with
28+
def isEmpty(t: List[T]): Boolean =
29+
t.isEmpty
30+
31+
given optionIsEmpty[T]: IsEmpty[Option[T]] with
32+
def isEmpty(t: Option[T]): Boolean =
33+
!t.isDefined
2634

2735
given eitherIsEmpty[E, T]: IsEmpty[Either[E, T]] with
2836
def isEmpty(t: Either[E, T]): Boolean =
2937
!t.toOption.isDefined
3038

3139
trait IsEmptyLowPriority2:
3240

41+
given iterableOnceIsEmpty: IsEmpty[IterableOnce[?]] with
42+
def isEmpty(t: IterableOnce[?]): Boolean =
43+
t.iterator.isEmpty
44+
3345
given stringIsEmpty: IsEmpty[String] with
3446
def isEmpty(t: String): Boolean =
3547
t.isEmpty

tests/jvm/src/test/scala/org/specs2/matcher/AnyMatchersSpec.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ class AnyMatchersSpec
3535
${false must beFalse}
3636
${(true must beFalse).message must ===("the value is true")}
3737

38+
beEmpty matches empty values
39+
${"" must beEmpty}
40+
${"x" must not(beEmpty)}
41+
${None must beEmpty}
42+
${Some(1) must not(beEmpty)}
43+
${Seq() must beEmpty}
44+
${Seq(1) must not(beEmpty)}
45+
${Map() must beEmpty}
46+
${Map(1 -> 2) must not(beEmpty)}
47+
${Set() must beEmpty}
48+
${Set(1) must not(beEmpty)}
49+
3850
beLike matches objects against a pattern
3951
${List(1, 2) must beLike { case List(a, b) => ok }}
4052
${List(1, 2) must beLike { case List(a, b) => (a + b) must ===(3) }}

0 commit comments

Comments
 (0)