mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 07:28:08 +03:00
Verify Buffer-modifying methods on Selection
This commit is contained in:
parent
56a3f1bc41
commit
cf576a0a7e
@ -154,4 +154,118 @@ describe('Selection', () => {
|
||||
expect(editor.isFoldedAtBufferRow(0)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('within a read-only editor', () => {
|
||||
beforeEach(() => {
|
||||
editor.setReadOnly(true)
|
||||
selection.setBufferRange([[0, 0], [0, 13]])
|
||||
})
|
||||
|
||||
const modifications = [
|
||||
{
|
||||
name: 'insertText',
|
||||
op: opts => selection.insertText('yes', opts)
|
||||
},
|
||||
{
|
||||
name: 'backspace',
|
||||
op: opts => selection.backspace(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteToPreviousWordBoundary',
|
||||
op: opts => selection.deleteToPreviousWordBoundary(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteToNextWordBoundary',
|
||||
op: opts => selection.deleteToNextWordBoundary(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteToBeginningOfWord',
|
||||
op: opts => selection.deleteToBeginningOfWord(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteToBeginningOfLine',
|
||||
op: opts => selection.deleteToBeginningOfLine(opts)
|
||||
},
|
||||
{
|
||||
name: 'delete',
|
||||
op: opts => selection.delete(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteToEndOfLine',
|
||||
op: opts => selection.deleteToEndOfLine(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteToEndOfWord',
|
||||
op: opts => selection.deleteToEndOfWord(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteToBeginningOfSubword',
|
||||
op: opts => selection.deleteToBeginningOfSubword(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteToEndOfSubword',
|
||||
op: opts => selection.deleteToEndOfSubword(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteSelectedText',
|
||||
op: opts => selection.deleteSelectedText(opts)
|
||||
},
|
||||
{
|
||||
name: 'deleteLine',
|
||||
op: opts => selection.deleteLine(opts)
|
||||
},
|
||||
{
|
||||
name: 'joinLines',
|
||||
op: opts => selection.joinLines(opts)
|
||||
},
|
||||
{
|
||||
name: 'outdentSelectedRows',
|
||||
op: opts => selection.outdentSelectedRows(opts)
|
||||
},
|
||||
{
|
||||
name: 'autoIndentSelectedRows',
|
||||
op: opts => selection.autoIndentSelectedRows(opts)
|
||||
},
|
||||
{
|
||||
name: 'toggleLineComments',
|
||||
op: opts => selection.toggleLineComments(opts)
|
||||
},
|
||||
{
|
||||
name: 'cutToEndOfLine',
|
||||
op: opts => selection.cutToEndOfLine(false, opts)
|
||||
},
|
||||
{
|
||||
name: 'cutToEndOfBufferLine',
|
||||
op: opts => selection.cutToEndOfBufferLine(false, opts)
|
||||
},
|
||||
{
|
||||
name: 'cut',
|
||||
op: opts => selection.cut(false, false, opts.bypassReadOnly)
|
||||
},
|
||||
{
|
||||
name: 'indent',
|
||||
op: opts => selection.indent(opts)
|
||||
},
|
||||
{
|
||||
name: 'indentSelectedRows',
|
||||
op: opts => selection.indentSelectedRows(opts)
|
||||
},
|
||||
]
|
||||
|
||||
describe('without bypassReadOnly', () => {
|
||||
for (const {name, op} of modifications) {
|
||||
it(`throws an error on ${name}`, () => {
|
||||
expect(op).toThrow()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe('with bypassReadOnly', () => {
|
||||
for (const {name, op} of modifications) {
|
||||
it(`permits ${name}`, () => {
|
||||
op({bypassReadOnly: true})
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user