Skip to content

Commit

Permalink
index reusable docs by language to avoid creating superfluous tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonatwork committed Jan 28, 2020
1 parent dbb22d6 commit 166a24e
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions test/Framework/BlackBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const extractInfo = (originalText: string) => {
};
};

let reusableDocument: TextDocument;
const reusableDocuments: Map<string, TextDocument> = new Map();

export const run = (testCase: TestCase, before?: (textEditor: TextEditor) => void) => {
const plainFrom = testCase.from.replace(/\n/g, '\\n');
Expand All @@ -107,41 +107,44 @@ export const run = (testCase: TestCase, before?: (textEditor: TextEditor) => voi
test(expectation, (done) => {
tries++;

const language = testCase.language || 'plaintext';
const fromInfo = extractInfo(testCase.from);
const toInfo = extractInfo(testCase.to);
const inputs = testCase.inputs.split(' ');

TestUtil.createTempDocument(fromInfo.cleanText, reusableDocument, testCase.language).then(
async (textEditor) => {
reusableDocument = textEditor.document;
TestUtil.createTempDocument(
fromInfo.cleanText,
reusableDocuments.get(language),
language,
).then(async (textEditor) => {
reusableDocuments.set(textEditor.document.languageId, textEditor.document);

if (before) {
before(textEditor);
}

TestUtil.setSelections(fromInfo.selections);
if (before) {
before(textEditor);
}

await waitForMillisecond(50 * tries);

for (let i = 0; i < inputs.length; i++) {
getCurrentMode()!.input(inputs[i]);
await waitForMillisecond(20 * tries);
}
TestUtil.setSelections(fromInfo.selections);

if (testCase.language) {
await waitForMillisecond(50 * tries);
}
await waitForMillisecond(50 * tries);

try {
assert.equal(TestUtil.getDocument()!.getText(), toInfo.cleanText);
assert.deepEqual(TestUtil.getSelections(), toInfo.selections);
} catch (error) {
done(error);
return;
}
for (let i = 0; i < inputs.length; i++) {
getCurrentMode()!.input(inputs[i]);
await waitForMillisecond(20 * tries);
}

done();
},
);
if (language !== 'plaintext') {
await waitForMillisecond(50 * tries);
}

try {
assert.equal(TestUtil.getDocument()!.getText(), toInfo.cleanText);
assert.deepEqual(TestUtil.getSelections(), toInfo.selections);
} catch (error) {
done(error);
return;
}

done();
});
});
};

0 comments on commit 166a24e

Please sign in to comment.