Snippets Collections
def mkPropEqMatcher[T,V](name:String, extr: T => V)(expVal : V): HavePropertyMatcher[T,V] =
     new HavePropertyMatcher[T, V] {
       def apply(t: T): HavePropertyMatchResult[V] =
         HavePropertyMatchResult(
           extr(t) == expVal,
           name,
           expVal,
           extr(t)
         )
     }
 
   val title = mkPropEqMatcher("title", (_ : Book).title) _
   val author = mkPropEqMatcher("author", (_ : Book).author) _  
star

Wed Dec 08 2021 17:23:04 GMT+0000 (Coordinated Universal Time) https://users.scala-lang.org/t/type-safe-checking-of-arbitary-properties-custom-class-for-without-boilerplate-code/6751/3

#scala #scala-test

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension