/
source-test.js
46 lines (38 loc) · 1.43 KB
/
source-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { Source } from '../source';
describe('Source', () => {
it('asserts that a body was provided', () => {
// $FlowExpectedError[incompatible-call]
expect(() => new Source()).to.throw(
'Body must be a string. Received: undefined.',
);
});
it('asserts that a valid body was provided', () => {
// $FlowExpectedError[incompatible-call]
expect(() => new Source({})).to.throw(
'Body must be a string. Received: {}.',
);
});
it('can be Object.toStringified', () => {
const source = new Source('');
expect(Object.prototype.toString.call(source)).to.equal('[object Source]');
});
it('rejects invalid locationOffset', () => {
function createSource(locationOffset: { line: number, column: number }) {
return new Source('', '', locationOffset);
}
expect(() => createSource({ line: 0, column: 1 })).to.throw(
'line in locationOffset is 1-indexed and must be positive.',
);
expect(() => createSource({ line: -1, column: 1 })).to.throw(
'line in locationOffset is 1-indexed and must be positive.',
);
expect(() => createSource({ line: 1, column: 0 })).to.throw(
'column in locationOffset is 1-indexed and must be positive.',
);
expect(() => createSource({ line: 1, column: -1 })).to.throw(
'column in locationOffset is 1-indexed and must be positive.',
);
});
});