       length: 2
       expected:
         '<div>
-          <b>123</b>
-          <b>
+          <#>123</#>
+          <#>
             <i>45</i>
-          </b>
+          </#>
           <i>6</i>
         </div>
         <div>

      length: 4
      expected:
        '<div>
          <b>123</b>
          <i>456</i>
        </div>
        <div>
          <b>
            <s>7</s>
            <u>8</u>
            <s>9</s>
            <u>0</u>
          </b>
        </div>
        <div>
          <b>abcdefg</b>

      length: 6
      expected:
        '<div>
          <#>123</#>
          <i>456</i>
        </div>
        <div>
          <#>
            <s>7</s>
            <u>8</u>
            <s>9</s>
            <u>0</u>
          </#>
        </div>
        <div>
          <b>abcdefg</b>
        </div>'
    }]

    attributeTests = [{
      apply: true
      attribute: 'bold'
      tagName: 'b'
      value: true
    }, {
      apply: false
      attribute: 'bold'
      tagName: 'b'
      value: false
    }, {
      apply: true
      attribute: 'font-family'
      cssClass: 'font-serif'
      tagName: 'span'
      value: 'serif'
    }, {
      apply: false
      attribute: 'font-family'
      tagName: 'span'
      value: false
    }, {
      apply: false
      attribute: 'font-family'
      tagName: 'span'
      value: 'serif'
    }]
    
    _.each(tests, (test) ->
      _.each(attributeTests, (attrTest) ->
        it("should set #{attrTest.attribute} to #{attrTest.value} on #{test.target}", ->
          openTag = if attrTest.cssClass? then "#{attrTest.tagName} class=\"#{attrTest.cssClass}\"" else attrTest.tagName
          expected = test.expected.replace(/\/#/g, "/#{attrTest.tagName}").replace(/#/g, openTag)
          original = originalHtml.replace(/\/#/g, "/#{attrTest.tagName}").replace(/#/g, openTag)
          [startHtml, endHtml] = if attrTest.apply then [original, expected] else [expected, original]
          editor = reset(startHtml)
          editor.applyAttribute(test.start, test.length, attrTest.attribute, attrTest.value)
          range = new Tandem.Range(editor, test.start, test.start + test.length)
          attributes = range.getAttributeIntersection()
          if attrTest.value != false
            expect(attributes[attrTest.attribute]).to.equal(attrTest.value)
          else
            expect(attributes[attrTest.attribute]).to.be.undefined
          delta = editor.doc.toDelta()
          editor.doc.root.innerHTML = Tandem.Utils.cleanHtml(endHtml, true)
          editor.doc.buildLines()
          expect(delta).to.deep.equal(editor.doc.toDelta())
          expect(editor.doc.checkConsistency(true)).to.be.true
