<commit_before>import * as Ajv from "ajv";
import { assert } from "chai";
import { readFileSync } from "fs";
import { resolve } from "path";

import * as TJS from "../typescript-json-schema";

const ajv = new Ajv();
const metaSchema = require("ajv/lib/refs/json-schema-draft-06.json");
ajv.addMetaSchema(metaSchema);

const BASE = "test/programs/";

export function assertSchema(group: string, type: string, settings: TJS.PartialArgs = {}, compilerOptions?: TJS.CompilerOptions, only?: boolean) {
    const run = only ? it.only : it;

    run(group + " should create correct schema", () => {
        if (!("required" in settings)) {
            settings.required = true;
        }

        const files = [resolve(BASE + group + "/main.ts")];
        const actual = TJS.generateSchema(TJS.getProgramFromFiles(files, compilerOptions), type, settings, files);

        // writeFileSync(BASE + group + "/schema.json", stringify(actual, {space: 4}) + "\n\n");

        const file = readFileSync(BASE + group + "/schema.json", "utf8");
        const expected = JSON.parse(file);

        assert.isObject(actual);
        assert.deepEqual(actual, expected, "The schema is not as expected");

        // test against the meta schema
        if (actual !== null) {
            ajv.validateSchema(actual);
            console.warn(ajv.errors);
            assert.equal(ajv.errors, null, "The schema is not valid");
        }
    });
}<commit_msg>Remove console.warn<commit_after>import * as Ajv from "ajv";
import { assert } from "chai";
import { readFileSync } from "fs";
import { resolve } from "path";

import * as TJS from "../typescript-json-schema";

const ajv = new Ajv();
const metaSchema = require("ajv/lib/refs/json-schema-draft-06.json");
ajv.addMetaSchema(metaSchema);

const BASE = "test/programs/";

export function assertSchema(group: string, type: string, settings: TJS.PartialArgs = {}, compilerOptions?: TJS.CompilerOptions, only?: boolean) {
    const run = only ? it.only : it;

    run(group + " should create correct schema", () => {
        if (!("required" in settings)) {
            settings.required = true;
        }

        const files = [resolve(BASE + group + "/main.ts")];
        const actual = TJS.generateSchema(TJS.getProgramFromFiles(files, compilerOptions), type, settings, files);

        // writeFileSync(BASE + group + "/schema.json", stringify(actual, {space: 4}) + "\n\n");

        const file = readFileSync(BASE + group + "/schema.json", "utf8");
        const expected = JSON.parse(file);

        assert.isObject(actual);
        assert.deepEqual(actual, expected, "The schema is not as expected");

        // test against the meta schema
        if (actual !== null) {
            ajv.validateSchema(actual);
            assert.equal(ajv.errors, null, "The schema is not valid");
        }
    });
}
{'fraction_non_alphanumeric': 0.14788732394366197, 'fraction_numerical': 0.0028169014084507044, 'mean_word_length': 2.967877094972067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '6497208', 'n_tokens_mistral': 849, 'n_tokens_neox': 825, 'n_words': 230}