forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextRange.unit.test.ts
More file actions
56 lines (53 loc) · 1.74 KB
/
textRange.unit.test.ts
File metadata and controls
56 lines (53 loc) · 1.74 KB
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
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as assert from 'assert';
import { TextRange } from '../../client/language/types';
// tslint:disable-next-line:max-func-body-length
suite('Language.TextRange', () => {
test('Empty static', async () => {
const e = TextRange.empty;
assert.equal(e.start, 0);
assert.equal(e.end, 0);
assert.equal(e.length, 0);
});
test('Construction', async () => {
let r = new TextRange(10, 20);
assert.equal(r.start, 10);
assert.equal(r.end, 30);
assert.equal(r.length, 20);
r = new TextRange(10, 0);
assert.equal(r.start, 10);
assert.equal(r.end, 10);
assert.equal(r.length, 0);
});
test('From bounds', async () => {
let r = TextRange.fromBounds(7, 9);
assert.equal(r.start, 7);
assert.equal(r.end, 9);
assert.equal(r.length, 2);
r = TextRange.fromBounds(5, 5);
assert.equal(r.start, 5);
assert.equal(r.end, 5);
assert.equal(r.length, 0);
});
test('Contains', async () => {
const r = TextRange.fromBounds(7, 9);
assert.equal(r.contains(-1), false);
assert.equal(r.contains(6), false);
assert.equal(r.contains(7), true);
assert.equal(r.contains(8), true);
assert.equal(r.contains(9), false);
assert.equal(r.contains(10), false);
});
test('Exceptions', async () => {
assert.throws(() => {
// @ts-ignore
const e = new TextRange(0, -1);
}, Error);
assert.throws(() => {
// @ts-ignore
const e = TextRange.fromBounds(3, 1);
}, Error);
});
});