<commit_before>var ShexParser = require('../shex').Parser;

var fs = require('fs'),
    expect = require('chai').expect;

var schemasPath = __dirname + '/../schemas/';
var parsedSchemasPath = __dirname + '/../test/parsedSchemas/';
var negSyntaxTestsPath = __dirname + '/../negativeSyntax/';

describe('A SHEX parser', function () {
  // var b = function () {  };
  // it('is a toy', function () {
  //   expect({a:1, b: b}).to.deep.equal({a:1, b: b});
  // });

  var parser = new ShexParser();

  // Ensure the same blank node identifiers are used in every test
  beforeEach(function () { parser._resetBlanks(); });

  var schemas = fs.readdirSync(schemasPath);
  schemas = schemas.map(function (q) { return q.replace(/\.shex$/, ''); });
  schemas.sort();

  schemas.forEach(function (schema) {

    var parsedSchemaFile = parsedSchemasPath + schema + '.json';
    if (!fs.existsSync(parsedSchemaFile)) return;

    it('should correctly parse schema "' + schema + '"', function () {
      var parsedSchema = parseJSON(fs.readFileSync(parsedSchemaFile, 'utf8'));

      console.log(schema);
      schema = fs.readFileSync(schemasPath + schema + '.shex', 'utf8');
      console.log("parsed   :"+  JSON.stringify(parser.parse(schema)));
      console.log("expected :"+JSON.stringify(parsedSchema));
      expect(parser.parse(schema)).to.deep.equal(parsedSchema);
    });
  });

  // make sure errors are reported
  it('should throw an error on an invalid schema', function () {
    var schema = 'invalid', error = null;<commit_msg>~ renamed some vars in ShexParser-test.js<commit_after>var ShexParser = require('../shex').Parser;

var fs = require('fs'),
    expect = require('chai').expect;

var schemasPath = __dirname + '/../schemas/';
var jsonSchemasPath = __dirname + '/../test/parsedSchemas/';
var negSyntaxTestsPath = __dirname + '/../negativeSyntax/';

describe('A SHEX parser', function () {
  // var b = function () {  };
  // it('is a toy', function () {
  //   expect({a:1, b: b}).to.deep.equal({a:1, b: b});
  // });

  var parser = new ShexParser();

  // Ensure the same blank node identifiers are used in every test
  beforeEach(function () { parser._resetBlanks(); });

  var schemas = fs.readdirSync(schemasPath);
  schemas = schemas.map(function (q) { return q.replace(/\.shex$/, ''); });
  schemas.sort();

  schemas.forEach(function (schema) {

    var jsonSchemaFile = jsonSchemasPath + schema + '.json';
    if (!fs.existsSync(jsonSchemaFile)) return;

    it('should correctly parse schema "' + schema + '"', function () {
      var jsonSchema = parseJSON(fs.readFileSync(jsonSchemaFile, 'utf8'));

      console.log(schema);
      schema = fs.readFileSync(schemasPath + schema + '.shex', 'utf8');
      var parsedSchema = parser.parse(schema);
      console.log("parsed   :" + JSON.stringify(parsedSchema));
      console.log("expected :" + JSON.stringify(jsonSchema));
      expect(parsedSchema).to.deep.equal(jsonSchema);
    });
  });

  // make sure errors are reported
  it('should throw an error on an invalid schema', function () {
    var schema = 'invalid', error = null;
{'fraction_non_alphanumeric': 0.17402513696422817, 'fraction_numerical': 0.002578150177247825, 'mean_word_length': 3.5580029368575623, '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': '909674', 'n_tokens_mistral': 969, 'n_tokens_neox': 944, 'n_words': 231}