Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 885 lines (670 sloc) 30.036 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
/*
* Copyright 2007-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.liftweb
package util

import xml._

import org.specs.Specification

import common._
import BindHelpers._


/**
* Systems under specification for BindHelpers.
*/
object BindHelpersSpec extends Specification("BindHelpers Specification") {

  "the mixinAttributes function" should {
    "mixin in all the attributes" in {
      mixinAttributes(<input />)(<input id="10" class="wee" />) must ==/(<input class="wee" id="10"></input>)
    }

    "not mix in the element label" in {
      mixinAttributes(<input />)(<div id="10" class="wee" />) must ==/(<input class="wee" id="10"></input>)
    }

    "handle the empty cases gracefully" in {
      mixinAttributes(<input />)(<div />) must ==/(<input></input>)
    }

    "not lose existing attributes" in {
      mixinAttributes(<input id="10" />)(<div />) must ==/(<input id="10"></input>)
    }

    "replace attributes with updated values" in {
      mixinAttributes(<input id="10" />)(<div id="12" />) must ==/(<input id="12"></input>)
    }
  }

  "the chooseTemplate function" should {
    "select the node matching a given tag and prefix" in {
      chooseTemplate("choose", "tag", <h><choose:tag a="att1">that</choose:tag></h>) must ==/(Text("that"))
    }
    "select the first node matching a given tag and prefix" in {
      chooseTemplate("choose", "tag", <h><choose:tag>that</choose:tag><choose:tag>those</choose:tag></h>) must ==/(Text("that"))
    }
    "return an empty NodeSeq if no node is found" in {
      chooseTemplate("choose", "tag", <h></h>) must be_==(NodeSeq.Empty)
    }
  }
  "the bind(Map, NodeSeq) function" should {
    "replace the content of a lift:bind node with the content of a map where the key is the value of the attribute 'name'" in {
      val map = Map("hello" -> <h1></h1>, "world" -> <b></b>)
      val liftbind = <body>
        <lift:bind name="hello">changethis</lift:bind>
                     </body>

      bind(map, liftbind) must ==/(<body><h1></h1></body>)
    }

    "bind should not peserve attrs on a bound element" in {

      val res:NodeSeq = bind("ledger", <ledger:entry ledger:id="foo" ledger:class="bar" />, "entry" -> <foo/>)

      res must ==/(<foo/>)
    }
  }
  "the bindlist function" should {
    "replace the content of a lift:bind node with the content of a map where the key is the value of the attribute 'name'" in {
      val maps = List(Map("hello" -> <h1></h1>, "world" -> <b></b>))
      val liftbind = <body>
        <lift:bind name="hello">changethis</lift:bind>
                     </body>
      bindlist(maps, liftbind).get must ==/(<body><h1></h1></body>)
    }
  }
  "the bind(namespace, NodeSeq, BindParams*) function" should {
    "replace a node named 'namespace:bindparam name' in a NodeSeq with the String value of the BindParam" in {
      bind("user", <t><user:tag>replacethis</user:tag></t>, "tag" -> "world") must ==/(<t>world</t>)
    }
    "replace a node named 'namespace:bindparam name' in a NodeSeq with the Symbol value of the BindParam" in {
      bind("user", <t><user:tag>replacethis</user:tag></t>, "tag" -> 'world) must ==/(<t>world</t>)
    }


    "replace a node named 'namespace:bindparam name' in a NodeSeq with the Symbol value of the BindParam via lift:bind attribute" in {
      bind("user", <t><div lift:bind="user:tag">replacethis</div></t>, "tag" -> 'world) must ==/(<t>world</t>)
    }

    "replace a node named 'namespace:bindparam name' in a NodeSeq with the NodeSeq value of the BindParam" in {
      bind("user", <user:tag>replacethis</user:tag>, "tag" -> <world></world>) must ==/(<world></world>)
    }
    "replace a node named 'namespace:bindparam name' in a NodeSeq with the NodeSeq value of the BindParam" in {
      bind("user", <user:tag>replacethis</user:tag>, "tag" -> <world></world>) must ==/(<world></world>)
    }
    "replace a node named 'namespace:bindparam name' in a NodeSeq with the function application of a FuncBindParam" in {
      bind("user", <t><user:tag>hello</user:tag></t>, FuncBindParam("tag", (n: NodeSeq) => Text(n.text + " world"))) must ==/(<t>hello world</t>)
    }
    "properly convert a NodeSeq => NodeSeq to a FuncBindParam" in {
      bind("user", <t><user:tag>hello</user:tag></t>, "tag" -> ((n: NodeSeq) => Text(n.text + " world"))) must ==/(<t>hello world</t>)
    }
    "replace an attribute value named 'namespace:bindparam name' in a NodeSeq with a value from a BindParam" in {
      bind("user", <t user:hello="toreplace"></t>, "hello" -> Text("world")) must ==/(<t user:hello="world"></t>)
    }
    "replace an attribute value named 'namespace:bindparam name' in a NodeSeq with a calculated value from a FuncBindParam" in {
      bind("user", <t user:tag="hello"></t>, FuncBindParam("tag", (n: NodeSeq) => Text(n.text + " world"))) must ==/(<t user:tag="hello world"></t>)
    }
    "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and value from an AttrBindParam" in {
      bind("user", <t user:tag="toreplace"></t>, AttrBindParam("tag", Text("world"), "hello")) must ==/(<t hello="world"></t>)
    }

    "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and value from an AttrBindParam using a String" in {
      bind("user", <t user:tag="toreplace"></t>, AttrBindParam("tag", "world", "hello")) must ==/(<t hello="world"></t>)
    }

    "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and calculated value from an FuncAttrBindParam" in {
      bind("user", <t user:tag="dear"></t>, FuncAttrBindParam("tag", (n: NodeSeq) =>Text(n.text + " world"), "hello")) must ==/(<t hello="dear world"></t>)
    }

    "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a blank attribute name and calculated value from an FuncAttrOptionBindParam" in {
      bind("user", <t user:tag="dear"></t>, FuncAttrOptionBindParam("tag", (n: NodeSeq) => None, "hello")) must ==/(<t/>)
    }


    "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and calculated value from an FuncAttrOptionBindParam" in {
      bind("user", <t user:tag="dear"></t>, FuncAttrOptionBindParam("tag", (n: NodeSeq) => Some(Text(n.text + " world")), "hello")) must ==/(<t hello="dear world"></t>)
    }

    "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a blank attribute name and calculated value from an FuncAttrBoxBindParam" in {
      bind("user", <t user:tag="dear"></t>, FuncAttrBoxBindParam("tag", (n: NodeSeq) => Empty, "hello")) must ==/(<t/>)
    }


    "replace an attribute named 'namespace:bindparam name' in a NodeSeq with a new attribute name and calculated value from an FuncAttrOptionBindParam" in {
      bind("user", <t user:tag="dear"></t>, FuncAttrBoxBindParam("tag", (n: NodeSeq) => Full(Text(n.text + " world")), "hello")) must ==/(<t hello="dear world"></t>)
    }
  }

  "findOption" should {
    "find an id" in {
      val xml = <foo><bar/>Dog<b><woof id="3"/></b></foo>

      findOption(xml) {
        e => e.attribute("id").
        filter(_.text == "3").map(i => e)
      }.get must ==/ (<woof id="3"/>)
    }

    "not find an ide" in {
      val xml = <foo><bar/>Dog<b><woof ide="3"/></b></foo>

      findOption(xml) {
        e => e.attribute("id").
        filter(_.text == "3").map(i => e)
      } must_== None
    }


    "not find a the wrong id" in {
      val xml = <foo><bar/>Dog<b><woof ide="4"/></b></foo>

      findOption(xml) {
        e => e.attribute("id").
        filter(_.text == "3").map(i => e)
      } must_== None
    }
  }

  "findBox" should {
    "find an id" in {
      val xml = <foo><bar/>Dog<b><woof id="3"/></b></foo>

      findBox(xml) {
        e => e.attribute("id").
        filter(_.text == "3").
        map(i => e)
      }.open_! must ==/ (<woof id="3"/>)
    }

    "not find an ide" in {
      val xml = <foo><bar/>Dog<b><woof ide="3"/></b></foo>

      findBox(xml) {
        e => e.attribute("id").
        filter(_.text == "3").map(i => e)
      } must_== Empty
    }


    "not find a the wrong id" in {
      val xml = <foo><bar/>Dog<b><woof ide="4"/></b></foo>

      findBox(xml) {
        e => e.attribute("id").
        filter(_.text == "3").map(i => e)
      } must_== Empty
    }
  }

  "replaceIdNode" should {
    "replace a node" in {
      Helpers.replaceIdNode(<foo><bar id="dog"/></foo>,
                            "dog",
                            <baz/>) must ==/ (<foo><baz/></foo>)
    }

    "Ignore if no id match" in {
      Helpers.replaceIdNode(<foo><bar/></foo>,
                            "dog",
                            <baz/>) must ==/ (<foo><bar/></foo>)
    }
  }

  "the xmlParam function" should {
    "find the value of an attribute in an xml fragment" in {
      xmlParam(<t hello="world">world</t>, "hello") must_== Full("world")
    }
    "return Empty if the value is empty" in {
      xmlParam(<t hello="">world</t>, "hello") must_== Empty
    }
    "return Empty if the attribute is not found" in {
      xmlParam(<t hello="">world</t>, "notfound") must_== Empty
    }
  }

  "Add CSS Class" should {
    "add a new attribute" in {
      (addCssClass("foo", <b/>) \ "@class").text must_== "foo"
    }

    "append an existing attribute" in {
      (addCssClass("foo", <b class="dog"/>) \ "@class").text must_== "dog foo"
    }

  }

  "The bind helpers should deal correctly with <select>" should {
    "do <select> correctly" in {
      val xhtml = <select name="days"> <stats:options/> </select>

      def options(xhtml: NodeSeq): NodeSeq = {
        <option value="7">week</option><option value="30">month</option> }

      val res = bind("stats", xhtml, "options" -> options _)

      res must ==/(<select name="days"><option value="7">week</option><option value="30">month</option></select>)
    }

    "do <input> correctly" in {
      val xhtml = <input name="days"> <stats:options/> </input>

      def options(xhtml: NodeSeq): NodeSeq = {
        <option value="7">week</option><option value="30">month</option> }

      val res = bind("stats", xhtml, "options" -> options _)

      res must ==/(<input name="days"><option value="7">week</option><option value="30">month</option></input>)
    }

    "do <div> correctly" in {
      val xhtml = <div> <stats:options/> </div>

      def options(xhtml: NodeSeq): NodeSeq = {
        <option value="7">week</option><option value="30">month</option> }

      val res = bind("stats", xhtml, "options" -> options _)
      res must ==/(<div><option value="7">week</option><option value="30">month</option></div>)
    }
  }


  "the bindByName bind(namespace, NodeSeq, BindParams*) function" should {
    "mix in if the element if the type of the elements are the same" in {
      bind("user", <t><input name="user:tag" id="cookie"/></t>, "tag" -> <input name="111222"/>) must ==/(<t><input name="111222" id="cookie"/></t>)
    }
    "replace the element if the replacement element type is not a bindByName type" in {
      bind("user", <t><input name="user:tag" id="cookie"/></t>, "tag" -> "world") must ==/(<t>world</t>)
    }
    "replace the value is value is a null string" in {
      bind("user", <t><input name="user:tag" type="submit" value="press me"/></t>, "tag" -> <input name="111222" type="submit"/>) must ==/(<t><input name="111222" type="submit" value="press me"></input></t>)
    }
    "handle a checkbox" in {
      bind("user", <t><input id="acceptTerms" type="checkbox" name="user:tag"/></t>,
           "tag" -> (<input /> ++
                     <input type="checkbox" name="F893599644556MN4" value="true"/>) ) must ==/(<t><input></input><input name="F893599644556MN4" type="checkbox" value="true" id="acceptTerms"></input></t>)
    }
  }

  "head removal" should {
    "remove <head>" in {
      Helpers.stripHead(<head><i>hello</i></head>) must ==/(<i>hello</i>)
    }

    "ignore non-head" in {
      Helpers.stripHead(<head3><i>hello</i></head3>) must ==/(<head3><i>hello</i></head3>)
    }

    "String subhead" in {
      Helpers.stripHead(<head3><i><head>hello</head></i></head3>) must ==/(<head3><i>hello</i></head3>)
    }
  }

  "Binding attributes" should {
    "handle static, unprefixed attributes" in {
      BindHelpers.bind("test",
                       <div><div test:x="replace" /></div>,
                       AttrBindParam("x", "staticUnprefixed", "id")) must ==/(<div><div id="staticUnprefixed" /></div>)
    }

    "handle dynamic, unprefixed attributes" in {
      // The Unprefixed attributes that Lift merges in cause the XML equals comparison to fail
      // stringifying and then reparsing fixes it.
      XML.loadString(
        BindHelpers.bind("test",
                         <div><div test:x="dynamicUnprefixed" /></div>,
                         FuncAttrBindParam("x", {ns : NodeSeq => ns }, "id")).toString) must ==/(<div><div id="dynamicUnprefixed" /></div>)
    }

    "handle static, prefixed attributes" in {
      BindHelpers.bind("test",
                       <div><div test:x="replace" /></div>,
                       AttrBindParam("x", "staticPrefixed", ("result","id"))) must ==/(<div><div result:id="staticPrefixed" /></div>)
    }

    "handle dynamic, prefixed attributes" in {
      BindHelpers.bind("test",
                       <div><div test:x="dynamicPrefixed" /></div>,
                       FuncAttrBindParam("x", {ns : NodeSeq => ns}, ("result","id"))) must ==/(<div><div result:id="dynamicPrefixed" /></div>)
    }
  }
}


object CssBindHelpersSpec extends Specification {

  "css bind helpers" should {
    "clear clearable" in {
      ClearClearable(<b><span class="clearable"/></b>) must ==/ (<b/>)
    }

    "substitute a String by id" in {
      ("#foo" #> "hello")(<b><span id="foo"/></b>) must ==/ (<b>hello</b>)
    }


    "not duplicate classes" in {

      def anchor(quesType: String, value: String) = {
        <a href="foo" class="selected">(value)</a>
      }
      var page = 1
      var elements = List("1","2","3","4")
      
      val xml = <div class="lift:Bug.attack bug">
      <div id="question" class="question">
      <a href="#" class="L">1</a>
      <a href="#" class="U">1</a>
      <a href="#" class="D">1</a>
      </div>
      <div class="navigation">
      <button class="previous">Previous</button> <button class="next">Next</button>
      </div>
      </div>
      
      val sel = ".question" #> elements.map(value => {
        ".question [id]" #> ("question-" + value) &
        ".question [class]" #> ("question-" + value) &
        ".L" #> anchor("L", value) &
        ".U" #> anchor("U", value) &
        ".D" #> anchor("D", value)
      })
      
      val res = sel(xml)

      ((res \\ "a").head \ "@class").head.text must_== "selected L"
    }


    "Compound selector" in {
      val res =
      (".foo [href]" #> "http://dog.com" & ".bar [id]" #> "moo").apply(
        <a class="foo bar" href="#"/>)
      (res \ "@href").text must_== "http://dog.com"
      (res \ "@id").text must_== "moo"
    }

    "not stack overflow on Elem" in {
      val xf = "* [id]" #> "xx" &
      "* [style]" #> "border:thin solid black" &
      "* *" #> <a/>
    }

    "not stack overflow on Elem" in {
      val xf = "* [id]" #> "xx" &
      "* [style]" #> "border:thin solid black" &
      "* *+" #> <a/>

      xf(<div/>)
    }

    "not stack overflow on Elem" in {
      val xf = "* [id]" #> "xx" &
      "* [style]" #> "border:thin solid black" &
      "* -*" #> <a/>

      xf(<div/>)
    }

    "substitute a String by id" in {
      ("#foo" replaceWith "hello")(<b><span id="foo"/></b>) must ==/ (<b>hello</b>)
    }

    "Select a node" in {
      ("#foo ^^" #> "hello")(<div><span id="foo"/></div>) must ==/ (<span id="foo"/>)
    }


    "Select a node and transform stuff" in {
      val ret = ("#foo ^^" #> "hello" &
                 "span [id]" #> "bar")(<span id="foo"/>)

      ret(0).asInstanceOf[Elem].label must_== "span"
      ret.length must_== 1
      (ret \ "@id").text must_== "bar"
    }


    "Select a node and transform stuff deeply nested" in {
      val ret = ("#foo ^^" #> "hello" &
                 "span [id]" #> "bar")(<div><div><span id="foo"/></div></div>)

      ret(0).asInstanceOf[Elem].label must_== "span"
      ret.length must_== 1
      (ret \ "@id").text must_== "bar"
    }


    "Select a node and transform stuff deeply nested 2" in {
      val ret = ("#foo ^^" #> "hello" &
                 "span [id]" #> "bar")(<div><div><span id="foo2"/><span id="foo3"/><span dog="woof" id="foo"/></div></div>)

      ret(0).asInstanceOf[Elem].label must_== "span"
      ret.length must_== 1
      (ret \ "@id").text must_== "bar"
      (ret \ "@dog").text must_== "woof"
    }



    "substitute multiple Strings by id" in {
      ("#foo" #> "hello" &
     "#baz" #> "bye")(<b><div id="baz">Hello</div><span id="foo"/></b>) must ==/ (<b>{Text("bye")}{Text("hello")}</b>)
    }

    "bind href and None content" in {
      val opt: Option[String] = None
      val res = ("top *" #> opt &
                 "top [href]" #> "frog")(<top>cat</top>)

      res.length must_== 0
    }

    "bind href and Some content" in {
      val opt: Option[String] = Some("Dog")
      val res = ("top *" #> opt &
                 "top [href]" #> "frog")(<top>cat</top>)

      res.text must_== "Dog"
      (res \ "@href").text.mkString must_== "frog"
    }

    "bind href and Some content with multiple attrs" in {
      val opt: Option[String] = Some("Dog")
      val res = ("top *" #> opt &
                 "top [meow]" #> "woof" &
                 "top [href]" #> "frog")(<top href="#">cat</top>)

      res.text must_== "Dog"
      (res \ "@href").text.mkString must_== "frog"
      (res \ "@meow").text.mkString must_== "woof"
    }

    "option transform on *" in {
      val opt: Option[String] = None
      val res = ("* *" #> opt.map(ignore => "Dog"))(<top>cat</top>)
      res.length must_== 0
    }

    "append attribute to a class with spaces" in {
      val stuff = List("a", "b")
      val res = ("* [class+]" #> stuff)(<top class="q">cat</top>)
      (res \ "@class").text must_== "q a b"
    }

    "append attribute to an href" in {
      val stuff = List("&a=b", "&b=d")
      val res = ("* [href+]" #> stuff)(<top href="q?z=r">cat</top>)
      (res \ "@href").text must_== "q?z=r&a=b&b=d"
    }

    "option transform on *" in {
      val opt: Option[Int] = Full(44)
      val res = ("* *" #> opt.map(ignore => "Dog"))(<top>cat</top>)
      res must ==/ (<top>Dog</top>)
    }


    "option transform on *" in {
      val opt: Box[String] = Empty
      val res = ("* *" #> opt.map(ignore => "Dog"))(<top>cat</top>)
      res.length must_== 0
    }

    "option transform on *" in {
      val opt: Box[Int] = Some(44)
      val res = ("* *" #> opt.map(ignore => "Dog"))(<top>cat</top>)
      res must ==/ (<top>Dog</top>)
    }

    "transform on *" in {
      val res = ("* *" #> "Dog")(<top>cat</top>)
      res must ==/ (<top>Dog</top>)
    }

    "transform child content on *+" in {
      val res = ("* *+" #> "moose")(<a>I like </a>)
      res.text must_== "I like moose"
    }

    "transform child content on -*" in {
      val res = ("* -*" #> "moose")(<a> I like</a>)
      res.text must_== "moose I like"
    }

    "transform on li" in {
      val res = ("li *" #> List("Woof", "Bark") & ClearClearable)(
        <ul><li>meow</li><li class="clearable">a</li><li class="clearable">a</li></ul>)
      res must ==/ (<ul><li>Woof</li><li>Bark</li></ul>)
    }

    "substitute multiple Strings by id" in {
      (("#foo" replaceWith "hello") &
       ("#baz" replaceWith "bye"))(<b><div id="baz">Hello</div><span id="foo"/></b>) must ==/ (<b>{Text("bye")}{Text("hello")}</b>)
    }

    "substitute multiple Strings with a List by id" in {
      ("#foo" #> "hello" &
     "#baz" #> List("bye", "bye"))(<b><div id="baz">Hello</div><span id="foo"/></b>) must ==/ (<b>{Text("bye")}{Text("bye")}{Text("hello")}</b>)
    }

    "substitute multiple Strings with a List by id" in {
      (("#foo" replaceWith "hello") &
       ("#baz" replaceWith List("bye", "bye")))(<b><div id="baz">Hello</div><span id="foo"/></b>) must ==/ (<b>{Text("bye")}{Text("bye")}{Text("hello")}</b>)
    }


    "substitute multiple Strings with a List of XML by id" in {
      val answer = ("#foo" #> "hello" &
     "#baz" #> List[NodeSeq](<i/>, <i>Meow</i>))(<b><div frog="dog" id="baz">Hello</div><span id="foo"/></b>)
      
      (answer \ "i").length must_== 2
      (answer \ "i")(0) must ==/ (<i id="baz" frog="dog"/>)
      (answer \ "i")(1) must ==/ (<i frog="dog">Meow</i>)
    }

    "substitute multiple Strings with a List of XML by id" in {
      val answer = (("#foo" replaceWith "hello") &
                    ("#baz" replaceWith List[NodeSeq](<i/>, <i>Meow</i>)))(<b><div frog="dog" id="baz">Hello</div><span id="foo"/></b>)
      
      (answer \ "i").length must_== 2
      (answer \ "i")(0) must ==/ (<i id="baz" frog="dog"/>)
      (answer \ "i")(1) must ==/ (<i frog="dog">Meow</i>)
    }

    "substitute by name" in {
      val answer = ("name=moose" #> <input name="goof"/>).apply (
        <div><input name="moose" value="start" id="79"/></div>)

      (answer \ "input")(0) must ==/ (<input name="goof" value="start" id="79"/>)
    }
    
    "substitute by name" in {
      val answer = ("name=moose" replaceWith <input name="goof"/>).apply (
        <div><input name="moose" value="start" id="79"/></div>)

      (answer \ "input")(0) must ==/ (<input name="goof" value="start" id="79"/>)
    }
    

    "substitute by name with attrs" in {
      val answer = ("name=moose" #> <input name="goof" value="8" id="88"/>).apply (
        <div><input name="moose" value="start" id="79"/></div>)

      (answer \ "input")(0) must ==/ (<input name="goof" value="8" id="88"/>)
    }
    
    "substitute by name with attrs" in {
      val answer = ("name=moose" replaceWith <input name="goof" value="8" id="88"/>).apply (
        <div><input name="moose" value="start" id="79"/></div>)

      (answer \ "input")(0) must ==/ (<input name="goof" value="8" id="88"/>)
    }
    

    "substitute by a selector with attrs" in {
      val answer = ("cute=moose" #> <input name="goof" value="8" id="88"/>).apply (
        <div><input name="meow" cute="moose" value="start" id="79"/></div>)

      (answer \ "input")(0) must ==/ (<input cute="moose" name="goof" value="8" id="88"/>)
    }
    
    "substitute by a selector with attrs" in {
      val answer = ("cute=moose" replaceWith <input name="goof" value="8" id="88"/>).apply (
        <div><input name="meow" cute="moose" value="start" id="79"/></div>)

      (answer \ "input")(0) must ==/ (<input cute="moose" name="goof" value="8" id="88"/>)
    }

    "Map of funcs" in {
      val func: NodeSeq => NodeSeq = "#horse" #> List(1,2,3).map(".item *" #> _)
      val answer: NodeSeq = func(<span><div id="horse">frog<span class="item">i</span></div></span>)

      answer must ==/ (<span><div id="horse">frog<span class="item">1</span></div><div>frog<span class="item">2</span></div><div>frog<span class="item">3</span></div></span>)
                  
    }
    

    "merge classes" in {
      val answer = ("cute=moose" #> <input class="a" name="goof" value="8" id="88"/>).apply (
        <div><input name="meow" class="b" cute="moose" value="start" id="79"/></div>)

      (answer \ "input")(0) must ==/ (<input class="a b" cute="moose" name="goof" value="8" id="88"/>)
    }
    

    "merge classes" in {
      val answer = ("cute=moose" replaceWith <input class="a" name="goof" value="8" id="88"/>).apply (
        <div><input name="meow" class="b" cute="moose" value="start" id="79"/></div>)

      (answer \ "input")(0) must ==/ (<input class="a b" cute="moose" name="goof" value="8" id="88"/>)
    }
    



    "list of strings" in {
      val answer = ("#moose *" #> List("a", "b", "c", "woof") &
                    ClearClearable).apply (
        <ul>
        <li id="moose">first</li>
        <li class="clearable">second</li>
        <li class="clearable">Third</li>
        </ul>)
        
      val lis = (answer \ "li").toList
      
      lis.length must_== 4

      lis(0) must ==/ (<li id="moose">a</li>)
      lis(3) must ==/ (<li>woof</li>)
    }
    

    "list of Nodes" in {
      val answer = ("#moose *" #> List[NodeSeq](<i>"a"</i>, Text("b"), Text("c"), <b>woof</b>) &
                    ClearClearable).apply (
        <ul>
        <li id="moose">first</li>
        <li class="clearable">second</li>
        <li class="clearable">Third</li>
        </ul>)
        
      val lis = (answer \ "li").toList
      
      lis.length must_== 4

      lis(0) must ==/ (<li id="moose"><i>"a"</i></li>)
      lis(3) must ==/ (<li><b>woof</b></li>)
    }
    

    "set href" in {
      val answer = ("#moose [href]" #> "Hi" &
                    ClearClearable).apply (
        <ul><a id="moose" href="meow">first</a><li class="clearable">second</li><li class="clearable">Third</li></ul>)
        
    
    (answer \ "a" \ "@href").text must_== "Hi"
      (answer \ "li").length must_== 0
    }
    
    "set href and subnodes" in {
      val answer = ("#moose [href]" #> "Hi" &
                    ClearClearable).apply (
        <ul><a id="moose" href="meow">first<li class="clearable">second</li><li class="clearable">Third</li></a></ul>)
        
    
    (answer \ "a" \ "@href").text must_== "Hi"
      (answer \\ "li").length must_== 0
    }


    "list of strings" in {
      val answer = (("#moose *" replaceWith List("a", "b", "c", "woof")) &
                    ClearClearable).apply (
        <ul>
        <li id="moose">first</li>
        <li class="clearable">second</li>
        <li class="clearable">Third</li>
        </ul>)
        
      val lis = (answer \ "li").toList
      
      lis.length must_== 4

      lis(0) must ==/ (<li id="moose">a</li>)
      lis(3) must ==/ (<li>woof</li>)
    }
    

    "list of Nodes" in {
      val answer = (("#moose *" replaceWith List[NodeSeq](<i>"a"</i>, Text("b"), Text("c"), <b>woof</b>)) &
                    ClearClearable).apply (
        <ul>
        <li id="moose">first</li>
        <li class="clearable">second</li>
        <li class="clearable">Third</li>
        </ul>)
        
      val lis = (answer \ "li").toList
      
      lis.length must_== 4

      lis(0) must ==/ (<li id="moose"><i>"a"</i></li>)
      lis(3) must ==/ (<li><b>woof</b></li>)
    }
    

    "set href" in {
      val answer = (("#moose [href]" replaceWith "Hi") &
                    ClearClearable).apply (
        <ul><a id="moose" href="meow">first</a><li class="clearable">second</li><li class="clearable">Third</li></ul>)
        
    
    (answer \ "a" \ "@href").text must_== "Hi"
      (answer \ "li").length must_== 0
    }
    
    "set href and subnodes" in {
      val answer = (("#moose [href]" replaceWith "Hi") &
                    ClearClearable).apply (
        <ul><a id="moose" href="meow">first<li class="clearable">second</li><li class="clearable">Third</li></a></ul>)
        
    
    (answer \ "a" \ "@href").text must_== "Hi"
      (answer \\ "li").length must_== 0
    }
    

  }
}


/**
* This class doesn't actually perform any tests, but insures that
* the implicit conversions work correctly
*/
object CheckTheImplicitConversionsForToCssBindPromoter {
  val bog = new ToCssBindPromoter(Empty, Empty)

  import BindHelpers._

  "foo" #> "baz"

  bog #> "Hello"
  bog #> <span/>
  bog #> 1
  bog #> 'foo
  bog #> 44L
  bog #> false

  bog #> List(<span/>)
  bog #> Full(<span/>)
  bog #> Some(<span/>)


  bog #> List("Hello")
  bog #> Full("Dog")
  bog #> Some("Moo")


  bog #> List((null: Bindable))
  bog #> Full((null: Bindable))
  bog #> Some((null: Bindable))

  bog #> nsToNs _
  bog #> nsToOptNs _
  bog #> nsToBoxNs _
  bog #> nsToSeqNs _

  bog #> nsToString _
  bog #> nsToOptString _
  bog #> nsToBoxString _
  bog #> nsToSeqString _

  val nsf: NodeSeq => NodeSeq = bog #> "Hello" &
  bog #> <span/> &
  bog #> 1 &
  bog #> 'foo &
  bog #> 44L &
  bog #> false

  "foo" #> "Hello"
  "foo" #> <span/>
  "foo" #> 1
  "foo" #> 'foo
  "foo" #> 44L
  "foo" #> false

  "foo" #> List(<span/>)
  "foo" #> Full(<span/>)
  "foo" #> Some(<span/>)


  "foo" #> List("Hello")
  "foo" #> Full("Dog")
  "foo" #> Some("Moo")


  "foo" #> List((null: Bindable))
  "foo" #> Full((null: Bindable))
  "foo" #> Some((null: Bindable))

  "foo" #> nsToNs _
  "foo" #> nsToOptNs _
  "foo" #> nsToBoxNs _
  "foo" #> nsToSeqNs _

  "foo" #> nsToString _
  "foo" #> nsToOptString _
  "foo" #> nsToBoxString _
  "foo" #> nsToSeqString _

  "#foo" #> Set("a", "b", "c")

  val nsf2: NodeSeq => NodeSeq = "foo" #> "Hello" &
  "foo" #> <span/> &
  "foo" #> 1 &
  "foo" #> 'foo &
  "foo" #> 44L &
  "foo" #> false

  "bar" #> List("1","2","3").map(s => "baz" #> s)

  "bar" #> Full(1).map(s => ("baz" #> s): CssBindFunc)
  "bar" #> Some(1).map(s => ("baz" #> s): CssBindFunc)



  def nsToNs(in: NodeSeq): NodeSeq = in
  def nsToOptNs(in: NodeSeq): Option[NodeSeq] = Some(in)
  def nsToBoxNs(in: NodeSeq): Box[NodeSeq] = Full(in)
  def nsToSeqNs(in: NodeSeq): Seq[NodeSeq] = List(in)

  def nsToString(in: NodeSeq): String = in.text
  def nsToOptString(in: NodeSeq): Option[String] = Some(in.text)
  def nsToBoxString(in: NodeSeq): Box[String] = Full(in.text)
  def nsToSeqString(in: NodeSeq): Seq[String] = List(in.text)
}
Something went wrong with that request. Please try again.