<commit_before>'use strict';

var assert = require('assert');
var recast = require('recast');

function AssertionMessage(actual, expected) {
	this.actual = recast.print(actual).code;
	this.expected = recast.print(expected).code;
	this.prefix = '';
	this.infix = 'is';
	this.suffix = '';

	if (actual.type === 'CallExpression') {
		this.infix = 'returns';
	}

	if (actual.type === 'MemberExpression' || actual.type === 'Identifier') {
		this.prefix = 'The value of';
	}

	if (actual.type === 'BinaryExpression' || actual.type === 'UpdateExpression') {
		this.prefix = 'The result of';
	}
}

AssertionMessage.wrap = function(target, prefix, suffix) {
	if (!suffix) {
		suffix = prefix;
	}

	return prefix + target + suffix;
};

AssertionMessage.code = function(target) {
	return AssertionMessage.wrap(target, "`");
};

AssertionMessage.prototype.toString = function() {
	return [
		this.prefix,
		AssertionMessage.code(this.actual),
		this.infix,
		AssertionMessage.code(this.expected),
		this.suffix
	].join(' ').trim();
};

var messages = {
	assert: function(path) {

		if (path.parentPath.value.type !== 'CallExpression') {
			return;
		}

		// Special case: assert(false)
		if (path.parentPath.value.type === 'CallExpression' &&
				(path.parentPath.value.callee.name === 'assert' &&
					path.parentPath.value.arguments.length === 1 &&
					path.parentPath.value.arguments[0].type === 'Literal' &&
					path.parentPath.value.arguments[0].value === false)) {


			var args = path.parentPath.value.arguments;

			// This will intentionally create messages that cause errors
			// to hopefully prevent them from being missed during review.
			args[0] = '!REVIEW!';
			path.value.name = '$ERROR';

			return;
		}

		var args = path.parentPath.value.arguments;
		var message = new AssertionMessage(args[0], recast.types.builders.literal(true));

		args[1] = recast.types.builders.literal(message.toString());
	},
	sameValue: function(path) {

		var args = path.parentPath.parentPath.value.arguments;
		var message = new AssertionMessage(args[0], args[1]);

		args[2] = recast.types.builders.literal(message.toString());
	},
};

module.exports = function(ast) {<commit_msg>Keep previously-existing assertion messages<commit_after>'use strict';

var assert = require('assert');
var recast = require('recast');

function AssertionMessage(actual, expected) {
	this.actual = recast.print(actual).code;
	this.expected = recast.print(expected).code;
	this.prefix = '';
	this.infix = 'is';
	this.suffix = '';

	if (actual.type === 'CallExpression') {
		this.infix = 'returns';
	}

	if (actual.type === 'MemberExpression' || actual.type === 'Identifier') {
		this.prefix = 'The value of';
	}

	if (actual.type === 'BinaryExpression' || actual.type === 'UpdateExpression') {
		this.prefix = 'The result of';
	}
}

AssertionMessage.wrap = function(target, prefix, suffix) {
	if (!suffix) {
		suffix = prefix;
	}

	return prefix + target + suffix;
};

AssertionMessage.code = function(target) {
	return AssertionMessage.wrap(target, "`");
};

AssertionMessage.prototype.toString = function() {
	return [
		this.prefix,
		AssertionMessage.code(this.actual),
		this.infix,
		AssertionMessage.code(this.expected),
		this.suffix
	].join(' ').trim();
};

var messages = {
	assert: function(path) {

		if (path.parentPath.value.type !== 'CallExpression') {
			return;
		}

		// Special case: assert(false)
		if (path.parentPath.value.type === 'CallExpression' &&
				(path.parentPath.value.callee.name === 'assert' &&
					path.parentPath.value.arguments.length === 1 &&
					path.parentPath.value.arguments[0].type === 'Literal' &&
					path.parentPath.value.arguments[0].value === false)) {


			var args = path.parentPath.value.arguments;

			// This will intentionally create messages that cause errors
			// to hopefully prevent them from being missed during review.
			args[0] = '!REVIEW!';
			path.value.name = '$ERROR';

			return;
		}

		var args = path.parentPath.value.arguments;
		var message = new AssertionMessage(args[0], recast.types.builders.literal(true));

		if (args[1]) {
			return;
		}

		args[1] = recast.types.builders.literal(message.toString());
	},
	sameValue: function(path) {

		var args = path.parentPath.parentPath.value.arguments;
		var message;

		if (args[2]) {
			return;
		}

		message = new AssertionMessage(args[0], args[1]);

		args[2] = recast.types.builders.literal(message.toString());
	},
};

module.exports = function(ast) {
{'fraction_non_alphanumeric': 0.16546762589928057, 'fraction_numerical': 0.0044964028776978415, 'mean_word_length': 4.061433447098976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6861705', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1425, 'n_words': 288}