forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextRangeCollection.test.ts
More file actions
88 lines (84 loc) · 3.18 KB
/
textRangeCollection.test.ts
File metadata and controls
88 lines (84 loc) · 3.18 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as assert from 'assert';
import { TextRangeCollection } from '../../client/language/textRangeCollection';
import { TextRange } from '../../client/language/types';
// tslint:disable-next-line:max-func-body-length
suite('Language.TextRangeCollection', () => {
test('Empty', async () => {
const items: TextRange[] = [];
const c = new TextRangeCollection(items);
assert.equal(c.start, 0);
assert.equal(c.end, 0);
assert.equal(c.length, 0);
assert.equal(c.count, 0);
});
test('Basic', async () => {
const items: TextRange[] = [];
items.push(new TextRange(2, 1));
items.push(new TextRange(4, 2));
const c = new TextRangeCollection(items);
assert.equal(c.start, 2);
assert.equal(c.end, 6);
assert.equal(c.length, 4);
assert.equal(c.count, 2);
assert.equal(c.getItemAt(0).start, 2);
assert.equal(c.getItemAt(0).length, 1);
assert.equal(c.getItemAt(1).start, 4);
assert.equal(c.getItemAt(1).length, 2);
});
test('Contains position (simple)', async () => {
const items: TextRange[] = [];
items.push(new TextRange(2, 1));
items.push(new TextRange(4, 2));
const c = new TextRangeCollection(items);
const results = [-1, -1, 0, -1, 1, 1, -1];
for (let i = 0; i < results.length; i += 1) {
const index = c.getItemContaining(i);
assert.equal(index, results[i]);
}
});
test('Contains position (adjoint)', async () => {
const items: TextRange[] = [];
items.push(new TextRange(2, 1));
items.push(new TextRange(3, 2));
const c = new TextRangeCollection(items);
const results = [-1, -1, 0, 1, 1, -1, -1];
for (let i = 0; i < results.length; i += 1) {
const index = c.getItemContaining(i);
assert.equal(index, results[i]);
}
});
test('Contains position (out of range)', async () => {
const items: TextRange[] = [];
items.push(new TextRange(2, 1));
items.push(new TextRange(4, 2));
const c = new TextRangeCollection(items);
const positions = [-100, -1, 10, 100];
for (const p of positions) {
const index = c.getItemContaining(p);
assert.equal(index, -1);
}
});
test('Contains position (empty)', async () => {
const items: TextRange[] = [];
const c = new TextRangeCollection(items);
const positions = [-2, -1, 0, 1, 2, 3];
for (const p of positions) {
const index = c.getItemContaining(p);
assert.equal(index, -1);
}
});
test('Item at position', async () => {
const items: TextRange[] = [];
items.push(new TextRange(2, 1));
items.push(new TextRange(4, 2));
const c = new TextRangeCollection(items);
const results = [-1, -1, 0, -1, 1, -1, -1];
for (let i = 0; i < results.length; i += 1) {
const index = c.getItemAtPosition(i);
assert.equal(index, results[i]);
}
});
});