Skip to content

Commit 04af7c9

Browse files
author
Daniel Barclay
committed
scalatest: Added EitherValues demo.
1 parent 2e8a646 commit 04af7c9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)