mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
update to new testing api
This commit is contained in:
29
test-provider-sample/src/parser.ts
Normal file
29
test-provider-sample/src/parser.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const testRe = /^([0-9]+)\s*([+*/-])\s*([0-9]+)\s*=\s*([0-9]+)/;
|
||||
const headingRe = /^(#+)\s*(.+)$/;
|
||||
|
||||
export const parseMarkdown = (text: string, events: {
|
||||
onTest(range: vscode.Range, a: number, operator: string, b: number, expected: number): void;
|
||||
onHeading(range: vscode.Range, name: string, depth: number): void;
|
||||
}) => {
|
||||
const lines = text.split('\n');
|
||||
|
||||
for (let lineNo = 0; lineNo < lines.length; lineNo++) {
|
||||
const line = lines[lineNo];
|
||||
const test = testRe.exec(line);
|
||||
if (test) {
|
||||
const [, a, operator, b, expected] = test;
|
||||
const range = new vscode.Range(new vscode.Position(lineNo, 0), new vscode.Position(lineNo, test[0].length));
|
||||
events.onTest(range, Number(a), operator, Number(b), Number(expected));
|
||||
continue;
|
||||
}
|
||||
|
||||
const heading = headingRe.exec(line);
|
||||
if (heading) {
|
||||
const [, pounds, name] = heading;
|
||||
const range = new vscode.Range(new vscode.Position(lineNo, 0), new vscode.Position(lineNo, line.length));
|
||||
events.onHeading(range, name, Number(pounds));
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user