<commit_before>/// <reference path="../../../globals.ts" />
/// <reference path="../../../tsdHelper.ts" />

describe('CLI Query', () => {
	'use strict';

	var fs = require('fs');
	var FS = require('q-io/fs');
	var path = require('path');
	var assert:Chai.Assert = require('chai').assert;

	function applyTestInfo(group:string, name:string, test:any, createConfigFile:boolean = false):helper.TestInfo {
		var info = new helper.TestInfo(group, name, test, createConfigFile);

		xm.file.writeJSONSync(info.testDump, test);

		return info;
	}

	function getArgs(test, data, info:helper.TestInfo):string[] {
		assert.isObject(test, 'test');
		assert.isObject(data, 'data');
		assert.instanceOf(info, helper.TestInfo, 'info');

		var args:string[] = [];

		if (test.command) {
			assert.isArray(test.command, 'test.command');
			args.push.apply(args, test.command);
		}
		else if (data.command) {
			assert.isArray(data.command, 'data.command');
			args.push.apply(args, data.command);
		}

		if (test.query) {
			if (test.query.pattern) {
				args.push(test.query.pattern);
			}
			if (test.query.overwrite) {
				args.push('--overwrite');
			}
			if (test.query.resolve) {
				args.push('--resolve');
			}
			if (test.query.save) {
				args.push('--save');
			}
		}

		if (test.style) {
			args.push('--style', test.style);
		}
		else {
			args.push('--style', 'plain');
		}

		args.push('--progress', 'no');
		args.push('--services', 'no');
		args.push('--cacheMode', xm.http.CacheMode[helper.settings.cache]);

		args.push('--cacheDir', info.cacheDirTestFixed);
		args.push('--config', path.resolve('./test/fixtures/config/default.json'));

		// TODO also write a .bat/.cmd and a shell script; with absolute paths etc (for lazy re-run)
		xm.file.writeJSONSync(info.argsDump, {list: args, flat: args.join(' ')});

		return args;
	}

	var trimHeaderExp = /^[.\s]*?(-> tsd.*)\s+?-*\s*/;
	var versionNumber = /(\d+-alpha.\d+)/;

	function trimHeader(str:string):string {
		return str.replace(trimHeaderExp, '').replace(versionNumber, 'x');
	}

	function assertCLIResult(result:xm.RunCLIResult, test, info:helper.TestInfo, args):void {<commit_msg>fixed version RegExp in test<commit_after>/// <reference path="../../../globals.ts" />
/// <reference path="../../../tsdHelper.ts" />

describe('CLI Query', () => {
	'use strict';

	var fs = require('fs');
	var FS = require('q-io/fs');
	var path = require('path');
	var assert:Chai.Assert = require('chai').assert;

	function applyTestInfo(group:string, name:string, test:any, createConfigFile:boolean = false):helper.TestInfo {
		var info = new helper.TestInfo(group, name, test, createConfigFile);

		xm.file.writeJSONSync(info.testDump, test);

		return info;
	}

	function getArgs(test, data, info:helper.TestInfo):string[] {
		assert.isObject(test, 'test');
		assert.isObject(data, 'data');
		assert.instanceOf(info, helper.TestInfo, 'info');

		var args:string[] = [];

		if (test.command) {
			assert.isArray(test.command, 'test.command');
			args.push.apply(args, test.command);
		}
		else if (data.command) {
			assert.isArray(data.command, 'data.command');
			args.push.apply(args, data.command);
		}

		if (test.query) {
			if (test.query.pattern) {
				args.push(test.query.pattern);
			}
			if (test.query.overwrite) {
				args.push('--overwrite');
			}
			if (test.query.resolve) {
				args.push('--resolve');
			}
			if (test.query.save) {
				args.push('--save');
			}
		}

		if (test.style) {
			args.push('--style', test.style);
		}
		else {
			args.push('--style', 'plain');
		}

		args.push('--progress', 'no');
		args.push('--services', 'no');
		args.push('--cacheMode', xm.http.CacheMode[helper.settings.cache]);

		args.push('--cacheDir', info.cacheDirTestFixed);
		args.push('--config', path.resolve('./test/fixtures/config/default.json'));

		// TODO also write a .bat/.cmd and a shell script; with absolute paths etc (for lazy re-run)
		xm.file.writeJSONSync(info.argsDump, {list: args, flat: args.join(' ')});

		return args;
	}

	var trimHeaderExp = /^[.\s]*?(-> tsd.*)\s+?-*\s*/;
	var versionNumber = /(\d+-[a-z]+.\d+)/;

	function trimHeader(str:string):string {
		return str.replace(trimHeaderExp, '').replace(versionNumber, 'x');
	}

	function assertCLIResult(result:xm.RunCLIResult, test, info:helper.TestInfo, args):void {
{'fraction_non_alphanumeric': 0.20670391061452514, 'fraction_numerical': 0.0, 'mean_word_length': 3.640388768898488, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '5909511', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1507, 'n_words': 276}