PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/scalate-core/src/test/scala/org/fusesource/scalate/scuery/support/CssParserTest.scala

http://github.com/scalate/scalate
Scala | 147 lines | 85 code | 29 blank | 33 comment | 0 complexity | 09a411629e41b3168173396dbe60652c 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.support
  19. //import org.fusesource.scalate.scuery.Selector
  20. class CssParserTest extends CssParserTestSupport {
  21. val cheese = <c:tr xmlns:c="http://apache.org/cheese"><blah/></c:tr>
  22. val a = <a href="http://scalate.fusesource.org/" title="Scalate" hreflang="en-US">Awesomeness</a>
  23. val xml = <table id="t1" class="people" summary="My Summary Notes">
  24. <tr id="tr1" class="personRow odd">
  25. <td class="person">Hey</td>
  26. </tr>
  27. { cheese }
  28. { a }
  29. </table>
  30. val tr1 = (xml \\ "tr")(0)
  31. val td1 = (xml \\ "td")(0)
  32. // simple stuff
  33. assertMatches("table", xml)
  34. assertMatches("table#t1", xml)
  35. assertMatches("#t1", xml)
  36. assertMatches(".people", xml)
  37. assertMatches("table.people", xml)
  38. assertMatches("*", td1)
  39. assertMatches("*.person", td1)
  40. assertMatches("*#tr1", tr1)
  41. assertMatches("#tr1", tr1)
  42. assertMatches(".personRow", tr1)
  43. assertMatches(".odd", tr1)
  44. // combinators
  45. assertMatches("tr > td", td1)
  46. assertMatches("tr td", td1)
  47. assertMatches("table td", td1)
  48. assertMatches("table tr td", td1)
  49. assertMatches("table tr .person", td1)
  50. assertMatches("table > tr > td", td1)
  51. assertMatches("table .person", td1)
  52. assertMatches("td.person", td1)
  53. assertMatches("tr .person", td1)
  54. assertMatches("tr > .person", td1)
  55. assertNotMatches("foo", td1)
  56. assertNotMatches(".foo", td1)
  57. assertNotMatches("#foo", td1)
  58. assertNotMatches("tr table td", td1)
  59. assertNotMatches("table tr tr td", td1)
  60. assertNotMatches("table table tr td", td1)
  61. assertNotMatches("table > td", td1)
  62. assertNotMatches("tr > table > td", td1)
  63. assertNotMatches("td > tr", td1)
  64. // namespaces
  65. assertMatches("*|*", cheese)
  66. assertMatches("*|*", tr1)
  67. assertMatches("*|tr", cheese)
  68. assertMatches("*|tr", tr1)
  69. assertNotMatches("|tr", cheese)
  70. assertMatches("|tr", tr1)
  71. assertMatches("c|tr", cheese)
  72. assertNotMatches("c|tr", tr1)
  73. // attributes
  74. assertMatches("table[summary]", xml)
  75. assertMatches("[summary]", xml)
  76. assertNotMatches("[summary]", tr1)
  77. assertMatches("[summary = \"My Summary Notes\"]", xml)
  78. assertNotMatches("[summary = \"NotMatch\"]", xml)
  79. assertMatches("[summary=\"My Summary Notes\"]", xml)
  80. // ~= matches whole words
  81. assertMatches("[summary ~= \"My\"]", xml)
  82. assertMatches("[summary ~= \"Summary\"]", xml)
  83. assertMatches("[summary ~= \"Notes\"]", xml)
  84. assertNotMatches("[summary ~= \"My Summary\"]", xml) // can only filter on whole words
  85. assertMatches("[summary~=\"My\"]", xml)
  86. // |=
  87. assertMatches("[hreflang |= \"en\"]", a)
  88. assertMatches("[hreflang |= \"en-US\"]", a)
  89. assertNotMatches("[hreflang |= \"de\"]", a)
  90. // TODO regex bug!!!
  91. // not sure yet why the parser fails to parse this!
  92. //assertMatches("[hreflang|=\"en\"]", a)
  93. //assertMatches("[hreflang|=en]", a)
  94. assertMatches("[hreflang |= en]", a)
  95. assertMatches("[hreflang |= en-US]", a)
  96. // ^=
  97. assertMatches("[summary ^= \"My\"]", xml)
  98. assertMatches("[summary ^= \"My S\"]", xml)
  99. assertNotMatches("[summary ^= \"T\"]", xml)
  100. assertMatches("[summary^=\"My\"]", xml)
  101. // $=
  102. assertMatches("[summary $= \"Notes\"]", xml)
  103. assertMatches("[summary $= \"Summary Notes\"]", xml)
  104. assertNotMatches("[summary $= \"Cheese\"]", xml)
  105. assertMatches("[summary$=\"Notes\"]", xml)
  106. // *=
  107. assertMatches("[summary *= \"Sum\"]", xml)
  108. assertMatches("[summary *= \"Summary N\"]", xml)
  109. assertNotMatches("[summary *= \"Cheese\"]", xml)
  110. assertMatches("[summary*=\"Sum\"]", xml)
  111. // :not
  112. assertMatches("td:not(.food)", td1)
  113. assertNotMatches("td:not(.person)", td1)
  114. // filtering using the pimped API on scala Node*
  115. assertFilter(".person", td1)
  116. assertFilter("table td", td1)
  117. assertFilter("table tr td", td1)
  118. }