Skip to content

Commit

Permalink
whatever
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila committed Jan 30, 2025
1 parent f9a2e3f commit 012a377
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/test/suite/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ suite('EditorConfig extension', function () {
})

test('keep selection on format', async () => {
await withSetting('insert_final_newline', 'true').saveText('foobar')
await withSetting('insert_final_newline', 'true', {
fileName: 'test-selection',
}).saveText('foobar')
assert(window.activeTextEditor, 'no active editor')

assert.strictEqual(
Expand All @@ -307,15 +309,16 @@ function withSetting(
value: string,
options: {
contents?: string
fileName?: string
} = {},
) {
return {
async getText() {
return (await createDoc(options.contents)).getText()
return (await createDoc(options.contents, options.fileName)).getText()
},
saveText(text: string) {
return new Promise<string>(async resolve => {
const doc = await createDoc(options.contents)
const doc = await createDoc(options.contents, options.fileName)
workspace.onDidChangeTextDocument(doc.save)
workspace.onDidSaveTextDocument(savedDoc => {
assert.strictEqual(savedDoc.isDirty, false, 'dirty saved doc')
Expand All @@ -331,20 +334,14 @@ function withSetting(
})
},
}
async function createDoc(contents = '') {
async function createDoc(contents = '', name = 'test') {
const uri = await utils.createFile(
contents,
generateFixturePath().next().value,
getFixturePath([rule, value, name]),
)
const doc = await workspace.openTextDocument(uri)
await window.showTextDocument(doc)
await wait(50) // wait for EditorConfig to apply new settings
return doc
}
function* generateFixturePath(): Generator<string> {
let index = 0
while (true) {
yield getFixturePath([rule, value, `${test}-${index++}`])
}
}
}

0 comments on commit 012a377

Please sign in to comment.