-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
176 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/vs/editor/test/common/model/bracketPairColorizer/length.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import assert = require('assert'); | ||
import { Length, lengthAdd, lengthDiffNonNeg, lengthToObj, toLength } from 'vs/editor/common/model/bracketPairColorizer/length'; | ||
|
||
suite('Bracket Pair Colorizer - Length', () => { | ||
function toStr(length: Length): string { | ||
return lengthToObj(length).toString(); | ||
} | ||
|
||
test('Basic', () => { | ||
const l1 = toLength(100, 10); | ||
assert.strictEqual(lengthToObj(l1).lineCount, 100); | ||
assert.strictEqual(lengthToObj(l1).columnCount, 10); | ||
|
||
assert.deepStrictEqual(toStr(lengthAdd(l1, toLength(100, 10))), '200,10'); | ||
assert.deepStrictEqual(toStr(lengthAdd(l1, toLength(0, 10))), '100,20'); | ||
}); | ||
|
||
test('lengthDiffNonNeg', () => { | ||
assert.deepStrictEqual( | ||
toStr( | ||
lengthDiffNonNeg( | ||
toLength(100, 10), | ||
toLength(100, 20)) | ||
), | ||
'0,10' | ||
); | ||
|
||
assert.deepStrictEqual( | ||
toStr( | ||
lengthDiffNonNeg( | ||
toLength(100, 10), | ||
toLength(101, 20)) | ||
), | ||
'1,20' | ||
); | ||
|
||
assert.deepStrictEqual( | ||
toStr( | ||
lengthDiffNonNeg( | ||
toLength(101, 30), | ||
toLength(101, 20)) | ||
), | ||
'0,0' | ||
); | ||
|
||
assert.deepStrictEqual( | ||
toStr( | ||
lengthDiffNonNeg( | ||
toLength(102, 10), | ||
toLength(101, 20)) | ||
), | ||
'0,0' | ||
); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
src/vs/editor/test/common/model/bracketPairColorizer/mergeItems.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import assert = require('assert'); | ||
import { AstNode, AstNodeKind, ListAstNode, TextAstNode } from 'vs/editor/common/model/bracketPairColorizer/ast'; | ||
import { toLength } from 'vs/editor/common/model/bracketPairColorizer/length'; | ||
import { merge23Trees } from 'vs/editor/common/model/bracketPairColorizer/mergeItems'; | ||
|
||
suite('Bracket Pair Colorizer - mergeItems', () => { | ||
test('Clone', () => { | ||
const tree = ListAstNode.create([ | ||
new TextAstNode(toLength(1, 1)), | ||
new TextAstNode(toLength(1, 1)), | ||
]); | ||
|
||
assert.ok(equals(tree, tree.clone())); | ||
}); | ||
|
||
function equals(node1: AstNode, node2: AstNode): boolean { | ||
if (node1.length !== node2.length) { | ||
return false; | ||
} | ||
|
||
if (node1.children.length !== node2.children.length) { | ||
return false; | ||
} | ||
|
||
for (let i = 0; i < node1.children.length; i++) { | ||
if (!equals(node1.children[i], node2.children[i])) { | ||
return false; | ||
} | ||
} | ||
|
||
if (!node1.unopenedBrackets.equals(node2.unopenedBrackets)) { | ||
return false; | ||
} | ||
|
||
if (node1.kind === AstNodeKind.Pair && node2.kind === AstNodeKind.Pair) { | ||
return node1.category === node2.category; | ||
} else if (node1.kind === node2.kind) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
function testMerge(lists: AstNode[]) { | ||
const node = (merge23Trees(lists.map(l => l.clone())) || ListAstNode.create([])).flattenLists(); | ||
// This trivial merge does not maintain the (2,3) tree invariant. | ||
const referenceNode = ListAstNode.create(lists).flattenLists(); | ||
|
||
assert.ok(equals(node, referenceNode), 'merge23Trees failed'); | ||
} | ||
|
||
test('Empty List', () => { | ||
testMerge([]); | ||
}); | ||
|
||
test('Same Height Lists', () => { | ||
const textNode = new TextAstNode(toLength(1, 1)); | ||
const tree = ListAstNode.create([textNode.clone(), textNode.clone()]); | ||
testMerge([tree.clone(), tree.clone(), tree.clone(), tree.clone(), tree.clone()]); | ||
}); | ||
|
||
test('Different Height Lists 1', () => { | ||
const textNode = new TextAstNode(toLength(1, 1)); | ||
const tree1 = ListAstNode.create([textNode.clone(), textNode.clone()]); | ||
const tree2 = ListAstNode.create([tree1.clone(), tree1.clone()]); | ||
|
||
testMerge([tree1, tree2]); | ||
}); | ||
|
||
test('Different Height Lists 2', () => { | ||
const textNode = new TextAstNode(toLength(1, 1)); | ||
const tree1 = ListAstNode.create([textNode.clone(), textNode.clone()]); | ||
const tree2 = ListAstNode.create([tree1.clone(), tree1.clone()]); | ||
|
||
testMerge([tree2, tree1]); | ||
}); | ||
|
||
test('Different Height Lists 3', () => { | ||
const textNode = new TextAstNode(toLength(1, 1)); | ||
const tree1 = ListAstNode.create([textNode.clone(), textNode.clone()]); | ||
const tree2 = ListAstNode.create([tree1.clone(), tree1.clone()]); | ||
|
||
testMerge([tree2, tree1, tree1, tree2, tree2]); | ||
}); | ||
}); |