4

I tried

assert(anOption)(contains("x"))

But that only works for Iterables such as List or Seq.

Thilo
  • 257,207
  • 101
  • 511
  • 656

2 Answers2

5
assert(anOption)(isSome(equalTo("x")))
derpy
  • 66
  • 2
  • 1
    Welcome to SO. I would suggest you to provide relevant details with your answer. That will be helpful for others to better understand your answer. https://stackoverflow.com/help/how-to-answer – Muhammad Tariq Apr 30 '21 at 06:07
  • @MuhammadTariq I had no problem to understand the answer. – Thilo Apr 30 '21 at 07:06
  • 1
    @derpy, people from different age group, background and technical level use SO to get guidance. A lot of students and junior level devs/people are there who can't understand one-line code answers. Its better to properly describe question or answer that can easily be understandable to a large number of people. – Muhammad Tariq Apr 30 '21 at 10:13
1

Could also be assert(anOption)(equalTo(Some("x"))) - just using equality. Or if you want to use contains: assert(isTrue(anOption.contains("x"))) using the contains operator on option

Alan
  • 11
  • 1
  • Yeah, the first one works well and is simpler than the accepted answer. `isTrue` is not great because the failure message it will produce won't be descriptive. – Thilo May 03 '21 at 23:54