本文整理汇总了TypeScript中vs/editor/common/services/editorSimpleWorker.ICommonModel类的典型用法代码示例。如果您正苦于以下问题:TypeScript ICommonModel类的具体用法?TypeScript ICommonModel怎么用?TypeScript ICommonModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ICommonModel类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('ICommonModel#getValueInRange, issue #17424', function () {
let model = worker.addModel([
'package main', // 1
'func foo() {', // 2
'}' // 3
]);
const value = model.getValueInRange({ startLineNumber: 3, startColumn: 1, endLineNumber: 4, endColumn: 1 });
assert.equal(value, '}');
});
示例2: suite
suite('EditorSimpleWorker', () => {
class WorkerWithModels extends EditorSimpleWorkerImpl {
getModel(uri: string) {
return this._getModel(uri);
}
addModel(lines: string[], eol: string = '\n') {
const uri = 'test:file#' + Date.now();
this.acceptNewModel({
url: uri,
versionId: 1,
lines: lines,
EOL: eol
});
return this._getModel(uri);
}
}
let worker: WorkerWithModels;
let model: ICommonModel;
setup(() => {
worker = new WorkerWithModels();
model = worker.addModel([
'This is line one', //16
'and this is line number two', //27
'it is followed by #3', //20
'and finished with the fourth.', //29
]);
});
function assertPositionAt(offset: number, line: number, column: number) {
let position = model.positionAt(offset);
assert.equal(position.lineNumber, line);
assert.equal(position.column, column);
}
function assertOffsetAt(lineNumber: number, column: number, offset: number) {
let actual = model.offsetAt({ lineNumber, column });
assert.equal(actual, offset);
}
test('ICommonModel#offsetAt', function () {
assertOffsetAt(1, 1, 0);
assertOffsetAt(1, 2, 1);
assertOffsetAt(1, 17, 16);
assertOffsetAt(2, 1, 17);
assertOffsetAt(2, 4, 20);
assertOffsetAt(3, 1, 45);
assertOffsetAt(5, 30, 95);
assertOffsetAt(5, 31, 95);
assertOffsetAt(5, Number.MAX_VALUE, 95);
assertOffsetAt(6, 30, 95);
assertOffsetAt(Number.MAX_VALUE, 30, 95);
assertOffsetAt(Number.MAX_VALUE, Number.MAX_VALUE, 95);
});
test('ICommonModel#positionAt', function () {
assertPositionAt(0, 1, 1);
assertPositionAt(Number.MIN_VALUE, 1, 1);
assertPositionAt(1, 1, 2);
assertPositionAt(16, 1, 17);
assertPositionAt(17, 2, 1);
assertPositionAt(20, 2, 4);
assertPositionAt(45, 3, 1);
assertPositionAt(95, 4, 30);
assertPositionAt(96, 4, 30);
assertPositionAt(99, 4, 30);
assertPositionAt(Number.MAX_VALUE, 4, 30);
});
test('ICommonModel#validatePosition, issue #15882', function () {
let model = worker.addModel(['{"id": "0001","type": "donut","name": "Cake","image":{"url": "images/0001.jpg","width": 200,"height": 200},"thumbnail":{"url": "images/thumbnails/0001.jpg","width": 32,"height": 32}}']);
assert.equal(model.offsetAt({ lineNumber: 1, column: 2 }), 1);
});
test('MoreMinimal', function () {
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: 'This is line One', range: new Range(1, 1, 1, 17) }], []).then(edits => {
assert.equal(edits.length, 1);
const [first] = edits;
assert.equal(first.text, 'O');
assert.deepEqual(first.range, { startLineNumber: 1, startColumn: 14, endLineNumber: 1, endColumn: 15 });
});
});
test('MoreMinimal, issue #15385 newline changes only', function () {
let model = worker.addModel([
'{',
'\t"a":1',
'}'
], '\n');
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: '{\r\n\t"a":1\r\n}', range: new Range(1, 1, 3, 2) }], []).then(edits => {
assert.equal(edits.length, 0);
});
});
//.........这里部分代码省略.........
示例3: suite
suite('EditorSimpleWorker', () => {
class WorkerWithModels extends EditorSimpleWorkerImpl {
getModel(uri: string) {
return this._getModel(uri);
}
addModel(lines: string[], eol: string = '\n') {
const uri = 'test:file#' + Date.now();
this.acceptNewModel({
url: uri,
versionId: 1,
value: {
EOL: eol,
lines,
BOM: undefined,
containsRTL: undefined,
length: undefined,
options: undefined
}
});
return this._getModel(uri);
}
}
let worker: WorkerWithModels;
let model: ICommonModel;
setup(() => {
worker = new WorkerWithModels();
model = worker.addModel([
'This is line one', //16
'and this is line number two', //27
'it is followed by #3', //20
'and finished with the fourth.', //29
]);
});
function assertPositionAt(offset: number, line: number, column: number) {
let position = model.positionAt(offset);
assert.equal(position.lineNumber, line);
assert.equal(position.column, column);
}
function assertOffsetAt(lineNumber: number, column: number, offset: number) {
let actual = model.offsetAt({ lineNumber, column });
assert.equal(actual, offset);
}
test('ICommonModel#offsetAt', function () {
assertOffsetAt(1, 1, 0);
assertOffsetAt(1, 2, 1);
assertOffsetAt(1, 17, 16);
assertOffsetAt(2, 1, 17);
assertOffsetAt(2, 4, 20);
assertOffsetAt(3, 1, 45);
assertOffsetAt(5, 30, 95);
assertOffsetAt(5, 31, 95);
assertOffsetAt(5, Number.MAX_VALUE, 95);
assertOffsetAt(6, 30, 95);
assertOffsetAt(Number.MAX_VALUE, 30, 95);
assertOffsetAt(Number.MAX_VALUE, Number.MAX_VALUE, 95);
});
test('ICommonModel#positionAt', function () {
assertPositionAt(0, 1, 1);
assertPositionAt(Number.MIN_VALUE, 1, 1);
assertPositionAt(1, 1, 2);
assertPositionAt(16, 1, 17);
assertPositionAt(17, 2, 1);
assertPositionAt(20, 2, 4);
assertPositionAt(45, 3, 1);
assertPositionAt(95, 4, 30);
assertPositionAt(96, 4, 30);
assertPositionAt(99, 4, 30);
assertPositionAt(Number.MAX_VALUE, 4, 30);
});
test('MoreMinimal', function () {
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: 'This is line One', range: new Range(1, 1, 1, 17) }], []).then(edits => {
assert.equal(edits.length, 1);
const [first] = edits;
assert.equal(first.text, 'O');
assert.deepEqual(first.range, { startLineNumber: 1, startColumn: 14, endLineNumber: 1, endColumn: 15 });
});
});
test('MoreMinimal, issue #15385 newline changes only', function () {
let model = worker.addModel([
'{',
'\t"a":1',
'}'
], '\n');
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: '{\r\n\t"a":1\r\n}', range: new Range(1, 1, 3, 2) }], []).then(edits => {
assert.equal(edits.length, 0);
});
//.........这里部分代码省略.........
示例4: function
test('get words via iterator, issue #46930', function () {
let model = worker.addModel([
'one line', // 1
'two line', // 2
'',
'past empty',
'single',
'',
'and now we are done'
]);
let words: string[] = [];
for (let iter = model.createWordIterator(/[a-z]+/img), e = iter.next(); !e.done; e = iter.next()) {
words.push(e.value);
}
assert.deepEqual(words, ['one', 'line', 'two', 'line', 'past', 'empty', 'single', 'and', 'now', 'we', 'are', 'done']);
});
示例5: assertOffsetAt
function assertOffsetAt(lineNumber: number, column: number, offset: number) {
let actual = model.offsetAt({ lineNumber, column });
assert.equal(actual, offset);
}
示例6: assertPositionAt
function assertPositionAt(offset: number, line: number, column: number) {
let position = model.positionAt(offset);
assert.equal(position.lineNumber, line);
assert.equal(position.column, column);
}