|
| 1 | +package com.us.dsb.explore.libs.scalatest |
| 2 | + |
| 3 | +import org.scalatest.funspec.AnyFunSpec |
| 4 | + |
| 5 | +class ScratchTest extends AnyFunSpec { |
| 6 | + |
| 7 | + // https://www.scalatest.org/user_guide/using_matchers#expectedExceptions |
| 8 | + // https://www.scalatest.org/user_guide/using_matchers#usingCustomMatchers |
| 9 | + // https://www.scalatest.org/user_guide/using_matchers#logicalExpressions |
| 10 | + // https://www.scalatest.org/user_guide/using_matchers#checkingThatCodeDoesNotCompile |
| 11 | + // https://www.scalatest.org/user_guide/using_matchers#inspectorShorthands |
| 12 | + |
| 13 | + it("EitherValues") { |
| 14 | + val right: Either[String, Int] = Right(1) |
| 15 | + |
| 16 | + /* Without EitherValues, left/right failure gets simple "Either.left.get on Right" |
| 17 | + with test line number down a bit in stack (but still linked in IntelliJ): |
| 18 | + Either.left.get on Right |
| 19 | + java.util.NoSuchElementException: Either.left.get on Right |
| 20 | + at scala.util.Either$LeftProjection.get(Either.scala:537) |
| 21 | + at com.us.dsb.explore.libs.scalatest.ScratchTest.$anonfun$new$1(ScratchTest.scala:10) |
| 22 | + at ... |
| 23 | + */ |
| 24 | + //assert("123" == right.left.get) |
| 25 | + assert(1 == right.right.get) |
| 26 | + |
| 27 | + import org.scalatest.EitherValues._ |
| 28 | + |
| 29 | + /* With EitherValues, gets display of actual value and test line number up |
| 30 | + top: |
| 31 | +
|
| 32 | + The Either on which left.value was invoked was not defined as a Left; it was Right(1). |
| 33 | + ScalaTestFailureLocation: com.us.dsb.explore.libs.scalatest.ScratchTest at (ScratchTest.scala:22) |
| 34 | + org.scalatest.exceptions.TestFailedException: ... |
| 35 | +
|
| 36 | + */ |
| 37 | + //assert("123" == right.left.value) |
| 38 | + } |
| 39 | + |
| 40 | + ignore("OptionValues") { |
| 41 | + } |
| 42 | + ignore("PartialFunctionValues") { |
| 43 | + } |
| 44 | + ignore("Inside? matchPattern?") { |
| 45 | + } |
| 46 | + ignore("loneElement") { |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments