Created
September 30, 2019 16:37
-
-
Save chrilves/6025ed435ba09e3a4801dae6982c94b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ivy.`io.github.jto:validation-xml_2.12:2.1.1` | |
import jto.validation._ | |
import jto.validation.xml._ | |
import jto.validation.xml.Rules._ | |
import scala.xml._ | |
import scala.reflect.runtime.universe._ | |
final case class Test(x: Int, y: Int) | |
implicit val testR: Rule[Node, Test] = | |
From[Node] { __ => | |
((__ \ "x").read[Int] ~ | |
(__ \ "y").read[Int])(Test.apply) | |
} | |
val xml1 = | |
<Truc> | |
<Test> | |
<x>1</x> | |
<y>2</y> | |
</Test> | |
<Test> | |
<x>3</x> | |
<y>4</y> | |
</Test> | |
<Test> | |
<x>5</x> | |
<y>6</y> | |
</Test> | |
</Truc> | |
val xml2 = | |
<Machin> | |
<Tasp> | |
<x>1</x> | |
<y>2</y> | |
</Tasp> | |
<Tiks> | |
<x>3</x> | |
<y>4</y> | |
</Tiks> | |
<Tops> | |
<x>5</x> | |
<y>6</y> | |
</Tops> | |
</Machin> | |
val xml3 = <Machin></Machin> | |
val fullR: Rule[Node, Seq[Test]] = | |
From[Node] { __ => | |
__.read[Seq[Test]]{ p => Rules.pickInNode(p)(Rules.pickSeq(testR)) } | |
} | |
fullR.validate(xml1) | |
fullR.validate(xml2) | |
fullR.validate(xml3) | |
/* | |
showCode((reify { From[Node] { __ => | |
__.read[Option[Seq[Test]]] | |
} }).tree) | |
*/ | |
// OPT: { p => ooo(p)({ p => pickInNode(p)(RuleLike.zero) }, pickSeq(cmd15.testR))) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment