/*!
 * Copyright (C) 2012 by Oleg Efimov
 *
 * See license text in LICENSE file
 */

var fs         = require('fs');
var assert     = require('assert');
var difflet    = require('difflet')({indent: 2, comment: true});
var proto2json = require('../');

// Patch assert.deepEqual
var originalDeepEqual = assert.deepEqual;

assert.deepEqual = function (actual, expected, message) {
  try {
    originalDeepEqual.apply(null, arguments);
  } catch (err) {
    var diff = difflet.compare(expected, actual);
    err.toString = function () { return 'AssertionError: ' + diff; };
    throw err;
  }
};

// Create tests for all fixtures files
var files = fs.readdirSync(__dirname + '/fixtures')
              .filter(function(file) { return file.match(/\.proto$/); })
              .sort();

describe('proto2json', function(){
  files.forEach(function(file) {
    var name = file.replace(/\.proto$/, '');

    var file_proto = __dirname + '/fixtures/' + name + '.proto';
    var file_json  = __dirname + '/fixtures/' + name + '.json';

    var proto = fs.readFileSync(file_proto, 'utf8');
    var json  = fs.readFileSync(file_json, 'utf8');

    json = JSON.parse(json);

    it('should properly parse ' + name + '.proto', function (done) {
      proto2json.parse(proto, function (err, parse_result) {
        if (err) {
          throw err;
        }

        assert.deepEqual(parse_result, json);

        done();
      });
    });
  });
});

@@ -786,22 +786,24 @@
 cribe('p
-roto2j
+arser.ji
 son', fu
@@ -812,36 +812,49 @@
 tion
+ 
 ()
+ 
 %7B%0A  
-files.forEach(
+it('should be parsable', 
 function
 (fil
@@ -849,21 +849,18 @@
 function
+ 
 (
-file
 ) %7B%0A    
@@ -867,218 +867,391 @@
 var 
-name = file.replace(/%5C.proto$/, '');%0A%0A    var file_proto = __dirname + '/fixtures/' + name + '.proto';%0A    var file_json  = __dirname + '/fixtures/' + name + '.json';%0A%0A    var proto = fs.readFileSync(file_
+jison_source = fs.readFileSync(__dirname + '/../src/parser.jison', 'utf8');%0A%0A    assert.doesNotThrow(function () %7B%0A      require(%22jison/lib/jison/bnf%22).parse(jison_source);%0A    %7D);%0A  %7D);%0A%7D);%0A%0Adescribe('proto2json', function () %7B%0A  files.forEach(function (file) %7B%0A    var name = file.replace(/%5C.proto$/, '');%0A%0A    var proto = fs.readFileSync(__dirname + '/fixtures/' + name + '.
 proto
+'
 , 'u
@@ -1293,18 +1293,51 @@
 ync(
-file_
+__dirname + '/fixtures/' + name + '.
 json
-,
+', 
  'ut

Test that parser.jison is parsable