PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/scalate-core/src/test/scala/org/fusesource/scalate/scuery/WilleScueryTest.scala

http://github.com/scalate/scalate
Scala | 58 lines | 48 code | 10 blank | 0 comment | 2 complexity | a3abf0c2285d5db79939ce93efd998ac MD5 | raw file
 1package org.fusesource.scalate
 2package scuery
 3
 4class WilleScueryTest extends FunSuiteSupport {
 5
 6  var verbose = false
 7
 8  test("hello") {
 9    val people = List(Person("James", "Mells"), Person("Hiram", "Tampa"))
10
11    object transformer extends Transformer {
12      $(".person") { node =>
13        people.flatMap {
14          p =>
15            new Transform(node) {
16              $(".name").contents = p.name
17              $(".location").contents = p.location
18            }
19        }
20      }
21    }
22
23    val result = transformer(xml)
24    show("got result: " + result)
25
26    val names = result.$(".name")
27    show("CSS filter got: " + names + " of size: " + names.size)
28
29    assertResult("James") {
30      names(0).text
31    }
32    assertResult("Hiram") {
33      names(1).text
34    }
35  }
36
37  def show(m: => String): Unit = {
38    if (verbose) {
39      info(m)
40    } else {
41      debug(m)
42    }
43  }
44
45  def xml = <div id="content">
46              <table class="people">
47                <tr>
48                  <th>Name</th>
49                  <th>Location</th>
50                </tr>
51                <tr class="person">
52                  <td class="name">DummyName</td>
53                  <td class="location">DummyLocation</td>
54                </tr>
55              </table>
56            </div>
57}
58