53
}
54
55
>
function assertOneDirectionLineMapping(model: TextModel, direction: AssertDocumentLineMappingDirection, msg: string): void {
editableTextModelTestUtils.ts
56
>
const allText = model.getValue();
57
>
58
>
let line = 1, column = 1, previousIsCarriageReturn = false;
59
>
for (let offset = 0; offset <= allText.length; offset++) {
60
>
// The position coordinate system cannot express the position between \r and \n
61
>
const position: Position = new Position(line, column + (previousIsCarriageReturn ? -1 : 0));
62
>
63
>
if (direction === AssertDocumentLineMappingDirection.OffsetToPosition) {
64
>
const actualPosition = model.getPositionAt(offset);
65
>
assert.strictEqual(actualPosition.toString(), position.toString(), msg + ' - getPositionAt mismatch for offset ' + offset);
66
>
} else {
67
>
// The position coordinate system cannot express the position between \r and \n
68
>
const expectedOffset: number = offset + (previousIsCarriageReturn ? -1 : 0);
69
>
const actualOffset = model.getOffsetAt(position);
70
>
assert.strictEqual(actualOffset, expectedOffset, msg + ' - getOffsetAt mismatch for position ' + position.toString());
71
>
}
72
>
73
>
if (allText.charAt(offset) === '\n') {
74
line++;
75
column = 1;
77
>
column++;
78
>
}
79
>
80
>
previousIsCarriageReturn = (allText.charAt(offset) === '\r');
81
>
}
82
>
}
83
85
>
assertOneDirectionLineMapping(model, AssertDocumentLineMappingDirection.PositionToOffset, msg);
86
>
assertOneDirectionLineMapping(model, AssertDocumentLineMappingDirection.OffsetToPosition, msg);
87
>
}
88
89
90
export function assertSyncedModels(text: string, callback: (model: TextModel, assertMirrorModels: () => void) => void, setup: ((model: TextModel) => void) | null = null): void {
92
>
model.setEOL(EndOfLineSequence.LF);
93
>
assertLineMapping(model, 'model');
94
>
95
>
if (setup) {
96
setup(model);
97
assertLineMapping(model, 'model');
98
}
100
>
const mirrorModel2 = new MirrorTextModel(null!, model.getLinesContent(), model.getEOL(), model.getVersionId());
101
>
let mirrorModel2PrevVersionId = model.getVersionId();
102
>
103
>
const disposable = model.onDidChangeContent((e: IModelContentChangedEvent) => {
104
const versionId = e.versionId;
105
if (versionId < mirrorModel2PrevVersionId) {