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