<commit_before>/**
 * This module defines an object which can write the results to a stream.
 * Any alternative output for the results can easily be created by
 * fulfilling the same API.
 * */

var library = require("./library");
var util = require('util');

// I'm bringing this one in simply because I don't want to have
// to write yet more wordwrap code.
var wordwrap = require("wordwrap");

/**
 * A ResultWriter accepts a Test results object and writes it's
 * data out to a stream. If the stream isn't set, this will default
 * to stdout.
 * 
 * NOTE: The stream object doesn't have to be a real stream. All it
 * really needs is an object with a method called 'write', which will
 * receive a string as it's parameter for everything written out. 
 * 
 * Parameters:
 * - stream: The stream to write to, optional.
 * */
var ResultWriter = module.exports = function(stream) {
    this._output = stream || process.stdout;
    
    /**
     * Specifies the string to concatenate onto the indent when nested
     * content is output.
     * */
    this.indentIncrease = "  ";

    // TODO: Will this work on Windows?    
    /**
     * Specifies the code to use for turning on bold text.
     * */
    this.boldOn = this._output.isTTY ? "\x1B[1m" : "";
    /**
     * Specifies the code to use for turning off bold text.
     * */
    this.boldOff = this._output.isTTY ? "\x1B[0m" : "";
    
}

/**
 * Writes the results of the test to the output. This should really only
 * be called after the application is relatively certain that the tests
 * are completed, but it should be able to work if the test isn't completed
 * as well.
 * 
 * Parameters:
 * - test: The results.Test object containing the results.
 * - indent: a set of spaces to indent lines with. Default is an empty string.
 * Nested calls will increase this indent by a specific ammount.
 * */
ResultWriter.prototype.writeTest = function(test,indent) {
    indent = indent || "";

     var result = test.isPassed() ? "passed" : test.isComplete() ? (this.boldOn + "failed" + this.boldOff) : (this.boldOn + "incomplete" + this.boldOff);
    
     this.writeData(util.format("%s -- %d/%d: %s",result,test.passed,test.total,test.name),indent);
    // If the test passed, we don't need to know anything more, a summary is plenty.<commit_msg>-- Added word wrapping<commit_after>/**
 * This module defines an object which can write the results to a stream.
 * Any alternative output for the results can easily be created by
 * fulfilling the same API.
 * */

var library = require("./library");
var util = require('util');

// I'm bringing this one in simply because I don't want to have
// to write yet more wordwrap code. It breaks the philosophy for this
// module, but this one works so much better than what I could write
// in a few hours.
var wordwrap = require("wordwrap");

/**
 * A ResultWriter accepts a Test results object and writes it's
 * data out to a stream. If the stream isn't set, this will default
 * to stdout.
 * 
 * NOTE: The stream object doesn't have to be a real stream. All it
 * really needs is an object with a method called 'write', which will
 * receive a string as it's parameter for everything written out. 
 * 
 * Parameters:
 * - stream: The stream to write to, optional.
 * */
var ResultWriter = module.exports = function(stream) {
    this._output = stream || process.stdout;
    
    /**
     * Specifies the string to concatenate onto the indent when nested
     * content is output.
     * */
    this.indentIncrease = "  ";

    // FUTURE: Test this on windows. I don't know if Windows consoles
    // are valid TTY's.
    /**
     * Specifies the code to use for turning on bold text.
     * */
    this.boldOn = this._output.isTTY ? "\x1B[1m" : "";
    /**
     * Specifies the code to use for turning off bold text.
     * */
    this.boldOff = this._output.isTTY ? "\x1B[0m" : "";
    
}

/**
 * Writes the results of the test to the output. This should really only
 * be called after the application is relatively certain that the tests
 * are completed, but it should be able to work if the test isn't completed
 * as well.
 * 
 * Parameters:
 * - test: The results.Test object containing the results.
 * - indent: a set of spaces to indent lines with. Default is an empty string.
 * Nested calls will increase this indent by a specific ammount.
 * */
ResultWriter.prototype.writeTest = function(test,indent) {
    indent = indent || "";

     var result = test.isPassed() ? "passed" : test.isComplete() ? (this.boldOn + "failed" + this.boldOff) : (this.boldOn + "incomplete" + this.boldOff);
    
     this.writeData(util.format("%s -- %d/%d: %s",result,test.passed,test.total,test.name),indent);
    // If the test passed, we don't need to know anything more, a summary is plenty.
{'fraction_non_alphanumeric': 0.10744836219486752, 'fraction_numerical': 0.001669100771959107, 'mean_word_length': 2.978423236514523, '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': '864263', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1339, 'n_words': 597}