Skip to content

Commit

Permalink
Merge pull request #266 from theiterators/fix/implementation_from_method
Browse files Browse the repository at this point in the history
Fixed from implementation
  • Loading branch information
piotrkuczko committed Feb 1, 2023
2 parents 9b0fc04 + 35d1251 commit cc6385d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ final class macroImpl(val c: whitebox.Context) {
else List.empty
val body =
if (hasValidations)
q"validate($argName).map(_ => $argName.taggedWith[${tagType.tagName}[..$tagParams]])"
q"validate($argName).map(_.taggedWith[${tagType.tagName}[..$tagParams]])"
else
q"$argName.taggedWith[${tagType.tagName}[..$tagParams]]"

Expand Down
31 changes: 31 additions & 0 deletions tagged-meta/src/test/scala/TaggedAnnotationFromMethodTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.scalatest._
import pl.iterators.kebs.tagged._
import pl.iterators.kebs.tag.meta.tagged
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

@tagged object DomainTrimmedString {
trait NameTag
type Name = String @@ NameTag

object Name {
sealed trait Error
case object Empty extends Error

def validate(name: String) = if (name.trim.isEmpty) Left(Empty) else Right(name.trim)
}
}

class TaggedAnnotationFromMethodTest extends AnyFunSuite with Matchers with EitherValues {
import DomainTrimmedString._

test("from method must use result from validation") {
Name(" name ") shouldEqual "name"
}

test("from method must forward Error value") {
intercept[Exception] {
Name(" ")
}
}
}

0 comments on commit cc6385d

Please sign in to comment.