<commit_before>"use strict";

import {TextEditor} from '../src/textEditor';
import * as vscode from "vscode";
import * as assert from 'assert';
import {join} from 'path';
import * as os from 'os';
import * as fs from 'fs';

function rndName() {
    return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
}

async function createRandomFile(contents: string): Promise<vscode.Uri> {
    const tmpFile = join(os.tmpdir(), rndName());

    try {
        await fs.writeFile(tmpFile, contents);
    } catch (error) {
        throw error;
    }

    return vscode.Uri.file(tmpFile);
}

export function assertEqualLines(expectedLines: string[]) {
    assert.equal(TextEditor.getLineCount(), expectedLines.length);

    for (let i = 0; i < expectedLines.length; i++) {
        assert.equal(TextEditor.readLineAt(i), expectedLines[i]);
    }
}

export async function setupWorkspace(): Promise<any> {
    const file   = await createRandomFile("");
    const doc    = await vscode.workspace.openTextDocument(file);

    await vscode.window.showTextDocument(doc);

    assert.ok(vscode.window.activeTextEditor);
}

export async function cleanUpWorkspace(): Promise<any> {
    // https://github.com/Microsoft/vscode/blob/master/extensions/vscode-api-tests/src/utils.ts
    return new Promise((c, e) => {
        if (vscode.window.visibleTextEditors.length === 0) {
            return c();
        }<commit_msg>Wait for test file to get written<commit_after>"use strict";

import {TextEditor} from '../src/textEditor';
import * as vscode from "vscode";
import * as assert from 'assert';
import {join} from 'path';
import * as os from 'os';
import * as fs from 'fs';

function rndName() {
    return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
}

async function createRandomFile(contents: string): Promise<vscode.Uri> {
    const tmpFile = join(os.tmpdir(), rndName());
    
    try {
        fs.writeFileSync(tmpFile, contents);
        return vscode.Uri.file(tmpFile);
    } catch (error) {
        throw error;
    }
}

export function assertEqualLines(expectedLines: string[]) {
    assert.equal(TextEditor.getLineCount(), expectedLines.length);

    for (let i = 0; i < expectedLines.length; i++) {
        assert.equal(TextEditor.readLineAt(i), expectedLines[i]);
    }
}

export async function setupWorkspace(): Promise<any> {
    const file   = await createRandomFile("");
    const doc    = await vscode.workspace.openTextDocument(file);

    await vscode.window.showTextDocument(doc);

    assert.ok(vscode.window.activeTextEditor);
}

export async function cleanUpWorkspace(): Promise<any> {
    // https://github.com/Microsoft/vscode/blob/master/extensions/vscode-api-tests/src/utils.ts
    return new Promise((c, e) => {
        if (vscode.window.visibleTextEditors.length === 0) {
            return c();
        }
{'fraction_non_alphanumeric': 0.14731673097158893, 'fraction_numerical': 0.004910557699052964, 'mean_word_length': 3.5632, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4778532', 'n_tokens_mistral': 911, 'n_tokens_neox': 898, 'n_words': 207}