Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed from implementation #266

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(" ")
}
}
}