describe('Curse', function() {
  var $e, curse;

  beforeEach(function() {
    $e = document.createElement('div');
    curse = new Curse($e);

    $e.setAttribute('contenteditable', true);
    document.body.appendChild($e);
    $e.focus();
  });

  afterEach(function() {
    $e.remove();
  });

  describe('capturing and restoring over plaintext', function() {
    beforeEach(function() {
      $e.innerText = 'foo bar';
      var range = createRange([$e.childNodes[0], 2], [$e.childNodes[0], 6]);
      addRange(range);
      assertSelected('o ba');
      curse.capture();
    });

    it('can capture a selection', function() {
      [curse.start, curse.end].should.eql([2, 6]);
    });

    it('can restore a selection', function() {
      window.getSelection().removeAllRanges();
      curse.restore();
      assertSelected('o ba');
    });
  });

  describe('capturing and restoring spanning an HTML element', function() {
    beforeEach(function() {
      $e.innerHTML = 'foo <b>bar</b> baz';
      var range = createRange([$e.childNodes[0], 2], [$e.childNodes[2], 2]);
      addRange(range);
      assertSelected('o bar b');
      curse.capture();
    });

    it('can capture the selection', function() {
      [curse.start, curse.end].should.eql([2, 9]);
    });

    it('can restore the selection', function() {
      window.getSelection().removeAllRanges();
      curse.restore();
      assertSelected('o bar b');
    });
  });
});

function addRange(range) {
  var sel = window.getSelection();
  sel.removeAllRanges();
  sel.addRange(range);
}

function assertSelected(text) {
  window.getSelection().toString().should.eql(text);
}

function createRange(anchor, focus) {
  var r = document.createRange();
  r.setStart(anchor[0], anchor[1]);
  r.setEnd(focus[0], focus[1]);
  return r;
}

@@ -1432,16 +1432,599 @@
 );%0A  %7D);
+%0A%0A  describe('capturing and restoring spanning a newline', function() %7B%0A    beforeEach(function() %7B%0A      $e.innerText = 'foo%5Cnbar%5Cnbaz';%0A      var range = createRange(%5B$e.childNodes%5B0%5D, 1%5D, %5B$e.childNodes%5B4%5D, 1%5D);%0A      addRange(range);%0A      assertSelected('oo%5Cnbar%5Cnb');%0A      curse.capture();%0A    %7D);%0A%0A    it('can capture the selection', function() %7B%0A      %5Bcurse.start, curse.end%5D.should.eql(%5B1, 9%5D);%0A    %7D);%0A%0A    it('can restore the selection', function() %7B%0A      window.getSelection().removeAllRanges();%0A      curse.restore();%0A      assertSelected('oo%5Cnbar%5Cnb');%0A    %7D);%0A  %7D);
 %0A%7D);%0A%0Afu

Test selecting over newlines