|
| 1 | +jest.disableAutomock(); |
| 2 | + |
| 3 | +import { Position, SourceLocation } from '../location'; |
| 4 | + |
| 5 | +describe('Position', () => { |
| 6 | + const line = 10; |
| 7 | + const column = 5; |
| 8 | + |
| 9 | + it('creates a new instance with line and column set', () => { |
| 10 | + const p = new Position(line, column); |
| 11 | + expect(p instanceof Position).toBe(true); |
| 12 | + |
| 13 | + expect(p.line).toBe(line); |
| 14 | + expect(p.column).toBe(column); |
| 15 | + }); |
| 16 | + |
| 17 | + it('clones the instance', () => { |
| 18 | + const p = new Position(line, column); |
| 19 | + const c = p.clone(); |
| 20 | + |
| 21 | + expect(p).toEqual(c); |
| 22 | + expect(p).not.toBe(c); |
| 23 | + }); |
| 24 | +}); |
| 25 | + |
| 26 | +describe('SourceLocation', () => { |
| 27 | + const start = new Position(0, 0); |
| 28 | + const end = new Position(10, 50); |
| 29 | + |
| 30 | + it('creates a new instance with start and end set', () => { |
| 31 | + const loc = new SourceLocation(start, end); |
| 32 | + expect(loc instanceof SourceLocation).toBe(true); |
| 33 | + |
| 34 | + expect(loc.start).toBe(start); |
| 35 | + expect(loc.end).toBe(end); |
| 36 | + }); |
| 37 | + |
| 38 | + it('clones the instance and the position', () => { |
| 39 | + const loc = new SourceLocation(start, end); |
| 40 | + const c = loc.clone(); |
| 41 | + |
| 42 | + expect(loc).toEqual(c); |
| 43 | + expect(loc).not.toBe(c); |
| 44 | + expect(c.start).not.toBe(start); |
| 45 | + expect(c.end).not.toBe(end); |
| 46 | + }); |
| 47 | +}); |
0 commit comments