Path: blob/main/src/vs/editor/test/common/controller/cursorAtomicMoveOperations.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';7import { AtomicTabMoveOperations, Direction } from '../../../common/cursor/cursorAtomicMoveOperations.js';89suite('Cursor move command test', () => {1011ensureNoDisposablesAreLeakedInTestSuite();1213test('Test whitespaceVisibleColumn', () => {14const testCases = [15{16lineContent: ' ',17tabSize: 4,18expectedPrevTabStopPosition: [-1, 0, 0, 0, 0, 4, 4, 4, 4, -1],19expectedPrevTabStopVisibleColumn: [-1, 0, 0, 0, 0, 4, 4, 4, 4, -1],20expectedVisibleColumn: [0, 1, 2, 3, 4, 5, 6, 7, 8, -1],21},22{23lineContent: ' ',24tabSize: 4,25expectedPrevTabStopPosition: [-1, 0, 0, -1],26expectedPrevTabStopVisibleColumn: [-1, 0, 0, -1],27expectedVisibleColumn: [0, 1, 2, -1],28},29{30lineContent: '\t',31tabSize: 4,32expectedPrevTabStopPosition: [-1, 0, -1],33expectedPrevTabStopVisibleColumn: [-1, 0, -1],34expectedVisibleColumn: [0, 4, -1],35},36{37lineContent: '\t ',38tabSize: 4,39expectedPrevTabStopPosition: [-1, 0, 1, -1],40expectedPrevTabStopVisibleColumn: [-1, 0, 4, -1],41expectedVisibleColumn: [0, 4, 5, -1],42},43{44lineContent: ' \t\t ',45tabSize: 4,46expectedPrevTabStopPosition: [-1, 0, 0, 2, 3, -1],47expectedPrevTabStopVisibleColumn: [-1, 0, 0, 4, 8, -1],48expectedVisibleColumn: [0, 1, 4, 8, 9, -1],49},50{51lineContent: ' \tA',52tabSize: 4,53expectedPrevTabStopPosition: [-1, 0, 0, -1, -1],54expectedPrevTabStopVisibleColumn: [-1, 0, 0, -1, -1],55expectedVisibleColumn: [0, 1, 4, -1, -1],56},57{58lineContent: 'A',59tabSize: 4,60expectedPrevTabStopPosition: [-1, -1, -1],61expectedPrevTabStopVisibleColumn: [-1, -1, -1],62expectedVisibleColumn: [0, -1, -1],63},64{65lineContent: '',66tabSize: 4,67expectedPrevTabStopPosition: [-1, -1],68expectedPrevTabStopVisibleColumn: [-1, -1],69expectedVisibleColumn: [0, -1],70},71];7273for (const testCase of testCases) {74const maxPosition = testCase.expectedVisibleColumn.length;75for (let position = 0; position < maxPosition; position++) {76const actual = AtomicTabMoveOperations.whitespaceVisibleColumn(testCase.lineContent, position, testCase.tabSize);77const expected = [78testCase.expectedPrevTabStopPosition[position],79testCase.expectedPrevTabStopVisibleColumn[position],80testCase.expectedVisibleColumn[position]81];82assert.deepStrictEqual(actual, expected);83}84}85});8687test('Test atomicPosition', () => {88const testCases = [89{90lineContent: ' ',91tabSize: 4,92expectedLeft: [-1, 0, 0, 0, 0, 4, 4, 4, 4, -1],93expectedRight: [4, 4, 4, 4, 8, 8, 8, 8, -1, -1],94expectedNearest: [0, 0, 0, 4, 4, 4, 4, 8, 8, -1],95},96{97lineContent: ' \t',98tabSize: 4,99expectedLeft: [-1, 0, 0, -1],100expectedRight: [2, 2, -1, -1],101expectedNearest: [0, 0, 2, -1],102},103{104lineContent: '\t ',105tabSize: 4,106expectedLeft: [-1, 0, -1, -1],107expectedRight: [1, -1, -1, -1],108expectedNearest: [0, 1, -1, -1],109},110{111lineContent: ' \t ',112tabSize: 4,113expectedLeft: [-1, 0, 0, -1, -1],114expectedRight: [2, 2, -1, -1, -1],115expectedNearest: [0, 0, 2, -1, -1],116},117{118lineContent: ' A',119tabSize: 4,120expectedLeft: [-1, 0, 0, 0, 0, 4, 4, 4, 4, -1, -1],121expectedRight: [4, 4, 4, 4, 8, 8, 8, 8, -1, -1, -1],122expectedNearest: [0, 0, 0, 4, 4, 4, 4, 8, 8, -1, -1],123},124{125lineContent: ' foo',126tabSize: 4,127expectedLeft: [-1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1],128expectedRight: [4, 4, 4, 4, -1, -1, -1, -1, -1, -1, -1],129expectedNearest: [0, 0, 0, 4, 4, -1, -1, -1, -1, -1, -1],130},131];132133for (const testCase of testCases) {134for (const { direction, expected } of [135{136direction: Direction.Left,137expected: testCase.expectedLeft,138},139{140direction: Direction.Right,141expected: testCase.expectedRight,142},143{144direction: Direction.Nearest,145expected: testCase.expectedNearest,146},147]) {148149const actual = expected.map((_, i) => AtomicTabMoveOperations.atomicPosition(testCase.lineContent, i, testCase.tabSize, direction));150assert.deepStrictEqual(actual, expected);151}152}153});154});155156157