Skip to content

Commit

Permalink
Remove unused MarkupSection#markerContaining
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Aug 18, 2015
1 parent 019814e commit 44518f8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 101 deletions.
33 changes: 0 additions & 33 deletions src/js/models/markup-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,37 +121,4 @@ export default class Section extends LinkedItem {
this.markers.append(m.clone());
});
}

/**
* A marker contains this offset if:
* * The offset is between the marker's start and end
* * the offset is between two markers and this is the right marker (and leftInclusive is true)
* * the offset is between two markers and this is the left marker (and leftInclusive is false)
*
* @return {Marker} The marker that contains this offset
*/
markerContaining(offset, leftInclusive=true) {
let length = 0;
let lastMarker = null;

if (offset === 0) {
return this.markers.head;
}

this.markers.detect((marker) => {
if (length < offset) {
lastMarker = marker;
length += marker.length;
return false;
} else {
return true; // stop iteration
}
});

if (length > offset) {
return lastMarker;
} else if (length === offset) {
return (leftInclusive ? lastMarker.next : lastMarker);
}
}
}
68 changes: 0 additions & 68 deletions tests/unit/models/markup-section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,6 @@ test('a section can append a marker', (assert) => {
assert.equal(s1.markers.length, 1);
});

test('#markerContaining finds the marker at the given offset when 1 marker', (assert) => {
const m = builder.createMarker('hi there!');
const s = builder.createMarkupSection('h2',[m]);

for (let i=0; i<m.length; i++) {
assert.equal(s.markerContaining(i), m, `finds marker at offset ${i}`);
}
});

test('#markerContaining finds the marker at the given offset when 2 markers', (assert) => {
const m1 = builder.createMarker('hi ');
const m2 = builder.createMarker('there!');
const s = builder.createMarkupSection('h2',[m1,m2]);

assert.equal(s.markerContaining(0), m1,
'first marker is always found at offset 0');
assert.equal(s.markerContaining(m1.length + m2.length, false), m2,
'last marker is found at offset === length when right-inclusive');
assert.ok(!s.markerContaining(m1.length + m2.length + 1),
'when offset > length && left-inclusive, no marker is found');
assert.ok(!s.markerContaining(m1.length + m2.length + 1, false),
'when offset > length && right-inclusive, no marker is found');

for (let i=1; i<m1.length; i++) {
assert.equal(s.markerContaining(i), m1, `finds marker 1 at offset ${i}`);
}
assert.equal(s.markerContaining(m1.length), m2, `finds marker m2 (left-inclusive)`);
assert.equal(s.markerContaining(m1.length, false), m1, `finds marker m1 (right-inclusive)`);

for (let i=m1.length+1; i<(m1.length+m2.length); i++) {
assert.equal(s.markerContaining(i), m2, `finds marker 2 at offset ${i}`);
}
});

test('#markerContaining finds the marker at the given offset when multiple markers', (assert) => {
const m1 = builder.createMarker('hi ');
const m2 = builder.createMarker('there!');
const m3 = builder.createMarker(' and more');
const markerLength = [m1,m2,m3].reduce((prev, cur) => prev + cur.length, 0);
const s = builder.createMarkupSection('h2',[m1,m2,m3]);

assert.equal(s.markerContaining(0), m1,
'first marker is always found at offset 0');
assert.ok(!s.markerContaining(markerLength),
'last marker is undefined at offset === length (left-inclusive)');
assert.equal(s.markerContaining(markerLength, false), m3,
'last marker is found at offset === length (right-inclusive)');
assert.ok(!s.markerContaining(markerLength + 1),
'no marker is found at offset > length');

for (let i=1; i<m1.length; i++) {
assert.equal(s.markerContaining(i), m1, `finds marker 1 at offset ${i}`);
}
assert.equal(s.markerContaining(m1.length), m2, `finds m2 (left-inclusive)`);
assert.equal(s.markerContaining(m1.length, false), m1, `finds m1 (right-inclusive)`);

for (let i=m1.length+1; i<(m1.length+m2.length); i++) {
assert.equal(s.markerContaining(i), m2, `finds marker 2 at offset ${i}`);
}

assert.equal(s.markerContaining(m1.length+m2.length), m3, `finds m3 (left-inclusive)`);
assert.equal(s.markerContaining(m1.length+m2.length, false), m2, `finds m2 (right-inclusive)`);

for (let i=m1.length+m2.length+1; i<markerLength; i++) {
assert.equal(s.markerContaining(i), m3, `finds marker 3 at offset ${i}`);
}
});

test('#splitMarker splits the marker at the offset', (assert) => {
const m1 = builder.createMarker('hi ');
const m2 = builder.createMarker('there!');
Expand Down

0 comments on commit 44518f8

Please sign in to comment.