fix(aio): region parser error line numbers were off by one

This commit is contained in:
Peter Bacon Darwin 2017-02-21 07:25:27 +00:00 committed by Igor Minar
parent c208f97461
commit 6a9251874b
2 changed files with 6 additions and 5 deletions

View File

@ -114,7 +114,8 @@ function removeLast(array, item) {
array.splice(index, 1);
}
function RegionParserError(message, lineNum) {
function RegionParserError(message, index) {
const lineNum = index + 1;
this.message = `regionParser: ${message} (at line ${lineNum}).`;
this.lineNum = lineNum;
this.stack = (new Error()).stack;

View File

@ -96,24 +96,24 @@ describe('regionParser service', () => {
it('should error if we attempt to open an already open region', () => {
expect(() => regionParser(t('/* #docregion */', 'abc', '/* #docregion */', 'def'), 'test-type'))
.toThrowError(
'regionParser: Tried to open a region, named "", that is already open (at line 2).');
'regionParser: Tried to open a region, named "", that is already open (at line 3).');
expect(
() =>
regionParser(t('/* #docregion X */', 'abc', '/* #docregion X */', 'def'), 'test-type'))
.toThrowError(
'regionParser: Tried to open a region, named "X", that is already open (at line 2).');
'regionParser: Tried to open a region, named "X", that is already open (at line 3).');
});
it('should error if we attempt to close an already closed region', () => {
expect(() => regionParser(t('abc', '/* #enddocregion */', 'def'), 'test-type'))
.toThrowError('regionParser: Tried to close a region when none are open (at line 1).');
.toThrowError('regionParser: Tried to close a region when none are open (at line 2).');
expect(
() =>
regionParser(t('/* #docregion */', 'abc', '/* #enddocregion X */', 'def'), 'test-type'))
.toThrowError(
'regionParser: Tried to close a region, named "X", that is not open (at line 2).');
'regionParser: Tried to close a region, named "X", that is not open (at line 3).');
});
it('should handle whitespace in region names on single annotation', () => {