diff --git a/src/main/scala/ch/usi/si/msde/edsl/lecture10/GenerativeFluentAssertionsDSL.scala b/src/main/scala/ch/usi/si/msde/edsl/lecture10/GenerativeFluentAssertionsDSL.scala index 2c252d3..165d4d9 100644 --- a/src/main/scala/ch/usi/si/msde/edsl/lecture10/GenerativeFluentAssertionsDSL.scala +++ b/src/main/scala/ch/usi/si/msde/edsl/lecture10/GenerativeFluentAssertionsDSL.scala @@ -72,7 +72,7 @@ object GenerativeFluentAssertionsDSL: // and the type of the property (actually... not exactly that. Why?) case '{ (${ typeProvider }: HavePropertyTypeProvider[subjectType]) - .applyDynamic($propertyNameExpr)($valueExpr: valueType) + .applyDynamic($propertyNameExpr)($valueExpr: valueType => Boolean) .$asInstanceOf$[AssertionProperty] } => val subjectExpr = '{ $typeProvider.subject } @@ -141,7 +141,7 @@ object GenerativeFluentAssertionsDSL: private def generateShouldHaveAssertion[T, R]( subjectExpr: Expr[T], propertyNameExpr: Expr[String], - propertyValueExpr: Expr[R] + propertyValueExpr: Expr[R => Boolean] )(using Type[T], Type[R])(using Quotes): Expr[Unit] = import quotes.reflect.* @@ -174,12 +174,11 @@ object GenerativeFluentAssertionsDSL: */ val assertion = '{ val subject = $subjectExpr - val expectedValue = $propertyValueExpr - lazy val result = ${ Select(('subject).asTerm, candidateMethod).asExpr } + val tester = $propertyValueExpr + lazy val value = ${ Select(('subject).asTerm, candidateMethod).asExprOf[R] } assert( - result == expectedValue, - s"${subject} did not have ${$propertyNameExpr} equal" + - s" to ${expectedValue}, but it was equal to ${result}" + tester.apply(value), + s"assertion failed for ${subject}.${$propertyNameExpr}" ) } report.info(assertion.show, subjectExpr.asTerm.pos) diff --git a/src/main/scala/ch/usi/si/msde/edsl/lecture10/Main.scala b/src/main/scala/ch/usi/si/msde/edsl/lecture10/Main.scala index d429dac..a926744 100644 --- a/src/main/scala/ch/usi/si/msde/edsl/lecture10/Main.scala +++ b/src/main/scala/ch/usi/si/msde/edsl/lecture10/Main.scala @@ -40,7 +40,7 @@ case class Box(label: String, weight: Mass, price: Money) // assert(List(1,2,3).nonEmpty) List(1, 2, 3) should be.nonEmpty - (person should have) age ((x: Int) => x == 10) + person should have age satisfying >= 10 // New syntax for `be` with type provider // either adult is a method with a dummy Unit parameter