/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import 'mocha'; import * as assert from 'assert'; import { Selection } from 'vscode'; import { withRandomFileEditor, closeAllEditors } from './testUtils'; import { fetchEditPoint } from '../editPoint'; import { fetchSelectItem } from '../selectItem'; import { balanceOut, balanceIn } from '../balance'; suite('Tests for Next/Previous Select/Edit point and Balance actions', () => { teardown(closeAllEditors); const cssContents = ` .boo { margin: 20px 10px; background-image: url('tryme.png'); } .boo .hoo { margin: 10px; } `; const scssContents = ` .boo { margin: 20px 10px; background-image: url('tryme.png'); .boo .hoo { margin: 10px; } } `; const htmlContents = `
\t\t
`; test('Emmet Next/Prev Edit point in html file', function (): any { return withRandomFileEditor(htmlContents, '.html', (editor, _) => { editor.selections = [new Selection(1, 5, 1, 5)]; let expectedNextEditPoints: [number, number][] = [[4, 16], [6, 8], [10, 2], [10, 2]]; expectedNextEditPoints.forEach(([line, col]) => { fetchEditPoint('next'); testSelection(editor.selection, col, line); }); let expectedPrevEditPoints = [[6, 8], [4, 16], [4, 16]]; expectedPrevEditPoints.forEach(([line, col]) => { fetchEditPoint('prev'); testSelection(editor.selection, col, line); }); return Promise.resolve(); }); }); test('Emmet Select Next/Prev Item in html file', function (): any { return withRandomFileEditor(htmlContents, '.html', (editor, _) => { editor.selections = [new Selection(2, 2, 2, 2)]; let expectedNextItemPoints: [number, number, number][] = [ [2, 1, 5], // html [2, 6, 15], // lang="en" [2, 12, 14], // en [3, 1, 5], // head [4, 2, 6], // meta [4, 7, 17], // charset="" [5, 2, 6], // meta [5, 7, 22], // name="viewport" [5, 13, 21], // viewport [5, 23, 70], // content="width=device-width, initial-scale=1.0" [5, 32, 69], // width=device-width, initial-scale=1.0 [5, 32, 51], // width=device-width, [5, 52, 69], // initial-scale=1.0 [6, 2, 7] // title ]; expectedNextItemPoints.forEach(([line, colstart, colend]) => { fetchSelectItem('next'); testSelection(editor.selection, colstart, line, colend); }); editor.selections = [new Selection(6, 15, 6, 15)]; expectedNextItemPoints.reverse().forEach(([line, colstart, colend]) => { fetchSelectItem('prev'); testSelection(editor.selection, colstart, line, colend); }); return Promise.resolve(); }); }); test('Emmet Select Next/Prev item at boundary', function (): any { return withRandomFileEditor(htmlContents, '.html', (editor, _) => { editor.selections = [new Selection(4, 1, 4, 1)]; fetchSelectItem('next'); testSelection(editor.selection, 2, 4, 6); editor.selections = [new Selection(4, 1, 4, 1)]; fetchSelectItem('prev'); testSelection(editor.selection, 1, 3, 5); return Promise.resolve(); }); }); test('Emmet Next/Prev Item in html template', function (): any { const templateContents = ` `; return withRandomFileEditor(templateContents, '.html', (editor, _) => { editor.selections = [new Selection(2, 2, 2, 2)]; let expectedNextItemPoints: [number, number, number][] = [ [2, 2, 5], // div [2, 6, 20], // class="header" [2, 13, 19], // header [3, 3, 5], // ul [3, 6, 22], // class="nav main" [3, 13, 21], // nav main [3, 13, 16], // nav [3, 17, 21], // main ]; expectedNextItemPoints.forEach(([line, colstart, colend]) => { fetchSelectItem('next'); testSelection(editor.selection, colstart, line, colend); }); editor.selections = [new Selection(4, 1, 4, 1)]; expectedNextItemPoints.reverse().forEach(([line, colstart, colend]) => { fetchSelectItem('prev'); testSelection(editor.selection, colstart, line, colend); }); return Promise.resolve(); }); }); test('Emmet Select Next/Prev Item in css file', function (): any { return withRandomFileEditor(cssContents, '.css', (editor, _) => { editor.selections = [new Selection(0, 0, 0, 0)]; let expectedNextItemPoints: [number, number, number][] = [ [1, 0, 4], // .boo [2, 1, 19], // margin: 20px 10px; [2, 9, 18], // 20px 10px [2, 9, 13], // 20px [2, 14, 18], // 10px [3, 1, 36], // background-image: url('tryme.png'); [3, 19, 35], // url('tryme.png') [6, 0, 9], // .boo .hoo [7, 1, 14], // margin: 10px; [7, 9, 13], // 10px ]; expectedNextItemPoints.forEach(([line, colstart, colend]) => { fetchSelectItem('next'); testSelection(editor.selection, colstart, line, colend); }); editor.selections = [new Selection(9, 0, 9, 0)]; expectedNextItemPoints.reverse().forEach(([line, colstart, colend]) => { fetchSelectItem('prev'); testSelection(editor.selection, colstart, line, colend); }); return Promise.resolve(); }); }); test('Emmet Select Next/Prev Item in scss file with nested rules', function (): any { return withRandomFileEditor(scssContents, '.scss', (editor, _) => { editor.selections = [new Selection(0, 0, 0, 0)]; let expectedNextItemPoints: [number, number, number][] = [ [1, 0, 4], // .boo [2, 1, 19], // margin: 20px 10px; [2, 9, 18], // 20px 10px [2, 9, 13], // 20px [2, 14, 18], // 10px [3, 1, 36], // background-image: url('tryme.png'); [3, 19, 35], // url('tryme.png') [5, 1, 10], // .boo .hoo [6, 2, 15], // margin: 10px; [6, 10, 14], // 10px ]; expectedNextItemPoints.forEach(([line, colstart, colend]) => { fetchSelectItem('next'); testSelection(editor.selection, colstart, line, colend); }); editor.selections = [new Selection(8, 0, 8, 0)]; expectedNextItemPoints.reverse().forEach(([line, colstart, colend]) => { fetchSelectItem('prev'); testSelection(editor.selection, colstart, line, colend); }); return Promise.resolve(); }); }); test('Emmet Balance Out in html file', function (): any { return withRandomFileEditor(htmlContents, 'html', (editor, _) => { editor.selections = [new Selection(14, 6, 14, 10)]; let expectedBalanceOutRanges: [number, number, number, number][] = [ [14, 3, 14, 32], //
  • Item 1
  • [13, 23, 16, 2], // inner contents of