<commit_before>// Copyright (C) 2014, Test262 Project Authors. All rights reserved.
// This code is governed by the BSD License found in the LICENSE file.
/*global it, describe */
"use strict";

var parser = require('../lib/parser'),
    fs = require('fs'),
    assert = require('assert'),
    through = require('through'),
    fixtures = {
        S11_4: 'test/fixtures/11.4.1-5-a-5gs.js',
        S72: 'test/fixtures/S7.2_A1.1_T1.js',
        async: 'test/fixtures/async.js',
        badYAML: 'test/fixtures/badYAML.js',
        issue_9: 'test/fixtures/issue_9.js',
        no_newline: 'test/fixtures/no_newline.js',
        promise_length: 'test/fixtures/promise_length.js'
    };

Object.keys(fixtures).forEach(function (k) {
    /*jslint stupid:true*/
    fixtures[k] = fs.readFileSync(fixtures[k], {encoding: 'utf-8'});
});

it('parses a fixture', function () {
    var file = {
        contents: fixtures.S72
    };
    file = parser.parseFile(file);

    assert.equal(file.attrs.es5id, '7.2_A1.1_T1');
});

it('parses a fixture when given only the contents as a string', function () {
    var file = parser.parseFile(fixtures.S72);

    assert.equal(file.attrs.es5id, '7.2_A1.1_T1');
});

it('parses a fixture with flags', function () {
    var file = {
        contents: fixtures.S11_4
    };
    file = parser.parseFile(file);

    assert.equal(file.attrs.flags.onlyStrict, true);
});

it('extracts the YAML', function () {
    assert.equal(parser.extractYAML("/*---foo---*/"), "foo");
    assert.equal(parser.extractYAML("/*---\nfoo\n---*/"), "\nfoo\n");
    assert.equal(parser.extractYAML("no yaml here"), "");
});

it('parses an empty file', function () {
    var file = {
        contents: ''
    };
    file = parser.parseFile(file);

    assert.deepEqual({
        contents: '',
        async: false,
        attrs: {
            includes: [],
            flags: {}
        },
        copyright: '',
        isATest: false
    }, file);
});

it('recovers from bad YAML', function () {
    var file = {
        file: 'mock_filename.js',
        contents: fixtures.badYAML
    };

    assert.throws(function () {
        file = parser.parseFile(file);
    }, /YAML/);
});

it('decides if a test is async', function () {
    var file = {<commit_msg>Latest YAML library throws an Error which does not include the string "YAML"<commit_after>// Copyright (C) 2014, Test262 Project Authors. All rights reserved.
// This code is governed by the BSD License found in the LICENSE file.
/*global it, describe */
"use strict";

var parser = require('../lib/parser'),
    fs = require('fs'),
    assert = require('assert'),
    through = require('through'),
    fixtures = {
        S11_4: 'test/fixtures/11.4.1-5-a-5gs.js',
        S72: 'test/fixtures/S7.2_A1.1_T1.js',
        async: 'test/fixtures/async.js',
        badYAML: 'test/fixtures/badYAML.js',
        issue_9: 'test/fixtures/issue_9.js',
        no_newline: 'test/fixtures/no_newline.js',
        promise_length: 'test/fixtures/promise_length.js'
    };

Object.keys(fixtures).forEach(function (k) {
    /*jslint stupid:true*/
    fixtures[k] = fs.readFileSync(fixtures[k], {encoding: 'utf-8'});
});

it('parses a fixture', function () {
    var file = {
        contents: fixtures.S72
    };
    file = parser.parseFile(file);

    assert.equal(file.attrs.es5id, '7.2_A1.1_T1');
});

it('parses a fixture when given only the contents as a string', function () {
    var file = parser.parseFile(fixtures.S72);

    assert.equal(file.attrs.es5id, '7.2_A1.1_T1');
});

it('parses a fixture with flags', function () {
    var file = {
        contents: fixtures.S11_4
    };
    file = parser.parseFile(file);

    assert.equal(file.attrs.flags.onlyStrict, true);
});

it('extracts the YAML', function () {
    assert.equal(parser.extractYAML("/*---foo---*/"), "foo");
    assert.equal(parser.extractYAML("/*---\nfoo\n---*/"), "\nfoo\n");
    assert.equal(parser.extractYAML("no yaml here"), "");
});

it('parses an empty file', function () {
    var file = {
        contents: ''
    };
    file = parser.parseFile(file);

    assert.deepEqual({
        contents: '',
        async: false,
        attrs: {
            includes: [],
            flags: {}
        },
        copyright: '',
        isATest: false
    }, file);
});

it('recovers from bad YAML', function () {
    var file = {
        file: 'mock_filename.js',
        contents: fixtures.badYAML
    };

    assert.throws(function () {
        file = parser.parseFile(file);
    }, /YAML|insufficient_indent/);
});

it('decides if a test is async', function () {
    var file = {
{'fraction_non_alphanumeric': 0.1720546756346279, 'fraction_numerical': 0.019527012367107834, 'mean_word_length': 2.610023492560689, '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': '1821998', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1553, 'n_words': 330}