Commit 053b1611 authored by Robert Knight's avatar Robert Knight

Add test for what happens if output string is short

parent 4e124a6f
......@@ -110,5 +110,26 @@ describe('annotator/util/normalize', () => {
assert.equal(outStart, outStr.indexOf('c'));
assert.equal(outEnd, outStart);
});
it('does not return offsets beyond output string length', () => {
const inStr = 'foo bar baz';
const start = inStr.indexOf('bar');
const end = start + 'bar'.length;
const outStrs = ['', 'foo b', 'fooba'];
for (let outStr of outStrs) {
const [outStart, outEnd] = translateOffsets(
inStr,
outStr,
start,
end,
isNotSpace
);
const outSubStr = outStr.slice(outStart, outEnd);
assert.equal(outSubStr, inStr.slice(start, start + outSubStr.length));
assert.isAtMost(outStart, outStr.length);
assert.isAtMost(outEnd, outStr.length);
}
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment