mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 17:23:19 -05:00
Implemented match case and whole wrd (#8904)
* Implemented match case and whole wrd * removed unused ref * renamed test method * escape \ * refactored search * added more tests * updated tests appying match case and whole word to spcl characters * regex update * spcl to special * non-capturing group added to the regex * test
This commit is contained in:
@@ -32,12 +32,12 @@ import { NotebookEditorContentManager } from 'sql/workbench/contrib/notebook/bro
|
||||
let expectedNotebookContent: nb.INotebookContents = {
|
||||
cells: [{
|
||||
cell_type: CellTypes.Code,
|
||||
source: 'insert into t1 values (c1, c2) \ninsert into markdown values (*hello worls*)',
|
||||
source: ['insert into t1 values (c1, c2) ', 'INSERT into markdown values (*hello world*)'],
|
||||
metadata: { language: 'python' },
|
||||
execution_count: 1
|
||||
}, {
|
||||
cell_type: CellTypes.Markdown,
|
||||
source: 'I am *markdown*',
|
||||
source: ['I am *markdown insertImportant*'],
|
||||
metadata: { language: 'python' },
|
||||
execution_count: 1
|
||||
}],
|
||||
@@ -110,23 +110,23 @@ suite('Notebook Find Model', function (): void {
|
||||
test('Should find results in the notebook', async function (): Promise<void> {
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('markdown', max_find_count);
|
||||
await notebookFindModel.find('markdown', false, false, max_find_count);
|
||||
|
||||
assert(notebookFindModel.findMatches, new Error('Find in notebook failed.'));
|
||||
assert(notebookFindModel.findMatches, 'Find in notebook failed.');
|
||||
assert.equal(notebookFindModel.findMatches.length, 2, 'Find couldnt find all occurances');
|
||||
});
|
||||
|
||||
test('Should not find results in the notebook', async function (): Promise<void> {
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('notFound', max_find_count);
|
||||
await notebookFindModel.find('notFound', false, false, max_find_count);
|
||||
|
||||
assert.equal(notebookFindModel.findMatches.length, 0, 'Find failed');
|
||||
});
|
||||
|
||||
test('Should match find result ranges', async function (): Promise<void> {
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('markdown', max_find_count);
|
||||
await notebookFindModel.find('markdown', false, false, max_find_count);
|
||||
|
||||
let expectedFindRange1 = new NotebookRange(model.cells[0], 2, 13, 2, 21);
|
||||
assert.deepEqual(notebookFindModel.findMatches[0].range, expectedFindRange1, 'Find in markdown range is wrong :\n' + JSON.stringify(expectedFindRange1) + '\n ' + JSON.stringify(notebookFindModel.findMatches[0].range));
|
||||
@@ -155,7 +155,7 @@ suite('Notebook Find Model', function (): void {
|
||||
await initNotebookModel(markdownContent);
|
||||
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('best', max_find_count);
|
||||
await notebookFindModel.find('best', false, false, max_find_count);
|
||||
|
||||
assert.equal(notebookFindModel.findMatches.length, 1, 'Find failed on markdown link');
|
||||
|
||||
@@ -184,11 +184,97 @@ suite('Notebook Find Model', function (): void {
|
||||
await initNotebookModel(codeContent);
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('x', max_find_count);
|
||||
await notebookFindModel.find('x', false, false, max_find_count);
|
||||
|
||||
assert.equal(notebookFindModel.findMatches.length, 3, 'Find failed');
|
||||
});
|
||||
|
||||
test('Should find results correctly with & without matching case selection', async function (): Promise<void> {
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('insert', false, false, max_find_count);
|
||||
|
||||
assert(notebookFindModel.findMatches, 'Find in notebook failed.');
|
||||
assert.equal(notebookFindModel.findMatches.length, 3, 'Find couldnt find all occurances');
|
||||
|
||||
await notebookFindModel.find('insert', true, false, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 2, 'Find failed to apply match case while searching');
|
||||
|
||||
});
|
||||
|
||||
test('Should find results with matching whole word in the notebook', async function (): Promise<void> {
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
|
||||
await notebookFindModel.find('insert', true, true, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 1, 'Find failed to apply whole word filter while searching');
|
||||
|
||||
});
|
||||
|
||||
test('Should find special characters in the search term without problems', async function (): Promise<void> {
|
||||
let codeContent: nb.INotebookContents = {
|
||||
cells: [{
|
||||
cell_type: CellTypes.Code,
|
||||
source: ['import x', 'x.init()', '//am just adding a bunch of {special} <characters> !!!!$}'],
|
||||
metadata: { language: 'python' },
|
||||
execution_count: 1
|
||||
}],
|
||||
metadata: {
|
||||
kernelspec: {
|
||||
name: 'python',
|
||||
language: 'python'
|
||||
}
|
||||
},
|
||||
nbformat: 4,
|
||||
nbformat_minor: 5
|
||||
};
|
||||
await initNotebookModel(codeContent);
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
// test for string with special character
|
||||
await notebookFindModel.find('{special}', true, true, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 1, 'Find failed for search term with special character');
|
||||
// test for only special character !!
|
||||
await notebookFindModel.find('!!', false, false, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 2, 'Find failed for special character');
|
||||
|
||||
// test for only special character combination
|
||||
await notebookFindModel.find('!!!$}', false, false, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 1, 'Find failed for special character combination');
|
||||
});
|
||||
|
||||
test('Should find // characters in the search term correctly', async function (): Promise<void> {
|
||||
let codeContent: nb.INotebookContents = {
|
||||
cells: [{
|
||||
cell_type: CellTypes.Code,
|
||||
source: ['import x', 'x.init()', '//am just adding a bunch of {special} <characters> !test$}'],
|
||||
metadata: { language: 'python' },
|
||||
execution_count: 1
|
||||
}],
|
||||
metadata: {
|
||||
kernelspec: {
|
||||
name: 'python',
|
||||
language: 'python'
|
||||
}
|
||||
},
|
||||
nbformat: 4,
|
||||
nbformat_minor: 5
|
||||
};
|
||||
await initNotebookModel(codeContent);
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
|
||||
await notebookFindModel.find('/', true, false, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 2, 'Find failed to find number of / occurrences');
|
||||
|
||||
await notebookFindModel.find('//', true, false, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 1, 'Find failed to find number of // occurrences');
|
||||
|
||||
await notebookFindModel.find('//', true, true, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 0, 'Find failed to apply match whole word for //');
|
||||
});
|
||||
|
||||
|
||||
async function initNotebookModel(contents: nb.INotebookContents): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(contents));
|
||||
@@ -200,4 +286,3 @@ suite('Notebook Find Model', function (): void {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ export class NotebookFindModelStub implements INotebookFindModel {
|
||||
findPrevious(): Promise<NotebookRange> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
find(exp: string, maxMatches?: number): Promise<NotebookRange> {
|
||||
find(exp: string, matchCase?: boolean, wholeWord?: boolean, maxMatches?: number): Promise<NotebookRange> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
clearFind(): void {
|
||||
|
||||
Reference in New Issue
Block a user