<commit_before>
var _wvtest_files = {};


function _wvtest_clean(s) {
  return (s + '').trim().replace(/\s/g, ' ');
}


function _wvtest_lookup(filename, line) {
    var f = _wvtest_files[filename];
    if (!f) {
        try {
            f = _wvtest_files[filename] = read(filename).split('\n');
        } catch (e) {
            f = _wvtest_files[filename] = [];
        }
    }
    return f[line - 1] || 'BAD_LINE'; // file line numbers are 1-based
}


function _v_ery_identifiable_stack_function() {
    return new Error();
}


var _wvtest_VISF_RE = /_v_ery_identifiable_stack_function/;
var _wvtest_FILELINE_RE = [
    // v8/chrome
    /\s+at .+ \((.+):(\d+):\d+\)$/,
    /\s+at (.+):(\d+):\d+$/,
    // safari or firefox
    /([^@]*):(\d+):\d+$/,
];


function wvtest_parse_trace(e) {
    var out = [];

    if (!e || !e.stack) {
        out.full = 'undefined-stack-1:0';
        out.push(['undefined-stack-1', 0]);
        return out;
    }

    var found_line = -2;
    var lines = e.stack.split('\n');
    for (i in lines) {
        if (lines[i].match(_wvtest_VISF_RE)) {
            found_line = out.length;
        }
        for (var r in _wvtest_FILELINE_RE) {
          g = lines[i].match(_wvtest_FILELINE_RE[r]);
          if (g) break;
        }
        if (g) {
            out.push([g[1], parseInt(g[2])]);
        }
    }

    // skip _VISF_RE and one additional line (its caller), if found
    out = out.slice(found_line + 2);
    out.full = e.stack;
    return out;
}


function wvtest_trace() {
    var e = _v_ery_identifiable_stack_function();
    return wvtest_parse_trace(e);
}


function _wvtest_pad(len, s) {
    s += '';
    while (s.length < len) {
        s += ' ';
    }
    return s;
}


function wvtest_check(cond, trace, condstr) {
    try {
        if (!trace.length) trace.push(['missing-trace', 0]);
        if (!cond) {
	    var full = trace.full;
	    print('\nBacktrace:\n  ' + full.split('\n').join('\n  '));
	}
        print('!', _wvtest_pad(15, trace[0][0] + ':' + trace[0][1]),
              _wvtest_pad(54, _wvtest_clean(condstr)),
              cond ? 'ok' : 'FAILED');
        return cond;
    } catch (e) {
        print('eek! e.full:', e.full);
        print('eek! Backtrace:', (new Error()).stack);
        print('! wvtest exception: ' + e + ' FAILED');
        throw e;
    }
}


function _wvtest_content(tracerow) {
    var WV_RE = /WV[\w_]+\((.*)\)/;
    var line = _wvtest_lookup(tracerow[0], tracerow[1]);
    var g = line.match(WV_RE);
    return g ? g[1] : _clean(line);
}


function WVPASS(cond) {
    var t = wvtest_trace();
    if (arguments.length >= 1) {
        var condstr = _wvtest_content(t[1]);
        return wvtest_check(cond, t.slice(1), condstr);<commit_msg>javascript: wvtest_check: better handle undefined trace.full.<commit_after>
var _wvtest_files = {};


function _wvtest_clean(s) {
  return (s + '').trim().replace(/\s/g, ' ');
}


function _wvtest_lookup(filename, line) {
    var f = _wvtest_files[filename];
    if (!f) {
        try {
            f = _wvtest_files[filename] = read(filename).split('\n');
        } catch (e) {
            f = _wvtest_files[filename] = [];
        }
    }
    return f[line - 1] || 'BAD_LINE'; // file line numbers are 1-based
}


function _v_ery_identifiable_stack_function() {
    return new Error();
}


var _wvtest_VISF_RE = /_v_ery_identifiable_stack_function/;
var _wvtest_FILELINE_RE = [
    // v8/chrome
    /\s+at .+ \((.+):(\d+):\d+\)$/,
    /\s+at (.+):(\d+):\d+$/,
    // safari or firefox
    /([^@]*):(\d+):\d+$/,
];


function wvtest_parse_trace(e) {
    var out = [];

    if (!e || !e.stack) {
        out.full = 'undefined-stack-1:0';
        out.push(['undefined-stack-1', 0]);
        return out;
    }

    var found_line = -2;
    var lines = e.stack.split('\n');
    for (i in lines) {
        if (lines[i].match(_wvtest_VISF_RE)) {
            found_line = out.length;
        }
        for (var r in _wvtest_FILELINE_RE) {
          g = lines[i].match(_wvtest_FILELINE_RE[r]);
          if (g) break;
        }
        if (g) {
            out.push([g[1], parseInt(g[2])]);
        }
    }

    // skip _VISF_RE and one additional line (its caller), if found
    out = out.slice(found_line + 2);
    out.full = e.stack;
    return out;
}


function wvtest_trace() {
    var e = _v_ery_identifiable_stack_function();
    return wvtest_parse_trace(e);
}


function _wvtest_pad(len, s) {
    s += '';
    while (s.length < len) {
        s += ' ';
    }
    return s;
}


function wvtest_check(cond, trace, condstr) {
    try {
        if (!trace.length) trace.push(['missing-trace', 0]);
        if (!trace.full) trace.full = trace.join('\n');
        if (!cond) {
	    var full = trace.full + '';
	    print('\nBacktrace:\n  ' + full.split('\n').join('\n  '));
	}
        print('!', _wvtest_pad(15, trace[0][0] + ':' + trace[0][1]),
              _wvtest_pad(54, _wvtest_clean(condstr)),
              cond ? 'ok' : 'FAILED');
        return cond;
    } catch (e) {
        print('eek! e.full:', e.full);
        print('eek! Backtrace:', (new Error()).stack);
        print('! wvtest exception: ' + e + ' FAILED');
        throw e;
    }
}


function _wvtest_content(tracerow) {
    var WV_RE = /WV[\w_]+\((.*)\)/;
    var line = _wvtest_lookup(tracerow[0], tracerow[1]);
    var g = line.match(WV_RE);
    return g ? g[1] : _clean(line);
}


function WVPASS(cond) {
    var t = wvtest_trace();
    if (arguments.length >= 1) {
        var condstr = _wvtest_content(t[1]);
        return wvtest_check(cond, t.slice(1), condstr);
{'fraction_non_alphanumeric': 0.18436657681940702, 'fraction_numerical': 0.009344115004492363, 'mean_word_length': 2.2417006406523003, 'pattern_counts': {'":': 0, '<': 5, '<?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': '768617', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2109, 'n_words': 410}