 
   
   describe('applyAttribute', ->
-    reset = ->
-      $('#editor-container').html(Tandem.Utils.removeHtmlWhitespace('
-        <div class="line">
-          <b>123</b>
-          <i>456</i>
+    originalHtml = Tandem.Utils.removeHtmlWhitespace('
+      <div class="line">
+        <b>123</b>
+        <i>456</i>
+      </div>
+      <div class="line">
+        <s>7</s>
+        <u>8</u>
+        <s>9</s>
+        <u>0</u>
+      </div>
+      <div class="line">
+        <b>abcdefg</b>
+      </div>
+    ')
+
+    reset = (html = originalHtml) ->
+      $('#editor-container').html(Tandem.Utils.removeHtmlWhitespace(html))
+      return new Tandem.Editor('editor-container')
+
+    tests = [{
+      target: 'single node'
+      start: 8
+      length: 1
+      expected:
+        '<div class="line">
+          <b>123</b>
+          <i>456</i>
+        </div>
+        <div class="line">
+          <s>7</s>
+          <b>
+            <u>8</u>
+          </b>
+          <s>9</s>
+          <u>0</u>
+        </div>
+        <div class="line">
+          <b>abcdefg</b>
+        </div>'
+    }, {
+      target: 'multiple nodes'
+      start: 8
+      length: 2
+      expected:
+        '<div class="line">
+          <b>123</b>
+          <i>456</i>
+        </div>
+        <div class="line">
+          <s>7</s>
+          <b>
+            <u>8</u>
+            <s>9</s>
+          </b>
+          <u>0</u>
+        </div>
+        <div class="line">
+          <b>abcdefg</b>
+        </div>'
+    }, {
+      target: 'part of node'
+      start: 3
+      length: 2
+      expected:
+        '<div class="line">
+          <b>123</b>
+          <b>
+            <i>45</i>
+          </b>
+          <i>6</i>
         </div>
         <div class="line">
           <s>7</s>

          <b>abcdefg</b>
        </div>'
    }, {
      name: 'should apply to entire line with preceding and trailing newline'
      start: 6
      length: 6
      expected:

          <b>abcdefg</b>
        </div>'
    }, {
      target: 'nodes spanning multiple lines'
      start: 3
      length: 6
      expected:
        '<div class="line">
          <b>123</b>
          <b>
            <i>456</i>
          </b>
        </div>
        <div class="line">
          <b>
            <s>7</s>
            <u>8</u>
          </b>
          <s>9</s>
          <u>0</u>
        </div>
