forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbraceCounter.unit.test.ts
More file actions
50 lines (39 loc) · 1.74 KB
/
Copy pathbraceCounter.unit.test.ts
File metadata and controls
50 lines (39 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as assert from 'assert';
import { BraceCounter } from '../../client/language/braceCounter';
import { Tokenizer } from '../../client/language/tokenizer';
suite('Language.BraceCounter', () => {
test('Brace counting: zero braces', () => {
const counter = new BraceCounter();
assert.equal(counter.count, 0);
});
['(x)', '[x]', '{x}'].forEach((text) => {
test(`Brace counting: ${text}`, () => {
const counter = new BraceCounter();
const tokens = new Tokenizer().tokenize(text);
assert.equal(tokens.count, 3);
const openBrace = tokens.getItemAt(0);
const identifier = tokens.getItemAt(1);
const closeBrace = tokens.getItemAt(2);
assert.ok(counter.countBrace(tokens.getItemAt(0)));
assert.equal(counter.countBrace(tokens.getItemAt(1)), false);
assert.equal(counter.isOpened(openBrace.type), true);
assert.equal(counter.isOpened(identifier.type), false);
assert.equal(counter.isOpened(closeBrace.type), true);
assert.ok(counter.countBrace(tokens.getItemAt(2)));
});
});
['(x))', '[x]]', '{x}}'].forEach((text) => {
test(`Brace counting with additional close brace: ${text}`, () => {
const counter = new BraceCounter();
const tokens = new Tokenizer().tokenize(text);
assert.equal(tokens.count, 4);
for (let i = 0; i < tokens.count - 1; i += 1) {
counter.countBrace(tokens.getItemAt(i));
}
assert.ok(counter.countBrace(tokens.getItemAt(3)));
});
});
});