Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/test/common/model/linesTextBuffer/linesTextBufferBuilder.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import * as strings from '../../../../../base/common/strings.js';
8
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
9
import { DefaultEndOfLine } from '../../../../common/model.js';
10
import { createTextBufferFactory } from '../../../../common/model/textModel.js';
11
12
function testTextBufferFactory(text: string, eol: string, mightContainNonBasicASCII: boolean, mightContainRTL: boolean): void {
13
const { disposable, textBuffer } = createTextBufferFactory(text).create(DefaultEndOfLine.LF);
14
15
assert.strictEqual(textBuffer.mightContainNonBasicASCII(), mightContainNonBasicASCII);
16
assert.strictEqual(textBuffer.mightContainRTL(), mightContainRTL);
17
assert.strictEqual(textBuffer.getEOL(), eol);
18
disposable.dispose();
19
}
20
21
suite('ModelBuilder', () => {
22
23
ensureNoDisposablesAreLeakedInTestSuite();
24
25
test('t1', () => {
26
testTextBufferFactory('', '\n', false, false);
27
});
28
29
test('t2', () => {
30
testTextBufferFactory('Hello world', '\n', false, false);
31
});
32
33
test('t3', () => {
34
testTextBufferFactory('Hello world\nHow are you?', '\n', false, false);
35
});
36
37
test('t4', () => {
38
testTextBufferFactory('Hello world\nHow are you?\nIs everything good today?\nDo you enjoy the weather?', '\n', false, false);
39
});
40
41
test('carriage return detection (1 \\r\\n 2 \\n)', () => {
42
testTextBufferFactory('Hello world\r\nHow are you?\nIs everything good today?\nDo you enjoy the weather?', '\n', false, false);
43
});
44
45
test('carriage return detection (2 \\r\\n 1 \\n)', () => {
46
testTextBufferFactory('Hello world\r\nHow are you?\r\nIs everything good today?\nDo you enjoy the weather?', '\r\n', false, false);
47
});
48
49
test('carriage return detection (3 \\r\\n 0 \\n)', () => {
50
testTextBufferFactory('Hello world\r\nHow are you?\r\nIs everything good today?\r\nDo you enjoy the weather?', '\r\n', false, false);
51
});
52
53
test('BOM handling', () => {
54
testTextBufferFactory(strings.UTF8_BOM_CHARACTER + 'Hello world!', '\n', false, false);
55
});
56
57
test('RTL handling 2', () => {
58
testTextBufferFactory('Hello world!זוהי עובדה מבוססת שדעתו', '\n', true, true);
59
});
60
61
test('RTL handling 3', () => {
62
testTextBufferFactory('Hello world!זוהי \nעובדה מבוססת שדעתו', '\n', true, true);
63
});
64
65
test('ASCII handling 1', () => {
66
testTextBufferFactory('Hello world!!\nHow do you do?', '\n', false, false);
67
});
68
test('ASCII handling 2', () => {
69
testTextBufferFactory('Hello world!!\nHow do you do?Züricha📚📚b', '\n', true, false);
70
});
71
});
72
73