PageRenderTime 33ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/scalate/scalate
Scala | 63 lines | 35 code | 10 blank | 18 comment | 0 complexity | 778c88c07b6afe6dd3b11dfae18b8ff7 MD5 | raw file
  1. /**
  2. * Copyright (C) 2009-2011 the original author or authors.
  3. * See the notice.md file distributed with this work for additional
  4. * information regarding copyright ownership.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.fusesource.scalate.scuery
  19. import _root_.org.fusesource.scalate.FunSuiteSupport
  20. import xml.Node
  21. class SetAttributeTest extends FunSuiteSupport {
  22. val xml = <html>
  23. <body>
  24. <div id="content">
  25. <a href="#" class="foo" title="A foo link">foo link</a>
  26. <a href="#" class="bar" title="A bar link">bar link</a>
  27. <a href="#" class="jog" title="A jog link">jog link</a>
  28. </div>
  29. </body>
  30. </html>
  31. test(" transform") {
  32. object transformer extends Transformer {
  33. // 3 different approaches to changing attributes
  34. $("a.foo").attribute("href", "http://scalate.fusesource.org/")
  35. $("a.bar").attribute("href").value = "http://scalate.fusesource.org/documentation/"
  36. $("a.jog").attribute("href") {
  37. e =>
  38. "http://scalate.fusesource.org/documentation/" + (e \ "@class") + ".html"
  39. }
  40. }
  41. val result = transformer(xml)
  42. debug("got result: " + result)
  43. assertLink((result \\ "a")(0), "http://scalate.fusesource.org/", "foo", "A foo link")
  44. assertLink((result \\ "a")(1), "http://scalate.fusesource.org/documentation/", "bar", "A bar link")
  45. assertLink((result \\ "a")(2), "http://scalate.fusesource.org/documentation/jog.html", "jog", "A jog link")
  46. }
  47. def assertLink(a: Node, href: String, className: String, title: String): Unit = {
  48. debug("testing link node: " + a)
  49. assertResult(href) { (a \ "@href").toString }
  50. assertResult(className) { (a \ "@class").toString }
  51. assertResult(title) { (a \ "@title").toString }
  52. }
  53. }