<commit_before>var assert = require('assert');

var fs = require('fs');

var SchemaRegistry = require('../index.js').SchemaRegistry;
var Schema = require('../index.js').Schema;
var Parser = require('../index.js').StreamParser;

var metaschemaObject = require('json-metaschema/draft-07-schema.json');

var syntaxTestDir = __dirname+'/syntax-suite/test_parsing';
var syntaxTestFilesPositive = fs.readdirSync(syntaxTestDir).filter(function(n){
	return n[0]=='y';
});
var syntaxTestFilesNegative = fs.readdirSync(syntaxTestDir).filter(function(n){
	return n[0]=='n';
});

describe('Syntax tests', function(){
	syntaxTestFilesPositive.forEach(function(filename){
		var filepath = syntaxTestDir + '/' + filename;
		var label = filename + ' (UTF-8)';
		it(label, function(done){
			var t = fs.createReadStream(filepath);
			var p = new Parser(null, {keepValue:true, charset:'UTF-8'});
			t.pipe(p);
			p.on('error', function(){
				assert.fail();
			});
			p.on('finish', function(){
				assert(p.value!==undefined);
				done();
			});
		});
	});
	syntaxTestFilesNegative.forEach(function(filename){
		var filepath = syntaxTestDir + '/' + filename;
		var label = filename + ' (UTF-8)';
		it(label, function(done){
			var t = fs.createReadStream(filepath);
			var p = new Parser(null, {keepValue:true, charset:'UTF-8'});
			t.pipe(p);
			var error = null;
			p.on('error', function(err){
				error = err;
			});
			p.on('finish', function(){
				assert.ok(error);
				done();
			});
		});

	});
});<commit_msg>Workaround strange error/end event behavior<commit_after>var assert = require('assert');

var fs = require('fs');

var SchemaRegistry = require('../index.js').SchemaRegistry;
var Schema = require('../index.js').Schema;
var Parser = require('../index.js').StreamParser;

var metaschemaObject = require('json-metaschema/draft-07-schema.json');

var syntaxTestDir = __dirname+'/syntax-suite/test_parsing';
var syntaxTestFilesPositive = fs.readdirSync(syntaxTestDir).filter(function(n){
	return n[0]=='y';
});
var syntaxTestFilesNegative = fs.readdirSync(syntaxTestDir).filter(function(n){
	return n[0]=='n';
});

describe('Syntax tests', function(){
	syntaxTestFilesPositive.forEach(function(filename){
		var filepath = syntaxTestDir + '/' + filename;
		var label = filename + ' (UTF-8)';
		it(label, function(done){
			var error = null;
			var t = fs.createReadStream(filepath);
			var p = new Parser(null, {keepValue:true, charset:'UTF-8'});
			t.pipe(p);
			p.on('error', function(err){
				done(err);
			});
			t.on('end', function(){
				assert(p.value!==undefined);
				if(!error) done();
			});
		});
	});
	syntaxTestFilesNegative.forEach(function(filename){
		var filepath = syntaxTestDir + '/' + filename;
		var label = filename + ' (UTF-8)';
		it(label, function(done){
			//console.log('\n\n'+filepath);
			var error = null;
			var t = fs.createReadStream(filepath);
			var p = new Parser(null, {keepValue:true, charset:'UTF-8'});
			t.pipe(p);
			p.on('error', function(err){
				//console.log('error');
				error = err;
				done();
			});
			t.on('end', function(){
				//console.log('finish');
				assert.ok(error);
				if(!error) done();
			});
		});

	});
});
{'fraction_non_alphanumeric': 0.1947069943289225, 'fraction_numerical': 0.005040957781978576, 'mean_word_length': 4.327181208053691, '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': '3787033', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1067, 'n_words': 201}