Skip to content

Commit

Permalink
Add command test
Browse files Browse the repository at this point in the history
  • Loading branch information
neild3r committed Jan 12, 2019
1 parent 985e65f commit ecdf581
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ export function activate(context: vscode.ExtensionContext)
vscode.languages.registerCompletionItemProvider(lang, new Completions(), '*', '@');
});

vscode.commands.registerTextEditorCommand('php-docblocker.trigger', (textEditor:vscode.TextEditor) => {
vscode.commands.registerTextEditorCommand('php-docblocker.trigger', (textEditor:vscode.TextEditor, edit:vscode.TextEditorEdit, callback:any) => {
textEditor.selection = new vscode.Selection(textEditor.selection.start, textEditor.selection.start);
let range = new vscode.Range(textEditor.selection.start, textEditor.selection.end);
let documenter = new Documenter(range, textEditor);
textEditor.insertSnippet(documenter.autoDocument());
let snippet = documenter.autoDocument();
textEditor.insertSnippet(snippet);

if (callback) {
callback(snippet);
}
});
}

Expand Down
6 changes: 3 additions & 3 deletions test/class.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import {TextEditor, TextDocument} from 'vscode';
import Helper from './helpers';
import Function from '../src/block/class';
import Class from '../src/block/class';
import {Doc, Param} from '../src/doc';

suite("Class tests", () => {
Expand All @@ -22,12 +22,12 @@ suite("Class tests", () => {

map.forEach(testData => {
test("Match Test: "+ testData.name, () => {
let func = new Function(testPositions[testData.key], editor);
let func = new Class(testPositions[testData.key], editor);
assert.equal(func.test(), true, test.name);
});

test("Parse Test: "+ testData.name, () => {
let func = new Function(testPositions[testData.key], editor);
let func = new Class(testPositions[testData.key], editor);
assert.ok(func.parse(), test.name);
});
});
Expand Down
23 changes: 23 additions & 0 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as assert from 'assert';
import {TextEditor, TextDocument, commands, Selection} from 'vscode';
import Helper from './helpers';

suite("Command tests", () => {
let editor:TextEditor;
let document:TextDocument;

suiteSetup(function(done) {
Helper.loadFixture('commands.php', (edit:TextEditor, doc:TextDocument) => {
editor = edit;
document = doc;
done();
});
});

test("Command: trigger", () => {
editor.selection = new Selection(3, 0, 3, 0);
assert.doesNotThrow(async () => {
await commands.executeCommand('php-docblocker.trigger', editor)
});
});
});
6 changes: 6 additions & 0 deletions test/fixtures/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php


class Trigger
{
}

0 comments on commit ecdf581

Please sign in to comment.