aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-tracing-utils/test/utils_test.ts
blob: 6fc8fcfe1d451a06604176f8069e35da970e28ef (plain) (blame)
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
47
48
49
50
51
52
53
import * as chai from 'chai';
import * as dirtyChai from 'dirty-chai';
import 'mocha';

import { utils } from '../src/utils';

chai.use(dirtyChai);
const expect = chai.expect;

describe('utils', () => {
    describe('#compareLineColumn', () => {
        it('correctly compares LineColumns', () => {
            expect(utils.compareLineColumn({ line: 1, column: 3 }, { line: 1, column: 4 })).to.be.lessThan(0);
            expect(utils.compareLineColumn({ line: 1, column: 4 }, { line: 1, column: 3 })).to.be.greaterThan(0);
            expect(utils.compareLineColumn({ line: 1, column: 3 }, { line: 1, column: 3 })).to.be.equal(0);
            expect(utils.compareLineColumn({ line: 0, column: 2 }, { line: 1, column: 0 })).to.be.lessThan(0);
            expect(utils.compareLineColumn({ line: 1, column: 0 }, { line: 0, column: 2 })).to.be.greaterThan(0);
        });
    });

    describe('#isRangeInside', () => {
        it('returns true if inside', () => {
            expect(
                utils.isRangeInside(
                    { start: { line: 1, column: 3 }, end: { line: 1, column: 4 } },
                    { start: { line: 1, column: 2 }, end: { line: 1, column: 5 } },
                ),
            ).to.be.true();
        });
        it('returns true if the same', () => {
            expect(
                utils.isRangeInside(
                    { start: { line: 1, column: 3 }, end: { line: 1, column: 4 } },
                    { start: { line: 1, column: 3 }, end: { line: 1, column: 4 } },
                ),
            ).to.be.true();
        });
        it('returns false if not inside', () => {
            expect(
                utils.isRangeInside(
                    { start: { line: 1, column: 3 }, end: { line: 1, column: 4 } },
                    { start: { line: 1, column: 4 }, end: { line: 1, column: 4 } },
                ),
            ).to.be.false();
            expect(
                utils.isRangeInside(
                    { start: { line: 1, column: 3 }, end: { line: 1, column: 4 } },
                    { start: { line: 1, column: 4 }, end: { line: 1, column: 5 } },
                ),
            ).to.be.false();
        });
    });
});