summaryrefslogtreecommitdiff
path: root/contrib/twirllib/test
diff options
context:
space:
mode:
authorIurii Malchenko <yurique@pm.me>2018-11-02 09:30:52 +0200
committerTobias Roeser <le.petit.fou@web.de>2018-11-02 08:30:52 +0100
commitff45d24103684342a47ec2ed42565356a116f18d (patch)
tree0d882ce0f5aa7ca362690e032b29b34127404333 /contrib/twirllib/test
parent8afe79afe33be68f59f89b8410984e508c3e8d08 (diff)
downloadmill-ff45d24103684342a47ec2ed42565356a116f18d.tar.gz
mill-ff45d24103684342a47ec2ed42565356a116f18d.tar.bz2
mill-ff45d24103684342a47ec2ed42565356a116f18d.zip
improving twirl (#473)
* improving twirl support: default imports, better `compileTwirl().classes` value * twirl module doc edits
Diffstat (limited to 'contrib/twirllib/test')
-rw-r--r--contrib/twirllib/test/resources/hello-world/core/views/wrapper.scala.html5
-rw-r--r--contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala52
2 files changed, 45 insertions, 12 deletions
diff --git a/contrib/twirllib/test/resources/hello-world/core/views/wrapper.scala.html b/contrib/twirllib/test/resources/hello-world/core/views/wrapper.scala.html
new file mode 100644
index 00000000..af1f5d8e
--- /dev/null
+++ b/contrib/twirllib/test/resources/hello-world/core/views/wrapper.scala.html
@@ -0,0 +1,5 @@
+@(content: Html)
+
+@defining("test") { className =>
+ <div class="@className">@content</div>
+} \ No newline at end of file
diff --git a/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala b/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala
index 8ef6ee3e..804fd5a1 100644
--- a/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala
+++ b/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala
@@ -5,14 +5,18 @@ import mill.util.{TestEvaluator, TestUtil}
import utest.framework.TestPath
import utest.{TestSuite, Tests, assert, _}
+import scala.io.Codec
+
object HelloWorldTests extends TestSuite {
trait HelloBase extends TestUtil.BaseModule {
- override def millSourcePath: Path = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.')
+ override def millSourcePath: Path =
+ TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.')
}
trait HelloWorldModule extends mill.twirllib.TwirlModule {
def twirlVersion = "1.0.0"
+ override def twirlAdditionalImports: Seq[String] = additionalImports
}
object HelloWorld extends HelloBase {
@@ -22,11 +26,13 @@ object HelloWorldTests extends TestSuite {
}
}
- val resourcePath: Path = pwd / 'contrib / 'twirllib / 'test / 'resources / "hello-world"
+ val resourcePath
+ : Path = pwd / 'contrib / 'twirllib / 'test / 'resources / "hello-world"
- def workspaceTest[T](m: TestUtil.BaseModule, resourcePath: Path = resourcePath)
- (t: TestEvaluator => T)
- (implicit tp: TestPath): T = {
+ def workspaceTest[T](
+ m: TestUtil.BaseModule,
+ resourcePath: Path = resourcePath
+ )(t: TestEvaluator => T)(implicit tp: TestPath): T = {
val eval = new TestEvaluator(m)
rm(m.millSourcePath)
rm(eval.outPath)
@@ -36,14 +42,30 @@ object HelloWorldTests extends TestSuite {
}
def compileClassfiles: Seq[RelPath] = Seq[RelPath](
- "hello.template.scala"
+ "hello.template.scala",
+ "wrapper.template.scala"
+ )
+
+ def expectedDefaultImports: Seq[String] = Seq(
+ "import _root_.play.twirl.api.TwirlFeatureImports._",
+ "import _root_.play.twirl.api.TwirlHelperImports._",
+ "import _root_.play.twirl.api.Html",
+ "import _root_.play.twirl.api.JavaScript",
+ "import _root_.play.twirl.api.Txt",
+ "import _root_.play.twirl.api.Xml"
+ )
+
+ def additionalImports: Seq[String] = Seq(
+ "mill.twirl.test.AdditionalImport1._",
+ "mill.twirl.test.AdditionalImport2._"
)
def tests: Tests = Tests {
'twirlVersion - {
'fromBuild - workspaceTest(HelloWorld) { eval =>
- val Right((result, evalCount)) = eval.apply(HelloWorld.core.twirlVersion)
+ val Right((result, evalCount)) =
+ eval.apply(HelloWorld.core.twirlVersion)
assert(
result == "1.3.15",
@@ -54,20 +76,26 @@ object HelloWorldTests extends TestSuite {
'compileTwirl - workspaceTest(HelloWorld) { eval =>
val Right((result, evalCount)) = eval.apply(HelloWorld.core.compileTwirl)
- val outputFiles = ls.rec(result.classes.path)
+ val outputFiles = ls.rec(result.classes.path).filter(_.name.endsWith(".scala"))
val expectedClassfiles = compileClassfiles.map(
eval.outPath / 'core / 'compileTwirl / 'dest / 'html / _
)
+
assert(
- result.classes.path == eval.outPath / 'core / 'compileTwirl / 'dest / 'html,
+ result.classes.path == eval.outPath / 'core / 'compileTwirl / 'dest,
outputFiles.nonEmpty,
outputFiles.forall(expectedClassfiles.contains),
- outputFiles.size == 1,
- evalCount > 0
+ outputFiles.size == 2,
+ evalCount > 0,
+ outputFiles.forall { p =>
+ val lines = p.getLines(Codec.UTF8).map(_.trim)
+ (expectedDefaultImports ++ additionalImports.map(s => s"import $s")).forall(lines.contains)
+ }
)
// don't recompile if nothing changed
- val Right((_, unchangedEvalCount)) = eval.apply(HelloWorld.core.compileTwirl)
+ val Right((_, unchangedEvalCount)) =
+ eval.apply(HelloWorld.core.compileTwirl)
assert(unchangedEvalCount == 0)
}